diff --git a/docs/generated/packages/plugin/generators/plugin.json b/docs/generated/packages/plugin/generators/plugin.json index e8c594a6b4bdc3..3f7fab0890aa60 100644 --- a/docs/generated/packages/plugin/generators/plugin.json +++ b/docs/generated/packages/plugin/generators/plugin.json @@ -40,7 +40,7 @@ "unitTestRunner": { "description": "Test runner to use for unit tests.", "type": "string", - "enum": ["none", "jest"], + "enum": ["none", "jest", "vitest"], "x-priority": "important" }, "tags": { diff --git a/packages/plugin/src/generators/plugin/plugin.spec.ts b/packages/plugin/src/generators/plugin/plugin.spec.ts index 82f66a7ae6db72..63a9e2b75fd37f 100644 --- a/packages/plugin/src/generators/plugin/plugin.spec.ts +++ b/packages/plugin/src/generators/plugin/plugin.spec.ts @@ -172,11 +172,55 @@ describe('NxPlugin Plugin Generator', () => { expect(tree.exists(path)).toBeFalsy() ); + ['my-plugin/vite.config.ts'].forEach((path) => + expect(tree.exists(path)).toBeFalsy() + ); + expect( readProjectConfiguration(tree, 'my-plugin').targets.test ).not.toBeDefined(); }); }); + + describe('jest', () => { + it('should generate test files with jest.config.ts', async () => { + await pluginGenerator( + tree, + getSchema({ + directory: 'my-plugin', + unitTestRunner: 'jest', + }) + ); + + ['my-plugin/jest.config.ts'].forEach((path) => + expect(tree.exists(path)).toBeTruthy() + ); + + expect( + readProjectConfiguration(tree, 'my-plugin').targets.test + ).toBeDefined(); + }); + }); + + describe('vitest', () => { + it('should generate test files with vite.config.ts', async () => { + await pluginGenerator( + tree, + getSchema({ + directory: 'my-plugin', + unitTestRunner: 'vitest', + }) + ); + + ['my-plugin/vite.config.ts'].forEach((path) => + expect(tree.exists(path)).toBeTruthy() + ); + + expect( + readProjectConfiguration(tree, 'my-plugin').targets.test + ).toBeDefined(); + }); + }); }); describe('--compiler', () => { diff --git a/packages/plugin/src/generators/plugin/plugin.ts b/packages/plugin/src/generators/plugin/plugin.ts index 5d7e0483017ee2..d73d2b289a932f 100644 --- a/packages/plugin/src/generators/plugin/plugin.ts +++ b/packages/plugin/src/generators/plugin/plugin.ts @@ -118,7 +118,8 @@ export async function pluginGeneratorInternal(host: Tree, schema: Schema) { '@nx/devkit': nxVersion, }, { - '@nx/jest': nxVersion, + [options.unitTestRunner === 'vitest' ? '@nx/vite' : '@nx/jest']: + nxVersion, '@nx/js': nxVersion, '@nx/plugin': nxVersion, } diff --git a/packages/plugin/src/generators/plugin/schema.d.ts b/packages/plugin/src/generators/plugin/schema.d.ts index f6e512c8666758..082eb02cfa6315 100644 --- a/packages/plugin/src/generators/plugin/schema.d.ts +++ b/packages/plugin/src/generators/plugin/schema.d.ts @@ -9,7 +9,7 @@ export interface Schema { skipLintChecks?: boolean; // default is false e2eTestRunner?: 'jest' | 'none'; tags?: string; - unitTestRunner?: 'jest' | 'none'; + unitTestRunner?: 'jest' | 'vitest' | 'none'; linter?: Linter | LinterType; setParserOptionsProject?: boolean; compiler?: 'swc' | 'tsc'; diff --git a/packages/plugin/src/generators/plugin/schema.json b/packages/plugin/src/generators/plugin/schema.json index 34469240b14d1b..7bd9253090bb98 100644 --- a/packages/plugin/src/generators/plugin/schema.json +++ b/packages/plugin/src/generators/plugin/schema.json @@ -40,7 +40,7 @@ "unitTestRunner": { "description": "Test runner to use for unit tests.", "type": "string", - "enum": ["none", "jest"], + "enum": ["none", "jest", "vitest"], "x-priority": "important" }, "tags": { diff --git a/packages/plugin/src/generators/plugin/utils/normalize-schema.ts b/packages/plugin/src/generators/plugin/utils/normalize-schema.ts index 632ec818a13c37..8cc585b253056a 100644 --- a/packages/plugin/src/generators/plugin/utils/normalize-schema.ts +++ b/packages/plugin/src/generators/plugin/utils/normalize-schema.ts @@ -20,7 +20,7 @@ export interface NormalizedSchema extends Schema { npmPackageName: string; bundler: 'swc' | 'tsc'; publishable: boolean; - unitTestRunner: 'jest' | 'none'; + unitTestRunner: 'jest' | 'vitest' | 'none'; linter: LinterType; useProjectJson: boolean; addPlugin: boolean; @@ -35,7 +35,7 @@ export async function normalizeOptions( const unitTestRunner = await normalizeUnitTestRunnerOption( host, options.unitTestRunner, - ['jest'] + ['jest', 'vitest'] ); const isTsSolutionSetup = isUsingTsSolutionSetup(host);