feat(vite): allow passing multiple test files to vite:test (#17496)
Co-authored-by: Caleb Ukle <caleb.ukle+github@pm.me>
This commit is contained in:
parent
c4b7a1f9d8
commit
a995940b19
@ -58,9 +58,10 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Directory to write coverage report to."
|
"description": "Directory to write coverage report to."
|
||||||
},
|
},
|
||||||
"testFile": {
|
"testFiles": {
|
||||||
"description": "The name of the file to test.",
|
"aliases": ["testFile"],
|
||||||
"type": "string"
|
"type": "array",
|
||||||
|
"items": { "type": "string" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [],
|
"required": [],
|
||||||
|
|||||||
@ -23,6 +23,12 @@
|
|||||||
"version": "16.0.0-beta.1",
|
"version": "16.0.0-beta.1",
|
||||||
"description": "Replace @nrwl/vite with @nx/vite",
|
"description": "Replace @nrwl/vite with @nx/vite",
|
||||||
"implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
|
"implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
|
||||||
|
},
|
||||||
|
"update-16-4-1-test-file-config": {
|
||||||
|
"version": "16.4.1-beta.0",
|
||||||
|
"description": "Changes the testFile config in the vite:test exectutor from a string to an array of strings",
|
||||||
|
"cli": "nx",
|
||||||
|
"implementation": "./src/migrations/update-16-4-1-update-test-file-config/update-16-4-1-test-file-config"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"packageJsonUpdates": {
|
"packageJsonUpdates": {
|
||||||
|
|||||||
2
packages/vite/src/executors/test/schema.d.ts
vendored
2
packages/vite/src/executors/test/schema.d.ts
vendored
@ -8,5 +8,5 @@ export interface VitestExecutorOptions {
|
|||||||
update?: boolean;
|
update?: boolean;
|
||||||
reportsDirectory?: string;
|
reportsDirectory?: string;
|
||||||
coverage?: boolean;
|
coverage?: boolean;
|
||||||
testFile?: string;
|
testFiles?: string[];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,9 +57,10 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Directory to write coverage report to."
|
"description": "Directory to write coverage report to."
|
||||||
},
|
},
|
||||||
"testFile": {
|
"testFiles": {
|
||||||
"description": "The name of the file to test.",
|
"aliases": ["testFile"],
|
||||||
"type": "string"
|
"type": "array",
|
||||||
|
"items": { "type": "string" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [],
|
"required": [],
|
||||||
|
|||||||
@ -62,7 +62,7 @@ export async function* vitestExecutor(
|
|||||||
const nxReporter = new NxReporter(options.watch);
|
const nxReporter = new NxReporter(options.watch);
|
||||||
const settings = await getSettings(options, context, projectRoot);
|
const settings = await getSettings(options, context, projectRoot);
|
||||||
settings.reporters.push(nxReporter);
|
settings.reporters.push(nxReporter);
|
||||||
const cliFilters = options.testFile ? [options.testFile] : [];
|
const cliFilters = options.testFiles ?? [];
|
||||||
|
|
||||||
const ctx = await startVitest(options.mode, cliFilters, settings);
|
const ctx = await startVitest(options.mode, cliFilters, settings);
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,106 @@
|
|||||||
|
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
||||||
|
import {
|
||||||
|
Tree,
|
||||||
|
addProjectConfiguration,
|
||||||
|
readProjectConfiguration,
|
||||||
|
} from '@nx/devkit';
|
||||||
|
|
||||||
|
import updateTestFileOption from './update-16-4-1-test-file-config';
|
||||||
|
|
||||||
|
describe('update-16-5-0-vite-test-file-config migration', () => {
|
||||||
|
let tree: Tree;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should run successfully when testFile does not exist in the config', () => {
|
||||||
|
addProjectConfiguration(tree, 'vitest', {
|
||||||
|
root: 'vitest',
|
||||||
|
targets: {
|
||||||
|
test: {
|
||||||
|
executor: '@nx/vite:test',
|
||||||
|
options: {
|
||||||
|
ci: true,
|
||||||
|
watch: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
updateTestFileOption(tree);
|
||||||
|
expect(readProjectConfiguration(tree, 'vitest')).toMatchInlineSnapshot(`
|
||||||
|
{
|
||||||
|
"$schema": "../node_modules/nx/schemas/project-schema.json",
|
||||||
|
"name": "vitest",
|
||||||
|
"root": "vitest",
|
||||||
|
"targets": {
|
||||||
|
"test": {
|
||||||
|
"executor": "@nx/vite:test",
|
||||||
|
"options": {
|
||||||
|
"ci": true,
|
||||||
|
"watch": true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should run successfully when testFile exists in options and configurations', () => {
|
||||||
|
addProjectConfiguration(tree, 'vitest', {
|
||||||
|
root: 'vitest',
|
||||||
|
targets: {
|
||||||
|
test: {
|
||||||
|
executor: '@nx/vite:test',
|
||||||
|
options: {
|
||||||
|
testFile: 'test-file.ts',
|
||||||
|
config: 'vite.config.ts',
|
||||||
|
},
|
||||||
|
configurations: {
|
||||||
|
one: {
|
||||||
|
testFile: 'test-file-one.ts',
|
||||||
|
ci: true,
|
||||||
|
},
|
||||||
|
two: {
|
||||||
|
testFile: 'test-file-two.ts',
|
||||||
|
watch: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
updateTestFileOption(tree);
|
||||||
|
expect(readProjectConfiguration(tree, 'vitest')).toMatchInlineSnapshot(`
|
||||||
|
{
|
||||||
|
"$schema": "../node_modules/nx/schemas/project-schema.json",
|
||||||
|
"name": "vitest",
|
||||||
|
"root": "vitest",
|
||||||
|
"targets": {
|
||||||
|
"test": {
|
||||||
|
"configurations": {
|
||||||
|
"one": {
|
||||||
|
"ci": true,
|
||||||
|
"testFiles": [
|
||||||
|
"test-file-one.ts",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"two": {
|
||||||
|
"testFiles": [
|
||||||
|
"test-file-two.ts",
|
||||||
|
],
|
||||||
|
"watch": true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"executor": "@nx/vite:test",
|
||||||
|
"options": {
|
||||||
|
"config": "vite.config.ts",
|
||||||
|
"testFiles": [
|
||||||
|
"test-file.ts",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
import { Tree, getProjects, updateProjectConfiguration } from '@nx/devkit';
|
||||||
|
import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils';
|
||||||
|
import { VitestExecutorOptions } from '../../executors/test/schema';
|
||||||
|
|
||||||
|
type OldVitestExecutorOptions = Omit<VitestExecutorOptions, 'testFiles'> & {
|
||||||
|
testFile: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function update(tree: Tree) {
|
||||||
|
const projects = getProjects(tree);
|
||||||
|
|
||||||
|
forEachExecutorOptions<OldVitestExecutorOptions>(
|
||||||
|
tree,
|
||||||
|
'@nx/vite:test',
|
||||||
|
(options, projectName, targetName, configuration) => {
|
||||||
|
const projectConfig = projects.get(projectName);
|
||||||
|
|
||||||
|
if (!options.testFile) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newTestFileArgs = [options.testFile];
|
||||||
|
|
||||||
|
delete options.testFile;
|
||||||
|
|
||||||
|
if (configuration) {
|
||||||
|
projectConfig.targets[targetName].configurations[configuration] = {
|
||||||
|
...options,
|
||||||
|
testFiles: newTestFileArgs,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
projectConfig.targets[targetName].options = {
|
||||||
|
...options,
|
||||||
|
testFiles: newTestFileArgs,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
updateProjectConfiguration(tree, projectName, projectConfig);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user