diff --git a/packages/main/README.md b/packages/main/README.md index 46ba1b2..694a3a1 100644 --- a/packages/main/README.md +++ b/packages/main/README.md @@ -37,39 +37,51 @@ npm install --save-dev quickpickle vitest ## Configuration -Add the quickpickle plugin to your Vitest configuration in vite.config.ts (or .js, etc.): +Add the quickpickle plugin to your Vitest configuration in vite.config.ts (or .js, etc.). +Also add the configuration to get the feature files, step definitions, world file, etc. ```ts // vite.config.ts import { quickpickle } from 'quickpickle'; -const qpConfig:Partial = { // <-- Optional configuration (defaults shown) - - /** - * The files to be imported for each Feature. - * All step definitions, hooks, world constructor, etc. must be listed. - * The value can be a glob pattern or an array of glob patterns. - */ - import: [ - '{features,test,tests}/**/*.steps.{ts,js,mjs}', - '{features,test,tests}/**/*.world.{ts,js,mjs}' - ] - -} - export default { plugins: [ - quickpickle(qpConfig) // <-- Add the quickpickle plugin + quickpickle() // <-- Add the quickpickle plugin ], test: { include : [ 'features/*.feature', // <-- Add Gherkin feature files into "test" configuration // (you'll probably want other test files too, for unit tests etc.) ], + setupFiles: ['./tests/tests.steps.ts'] // <-- specify each setupfile here }, }; ``` +If you have multiple configurations, you can also add the test settings in vitest.workspace.ts. +This is also where you could set up separate configurations for components vs. application, +different browser environments, different world constructors, etc. + +```ts +// vitest.workspace.ts +import { defineWorkspace } from 'vitest/config'; + +export default defineWorkspace([ + { // configuration for feature files + extends: './vite.config.ts', + test: { + include : [ 'tests/*.feature' ], + setupFiles: [ 'tests/tests.steps.ts' ], + }, + }, + { // configuration for unit tests + test: { + include : [ 'tests/*.test.ts' ], + } + } +]) +``` + ## Usage ### Write Feature files @@ -100,11 +112,11 @@ npx vitest --run ### Write step definitions Write your step definitions in a typescript or javascript file as configured -in the "import" declaration of the qpConfig object above. +in the "setupFiles" declaration in your vitest config. These files will be imported into the Vitest test runner, and the code for `Given`, `When`, `Then` will register each of the step definitions with quickpickle. -These step definitions should run on import, i.e. at the top level of the script, +These step definitions should run immediately, i.e. at the top level of the script, not as exported functions like a normal node module would do. ```ts diff --git a/packages/main/src/index.ts b/packages/main/src/index.ts index b48001c..46cf641 100644 --- a/packages/main/src/index.ts +++ b/packages/main/src/index.ts @@ -85,6 +85,7 @@ export type QuickPickleConfig = { const defaultConfig: QuickPickleConfig = { /** + * @deprecated -- use the Vitest config test.setupFiles insetad * The files to be imported for each Feature. * All step definitions, hooks, world constructor, etc. must be listed. * The value can be a glob pattern or an array of glob patterns. @@ -98,7 +99,7 @@ const defaultConfig: QuickPickleConfig = { interface ResolvedConfig { test?: { - cucumber?: Partial; + quickpickle?: Partial; }; } @@ -110,7 +111,7 @@ export const quickpickle = function() { configResolved: (resolvedConfig: ResolvedConfig) => { config = defaults( defaultConfig, - get(resolvedConfig, 'test.cucumber') + get(resolvedConfig, 'test.quickpickle') ) as QuickPickleConfig; }, transform: async (src: string, id: string): Promise => { diff --git a/packages/main/vite.config.ts b/packages/main/vite.config.ts index fba5eee..56459ab 100644 --- a/packages/main/vite.config.ts +++ b/packages/main/vite.config.ts @@ -2,9 +2,6 @@ import { quickpickle } from './src'; export default { plugins: [quickpickle()], - test: { - include : [ '{features,test,tests}/**/*.feature', 'tests/**/*.test.ts' ], - }, resolve: { alias: { 'quickpickle': __dirname + '/src', // only needed because this is the quickpickle repository diff --git a/packages/main/vitest.workspace.ts b/packages/main/vitest.workspace.ts new file mode 100644 index 0000000..e86526f --- /dev/null +++ b/packages/main/vitest.workspace.ts @@ -0,0 +1,16 @@ +import { defineWorkspace, defineProject } from 'vitest/config'; + +export default defineWorkspace([ + { + extends: './vite.config.ts', + test: { + include : [ 'tests/*.feature' ], + setupFiles: [ 'tests/tests.steps.ts' ], + }, + }, + { + test: { + include : [ './tests/*.test.ts' ], + } + } +])