Skip to content

Commit

Permalink
feat(nx-plugin): added suport for vitest test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
gperdomor committed Dec 2, 2024
1 parent ec5a5e6 commit 3b1052d
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/generated/packages/plugin/generators/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
44 changes: 44 additions & 0 deletions packages/plugin/src/generators/plugin/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin/src/generators/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/generators/plugin/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/generators/plugin/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,7 +35,7 @@ export async function normalizeOptions(
const unitTestRunner = await normalizeUnitTestRunnerOption(
host,
options.unitTestRunner,
['jest']
['jest', 'vitest']
);

const isTsSolutionSetup = isUsingTsSolutionSetup(host);
Expand Down

0 comments on commit 3b1052d

Please sign in to comment.