feat(nx-plugin): added support for vitest test runner (#29140)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> Nx Plugin do not have the option to use Vitest as test runner ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> This PR allow us to use Vitest as test runner in plugins projects. Vitest for e2e targets is still missing and a new PR will be raised after https://github.com/nrwl/nx/issues/29139 is fixed ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #22882
This commit is contained in:
parent
2143ea5e30
commit
3a164a22de
@ -5,6 +5,8 @@ auth:
|
|||||||
htpasswd:
|
htpasswd:
|
||||||
file: ./htpasswd
|
file: ./htpasswd
|
||||||
|
|
||||||
|
max_body_size: 15mb
|
||||||
|
|
||||||
# a list of other known repositories we can talk to
|
# a list of other known repositories we can talk to
|
||||||
uplinks:
|
uplinks:
|
||||||
npmjs:
|
npmjs:
|
||||||
|
|||||||
@ -31,7 +31,7 @@
|
|||||||
},
|
},
|
||||||
"unitTestRunner": {
|
"unitTestRunner": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["none", "jest"],
|
"enum": ["none", "jest", "vitest"],
|
||||||
"description": "Test runner to use for unit tests."
|
"description": "Test runner to use for unit tests."
|
||||||
},
|
},
|
||||||
"linter": {
|
"linter": {
|
||||||
|
|||||||
@ -28,7 +28,7 @@
|
|||||||
},
|
},
|
||||||
"unitTestRunner": {
|
"unitTestRunner": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["jest", "none"],
|
"enum": ["jest", "vitest", "none"],
|
||||||
"description": "Test runner to use for unit tests.",
|
"description": "Test runner to use for unit tests.",
|
||||||
"default": "jest"
|
"default": "jest"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -41,7 +41,7 @@
|
|||||||
},
|
},
|
||||||
"unitTestRunner": {
|
"unitTestRunner": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["jest", "none"],
|
"enum": ["jest", "vitest", "none"],
|
||||||
"description": "Test runner to use for unit tests.",
|
"description": "Test runner to use for unit tests.",
|
||||||
"default": "jest"
|
"default": "jest"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -40,7 +40,7 @@
|
|||||||
"unitTestRunner": {
|
"unitTestRunner": {
|
||||||
"description": "Test runner to use for unit tests.",
|
"description": "Test runner to use for unit tests.",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["none", "jest"],
|
"enum": ["none", "jest", "vitest"],
|
||||||
"x-priority": "important"
|
"x-priority": "important"
|
||||||
},
|
},
|
||||||
"tags": {
|
"tags": {
|
||||||
|
|||||||
@ -8,7 +8,7 @@ export interface CreatePackageSchema {
|
|||||||
// options to create cli package, passed to js library generator
|
// options to create cli package, passed to js library generator
|
||||||
skipFormat?: boolean;
|
skipFormat?: boolean;
|
||||||
tags?: string;
|
tags?: string;
|
||||||
unitTestRunner?: 'jest' | 'none';
|
unitTestRunner?: 'jest' | 'vitest' | 'none';
|
||||||
linter?: Linter | LinterType;
|
linter?: Linter | LinterType;
|
||||||
compiler?: 'swc' | 'tsc';
|
compiler?: 'swc' | 'tsc';
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@
|
|||||||
},
|
},
|
||||||
"unitTestRunner": {
|
"unitTestRunner": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["none", "jest"],
|
"enum": ["none", "jest", "vitest"],
|
||||||
"description": "Test runner to use for unit tests."
|
"description": "Test runner to use for unit tests."
|
||||||
},
|
},
|
||||||
"linter": {
|
"linter": {
|
||||||
|
|||||||
@ -12,7 +12,7 @@ export interface NormalizedSchema extends CreatePackageSchema {
|
|||||||
bundler: 'swc' | 'tsc';
|
bundler: 'swc' | 'tsc';
|
||||||
projectName: string;
|
projectName: string;
|
||||||
projectRoot: string;
|
projectRoot: string;
|
||||||
unitTestRunner: 'jest' | 'none';
|
unitTestRunner: 'jest' | 'vitest' | 'none';
|
||||||
linter: LinterType;
|
linter: LinterType;
|
||||||
useProjectJson: boolean;
|
useProjectJson: boolean;
|
||||||
addPlugin: boolean;
|
addPlugin: boolean;
|
||||||
|
|||||||
@ -2,7 +2,7 @@ export interface Schema {
|
|||||||
path: string;
|
path: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
unitTestRunner: 'jest' | 'none';
|
unitTestRunner: 'jest' | 'vitest' | 'none';
|
||||||
includeHasher: boolean;
|
includeHasher: boolean;
|
||||||
skipLintChecks?: boolean;
|
skipLintChecks?: boolean;
|
||||||
skipFormat?: boolean;
|
skipFormat?: boolean;
|
||||||
|
|||||||
@ -28,7 +28,7 @@
|
|||||||
},
|
},
|
||||||
"unitTestRunner": {
|
"unitTestRunner": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["jest", "none"],
|
"enum": ["jest", "vitest", "none"],
|
||||||
"description": "Test runner to use for unit tests.",
|
"description": "Test runner to use for unit tests.",
|
||||||
"default": "jest"
|
"default": "jest"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -2,7 +2,7 @@ export interface Schema {
|
|||||||
path: string;
|
path: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
unitTestRunner: 'jest' | 'none';
|
unitTestRunner: 'jest' | 'vitest' | 'none';
|
||||||
skipLintChecks?: boolean;
|
skipLintChecks?: boolean;
|
||||||
skipFormat?: boolean;
|
skipFormat?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,7 +41,7 @@
|
|||||||
},
|
},
|
||||||
"unitTestRunner": {
|
"unitTestRunner": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["jest", "none"],
|
"enum": ["jest", "vitest", "none"],
|
||||||
"description": "Test runner to use for unit tests.",
|
"description": "Test runner to use for unit tests.",
|
||||||
"default": "jest"
|
"default": "jest"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -172,11 +172,63 @@ describe('NxPlugin Plugin Generator', () => {
|
|||||||
expect(tree.exists(path)).toBeFalsy()
|
expect(tree.exists(path)).toBeFalsy()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
['my-plugin/vite.config.ts'].forEach((path) =>
|
||||||
|
expect(tree.exists(path)).toBeFalsy()
|
||||||
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
readProjectConfiguration(tree, 'my-plugin').targets.test
|
readProjectConfiguration(tree, 'my-plugin').targets.test
|
||||||
).not.toBeDefined();
|
).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()
|
||||||
|
);
|
||||||
|
|
||||||
|
const projectTargets = readProjectConfiguration(
|
||||||
|
tree,
|
||||||
|
'my-plugin'
|
||||||
|
).targets;
|
||||||
|
|
||||||
|
expect(projectTargets.test).toBeDefined();
|
||||||
|
expect(projectTargets.test?.executor).toEqual('@nx/jest:jest');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
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()
|
||||||
|
);
|
||||||
|
|
||||||
|
const projectTargets = readProjectConfiguration(
|
||||||
|
tree,
|
||||||
|
'my-plugin'
|
||||||
|
).targets;
|
||||||
|
|
||||||
|
expect(projectTargets.test).toBeDefined();
|
||||||
|
expect(projectTargets.test?.executor).toEqual('@nx/vite:test');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('--compiler', () => {
|
describe('--compiler', () => {
|
||||||
|
|||||||
@ -118,7 +118,8 @@ export async function pluginGeneratorInternal(host: Tree, schema: Schema) {
|
|||||||
'@nx/devkit': nxVersion,
|
'@nx/devkit': nxVersion,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'@nx/jest': nxVersion,
|
[options.unitTestRunner === 'vitest' ? '@nx/vite' : '@nx/jest']:
|
||||||
|
nxVersion,
|
||||||
'@nx/js': nxVersion,
|
'@nx/js': nxVersion,
|
||||||
'@nx/plugin': nxVersion,
|
'@nx/plugin': nxVersion,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ export interface Schema {
|
|||||||
skipLintChecks?: boolean; // default is false
|
skipLintChecks?: boolean; // default is false
|
||||||
e2eTestRunner?: 'jest' | 'none';
|
e2eTestRunner?: 'jest' | 'none';
|
||||||
tags?: string;
|
tags?: string;
|
||||||
unitTestRunner?: 'jest' | 'none';
|
unitTestRunner?: 'jest' | 'vitest' | 'none';
|
||||||
linter?: Linter | LinterType;
|
linter?: Linter | LinterType;
|
||||||
setParserOptionsProject?: boolean;
|
setParserOptionsProject?: boolean;
|
||||||
compiler?: 'swc' | 'tsc';
|
compiler?: 'swc' | 'tsc';
|
||||||
|
|||||||
@ -40,7 +40,7 @@
|
|||||||
"unitTestRunner": {
|
"unitTestRunner": {
|
||||||
"description": "Test runner to use for unit tests.",
|
"description": "Test runner to use for unit tests.",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["none", "jest"],
|
"enum": ["none", "jest", "vitest"],
|
||||||
"x-priority": "important"
|
"x-priority": "important"
|
||||||
},
|
},
|
||||||
"tags": {
|
"tags": {
|
||||||
|
|||||||
@ -20,7 +20,7 @@ export interface NormalizedSchema extends Schema {
|
|||||||
npmPackageName: string;
|
npmPackageName: string;
|
||||||
bundler: 'swc' | 'tsc';
|
bundler: 'swc' | 'tsc';
|
||||||
publishable: boolean;
|
publishable: boolean;
|
||||||
unitTestRunner: 'jest' | 'none';
|
unitTestRunner: 'jest' | 'vitest' | 'none';
|
||||||
linter: LinterType;
|
linter: LinterType;
|
||||||
useProjectJson: boolean;
|
useProjectJson: boolean;
|
||||||
addPlugin: boolean;
|
addPlugin: boolean;
|
||||||
@ -35,7 +35,7 @@ export async function normalizeOptions(
|
|||||||
const unitTestRunner = await normalizeUnitTestRunnerOption(
|
const unitTestRunner = await normalizeUnitTestRunnerOption(
|
||||||
host,
|
host,
|
||||||
options.unitTestRunner,
|
options.unitTestRunner,
|
||||||
['jest']
|
['jest', 'vitest']
|
||||||
);
|
);
|
||||||
|
|
||||||
const isTsSolutionSetup = isUsingTsSolutionSetup(host);
|
const isTsSolutionSetup = isUsingTsSolutionSetup(host);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user