feat(vite): update to vitest v1 (#20747)
This commit is contained in:
parent
85fa68b181
commit
cac2c173c5
@ -240,21 +240,11 @@ export default App;
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
||||
|
||||
|
||||
export default defineConfig({
|
||||
root: __dirname,
|
||||
cacheDir: '../../node_modules/.vite/libs/${lib}',
|
||||
server: {
|
||||
port: 4200,
|
||||
host: 'localhost',
|
||||
},
|
||||
plugins: [
|
||||
react(),
|
||||
nxViteTsPaths()
|
||||
],
|
||||
build: {
|
||||
outDir: '../../dist/libs/${lib}',
|
||||
},
|
||||
plugins: [react(), nxViteTsPaths()],
|
||||
test: {
|
||||
globals: true,
|
||||
cache: {
|
||||
@ -262,15 +252,18 @@ export default App;
|
||||
},
|
||||
environment: 'jsdom',
|
||||
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
||||
reporters: ['default'],
|
||||
coverage: {
|
||||
reportsDirectory: '../../coverage/libs/${lib}',
|
||||
provider: "v8",
|
||||
provider: 'v8',
|
||||
enabled: true,
|
||||
lines: 100,
|
||||
statements: 100,
|
||||
functions: 100,
|
||||
branches: 1000,
|
||||
}
|
||||
thresholds: {
|
||||
lines: 100,
|
||||
statements: 100,
|
||||
functions: 100,
|
||||
branches: 1000,
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
`;
|
||||
|
||||
@ -60,10 +60,10 @@
|
||||
"@nestjs/schematics": "^9.1.0",
|
||||
"@nestjs/swagger": "^6.0.0",
|
||||
"@nestjs/testing": "^9.0.0",
|
||||
"@nuxt/kit": "^3.8.1",
|
||||
"@ngrx/effects": "17.0.1",
|
||||
"@ngrx/router-store": "17.0.1",
|
||||
"@ngrx/store": "17.0.1",
|
||||
"@nuxt/kit": "^3.8.1",
|
||||
"@nuxt/schema": "^3.8.1",
|
||||
"@nx/angular": "17.2.0-rc.2",
|
||||
"@nx/cypress": "17.2.0-rc.2",
|
||||
@ -287,7 +287,8 @@
|
||||
"url-loader": "^4.1.1",
|
||||
"use-sync-external-store": "^1.2.0",
|
||||
"verdaccio": "^5.0.4",
|
||||
"vite": "5.0.5",
|
||||
"vite": "5.0.8",
|
||||
"vitest": "^1.0.4",
|
||||
"webpack": "5.88.0",
|
||||
"webpack-dev-server": "^4.9.3",
|
||||
"webpack-merge": "^5.8.0",
|
||||
@ -352,7 +353,6 @@
|
||||
"tailwind-merge": "^1.8.1",
|
||||
"tailwindcss": "3.2.4",
|
||||
"tslib": "^2.3.0",
|
||||
"vitest": "^0.34.6",
|
||||
"weak-napi": "^2.0.2"
|
||||
},
|
||||
"resolutions": {
|
||||
@ -371,4 +371,3 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@ describe('app', () => {
|
||||
).toMatchSnapshot();
|
||||
expect(tree.read('my-app/tsconfig.json', 'utf-8')).toMatchSnapshot();
|
||||
const packageJson = readJson(tree, 'package.json');
|
||||
expect(packageJson.devDependencies['vitest']).toEqual('~0.34.6');
|
||||
expect(packageJson.devDependencies['vitest']).toEqual('^1.0.4');
|
||||
});
|
||||
|
||||
it('should configure tsconfig and project.json correctly', () => {
|
||||
|
||||
@ -348,7 +348,7 @@ export default defineConfig({
|
||||
// },
|
||||
|
||||
test: {
|
||||
setupFiles: ['./test-setup.ts'],
|
||||
setupFiles: ['test-setup.ts'],
|
||||
globals: true,
|
||||
cache: {
|
||||
dir: '../node_modules/.vitest',
|
||||
@ -810,7 +810,7 @@ export default defineConfig({
|
||||
// },
|
||||
|
||||
test: {
|
||||
setupFiles: ['./test-setup.ts'],
|
||||
setupFiles: ['test-setup.ts'],
|
||||
globals: true,
|
||||
cache: {
|
||||
dir: '../../node_modules/.vitest',
|
||||
@ -1118,7 +1118,7 @@ export default defineConfig({
|
||||
// },
|
||||
|
||||
test: {
|
||||
setupFiles: ['./test-setup.ts'],
|
||||
setupFiles: ['test-setup.ts'],
|
||||
globals: true,
|
||||
cache: {
|
||||
dir: './node_modules/.vitest',
|
||||
|
||||
@ -43,7 +43,7 @@ export function updateUnitTestConfig(
|
||||
pathToViteConfig,
|
||||
'./tests/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'
|
||||
);
|
||||
updateViteTestSetup(tree, pathToViteConfig, './test-setup.ts');
|
||||
updateViteTestSetup(tree, pathToViteConfig, 'test-setup.ts');
|
||||
} else if (unitTestRunner === 'jest') {
|
||||
const pathToJestConfig = joinPathFragments(pathToRoot, 'jest.config.ts');
|
||||
tree.rename('jest.preset.js', 'jest.preset.cjs');
|
||||
|
||||
@ -45,9 +45,35 @@
|
||||
"version": "17.2.0-beta.10",
|
||||
"description": "Update vite config.",
|
||||
"implementation": "./src/migrations/update-17-2-0/update-vite-config"
|
||||
},
|
||||
"vitest-coverage-threshold": {
|
||||
"version": "17.3.0-beta.0",
|
||||
"description": "Move the vitest coverage thresholds in their own object if exists.",
|
||||
"implementation": "./src/migrations/update-17-3-0/vitest-coverage-threshold"
|
||||
}
|
||||
},
|
||||
"packageJsonUpdates": {
|
||||
"17.3.0": {
|
||||
"version": "17.3.0-beta.0",
|
||||
"packages": {
|
||||
"vitest": {
|
||||
"version": "^1.0.4",
|
||||
"alwaysAddToPackageJson": false
|
||||
},
|
||||
"@vitest/coverage-v8": {
|
||||
"version": "^1.0.4",
|
||||
"alwaysAddToPackageJson": false
|
||||
},
|
||||
"@vitest/ui": {
|
||||
"version": "^1.0.4",
|
||||
"alwaysAddToPackageJson": false
|
||||
},
|
||||
"@vitest/coverage-istanbul": {
|
||||
"version": "^1.0.4",
|
||||
"alwaysAddToPackageJson": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"17.2.0": {
|
||||
"version": "17.2.0-beta.2",
|
||||
"packages": {
|
||||
|
||||
@ -38,7 +38,7 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vite": "^5.0.0",
|
||||
"vitest": ">=0.34.6"
|
||||
"vitest": "^1.0.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
|
||||
@ -11,12 +11,12 @@ exports[`@nx/vite:init dependencies for package.json should add vite packages an
|
||||
"@swc-node/register": "~1.6.7",
|
||||
"@swc/core": "~1.3.85",
|
||||
"@vitejs/plugin-react": "^4.2.0",
|
||||
"@vitest/ui": "~0.34.6",
|
||||
"@vitest/ui": "^1.0.4",
|
||||
"existing": "1.0.0",
|
||||
"prettier": "^2.6.2",
|
||||
"typescript": "~5.2.2",
|
||||
"vite": "^5.0.0",
|
||||
"vitest": "~0.34.6",
|
||||
"vitest": "^1.0.4",
|
||||
},
|
||||
"name": "@proj/source",
|
||||
}
|
||||
@ -31,11 +31,11 @@ exports[`@nx/vite:init dependencies for package.json should support --testEnviro
|
||||
"@nx/vite": "0.0.1",
|
||||
"@swc-node/register": "~1.6.7",
|
||||
"@swc/core": "~1.3.85",
|
||||
"@vitest/ui": "~0.34.6",
|
||||
"@vitest/ui": "^1.0.4",
|
||||
"prettier": "^2.6.2",
|
||||
"typescript": "~5.2.2",
|
||||
"vite": "^5.0.0",
|
||||
"vitest": "~0.34.6",
|
||||
"vitest": "^1.0.4",
|
||||
},
|
||||
"name": "@proj/source",
|
||||
}
|
||||
@ -49,12 +49,12 @@ exports[`@nx/vite:init dependencies for package.json should support --testEnviro
|
||||
"@nx/vite": "0.0.1",
|
||||
"@swc-node/register": "~1.6.7",
|
||||
"@swc/core": "~1.3.85",
|
||||
"@vitest/ui": "~0.34.6",
|
||||
"@vitest/ui": "^1.0.4",
|
||||
"happy-dom": "~9.20.3",
|
||||
"prettier": "^2.6.2",
|
||||
"typescript": "~5.2.2",
|
||||
"vite": "^5.0.0",
|
||||
"vitest": "~0.34.6",
|
||||
"vitest": "^1.0.4",
|
||||
},
|
||||
"name": "@proj/source",
|
||||
}
|
||||
@ -68,12 +68,12 @@ exports[`@nx/vite:init dependencies for package.json should support --testEnviro
|
||||
"@nx/vite": "0.0.1",
|
||||
"@swc-node/register": "~1.6.7",
|
||||
"@swc/core": "~1.3.85",
|
||||
"@vitest/ui": "~0.34.6",
|
||||
"@vitest/ui": "^1.0.4",
|
||||
"jsdom": "~22.1.0",
|
||||
"prettier": "^2.6.2",
|
||||
"typescript": "~5.2.2",
|
||||
"vite": "^5.0.0",
|
||||
"vitest": "~0.34.6",
|
||||
"vitest": "^1.0.4",
|
||||
},
|
||||
"name": "@proj/source",
|
||||
}
|
||||
|
||||
@ -0,0 +1,165 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`vitest-coverage-threshold migration should move thresholds in threshold object - has 1 1`] = `
|
||||
"/// <reference types="vitest" />
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
|
||||
export default defineConfig({
|
||||
cacheDir: '../../node_modules/.vite/demo6',
|
||||
test: {
|
||||
globals: true,
|
||||
cache: {
|
||||
dir: '../node_modules/.vitest',
|
||||
},
|
||||
environment: 'jsdom',
|
||||
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
||||
reporters: ['default'],
|
||||
coverage: {
|
||||
thresholds: {
|
||||
branches: 75,
|
||||
},
|
||||
reportsDirectory: '../coverage/demo6',
|
||||
provider: 'v8',
|
||||
},
|
||||
},
|
||||
});
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`vitest-coverage-threshold migration should move thresholds in threshold object - has 2 1`] = `
|
||||
"/// <reference types="vitest" />
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
|
||||
export default defineConfig({
|
||||
cacheDir: '../../node_modules/.vite/demo3',
|
||||
test: {
|
||||
globals: true,
|
||||
cache: {
|
||||
dir: '../node_modules/.vitest',
|
||||
},
|
||||
environment: 'jsdom',
|
||||
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
||||
reporters: ['default'],
|
||||
coverage: {
|
||||
thresholds: {
|
||||
lines: 100,
|
||||
statements: 100,
|
||||
},
|
||||
reportsDirectory: '../coverage/demo3',
|
||||
provider: 'v8',
|
||||
},
|
||||
},
|
||||
});
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`vitest-coverage-threshold migration should move thresholds in threshold object - has 3 1`] = `
|
||||
"/// <reference types="vitest" />
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
|
||||
export default defineConfig({
|
||||
cacheDir: '../../node_modules/.vite/demo4',
|
||||
test: {
|
||||
globals: true,
|
||||
cache: {
|
||||
dir: '../node_modules/.vitest',
|
||||
},
|
||||
environment: 'jsdom',
|
||||
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
||||
reporters: ['default'],
|
||||
coverage: {
|
||||
thresholds: {
|
||||
lines: 100,
|
||||
statements: 100,
|
||||
|
||||
branches: 75,
|
||||
},
|
||||
reportsDirectory: '../coverage/demo4',
|
||||
provider: 'v8',
|
||||
},
|
||||
},
|
||||
});
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`vitest-coverage-threshold migration should move thresholds in threshold object - has all 1`] = `
|
||||
"/// <reference types="vitest" />
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
|
||||
export default defineConfig({
|
||||
cacheDir: '../../node_modules/.vite/demo5',
|
||||
test: {
|
||||
globals: true,
|
||||
cache: {
|
||||
dir: '../node_modules/.vitest',
|
||||
},
|
||||
environment: 'jsdom',
|
||||
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
||||
reporters: ['default'],
|
||||
coverage: {
|
||||
thresholds: {
|
||||
lines: 100,
|
||||
statements: 100,
|
||||
functions: 60,
|
||||
branches: 75,
|
||||
},
|
||||
reportsDirectory: '../coverage/demo5',
|
||||
provider: 'v8',
|
||||
},
|
||||
},
|
||||
});
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`vitest-coverage-threshold migration should not do anything if coverage but no thresholds 1`] = `
|
||||
"/// <reference types="vitest" />
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
|
||||
export default defineConfig({
|
||||
cacheDir: '../../node_modules/.vite/demo2',
|
||||
test: {
|
||||
globals: true,
|
||||
cache: {
|
||||
dir: '../node_modules/.vitest',
|
||||
},
|
||||
environment: 'jsdom',
|
||||
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
||||
reporters: ['default'],
|
||||
coverage: {
|
||||
reportsDirectory: '../coverage/demo2',
|
||||
provider: 'v8',
|
||||
},
|
||||
},
|
||||
});
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`vitest-coverage-threshold migration should not do anything if no coverage 1`] = `
|
||||
"/// <reference types="vitest" />
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
|
||||
export default defineConfig({
|
||||
cacheDir: '../../node_modules/.vite/demo',
|
||||
test: {
|
||||
globals: true,
|
||||
cache: {
|
||||
dir: '../../node_modules/.vitest',
|
||||
},
|
||||
environment: 'jsdom',
|
||||
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
||||
},
|
||||
});
|
||||
"
|
||||
`;
|
||||
132
packages/vite/src/migrations/update-17-3-0/lib/fix-coverage.ts
Normal file
132
packages/vite/src/migrations/update-17-3-0/lib/fix-coverage.ts
Normal file
@ -0,0 +1,132 @@
|
||||
import { ChangeType, applyChangesToString } from '@nx/devkit';
|
||||
import { tsquery } from '@phenomnomnominal/tsquery';
|
||||
import ts = require('typescript');
|
||||
|
||||
export function fixCoverage(configContents: string): string | undefined {
|
||||
const configNode = getConfigNode(configContents);
|
||||
if (!configNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
const testHasCoverage = tsquery.query(
|
||||
configNode,
|
||||
`PropertyAssignment:has(Identifier[name="test"]):has(PropertyAssignment:has(Identifier[name="coverage"]))`
|
||||
)?.[0];
|
||||
let changes = [];
|
||||
|
||||
if (!testHasCoverage) {
|
||||
return;
|
||||
}
|
||||
const testObjectLiteralExpressionNode = tsquery.query(
|
||||
testHasCoverage,
|
||||
`ObjectLiteralExpression:has(Identifier[name="coverage"])`
|
||||
)?.[0];
|
||||
const coverageNode = findCoverageNode(testObjectLiteralExpressionNode);
|
||||
console.log('coverage node', coverageNode?.getText());
|
||||
console.log('coverage node getStart', coverageNode?.getStart());
|
||||
|
||||
if (!coverageNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
const linesNode = tsquery.query(
|
||||
coverageNode,
|
||||
`PropertyAssignment:has(Identifier[name="lines"])`
|
||||
)?.[0];
|
||||
|
||||
const statementsNode = tsquery.query(
|
||||
coverageNode,
|
||||
`PropertyAssignment:has(Identifier[name="statements"])`
|
||||
)?.[0];
|
||||
|
||||
const functionsNode = tsquery.query(
|
||||
coverageNode,
|
||||
`PropertyAssignment:has(Identifier[name="functions"])`
|
||||
)?.[0];
|
||||
|
||||
const branchesNode = tsquery.query(
|
||||
coverageNode,
|
||||
`PropertyAssignment:has(Identifier[name="branches"])`
|
||||
)?.[0];
|
||||
|
||||
if (linesNode) {
|
||||
changes.push({
|
||||
type: ChangeType.Delete,
|
||||
start: linesNode.getStart(),
|
||||
length: linesNode.getWidth() + 1,
|
||||
});
|
||||
}
|
||||
if (statementsNode) {
|
||||
changes.push({
|
||||
type: ChangeType.Delete,
|
||||
start: statementsNode.getStart(),
|
||||
length: statementsNode.getWidth() + 1,
|
||||
});
|
||||
}
|
||||
|
||||
if (functionsNode) {
|
||||
changes.push({
|
||||
type: ChangeType.Delete,
|
||||
start: functionsNode.getStart(),
|
||||
length: functionsNode.getWidth() + 1,
|
||||
});
|
||||
}
|
||||
|
||||
if (branchesNode) {
|
||||
changes.push({
|
||||
type: ChangeType.Delete,
|
||||
start: branchesNode.getStart(),
|
||||
length: branchesNode.getWidth() + 1,
|
||||
});
|
||||
}
|
||||
|
||||
if (branchesNode || functionsNode || statementsNode || linesNode) {
|
||||
changes.push({
|
||||
type: ChangeType.Insert,
|
||||
index: coverageNode.getStart() + 1,
|
||||
text: `thresholds: {
|
||||
${linesNode ? linesNode.getText() + ',' : ''}
|
||||
${statementsNode ? statementsNode.getText() + ',' : ''}
|
||||
${functionsNode ? functionsNode.getText() + ',' : ''}
|
||||
${branchesNode ? branchesNode.getText() + ',' : ''}
|
||||
},`,
|
||||
});
|
||||
}
|
||||
|
||||
if (changes.length > 0) {
|
||||
return applyChangesToString(configContents, changes);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
export function getConfigNode(configFileContents: string): ts.Node | undefined {
|
||||
if (!configFileContents) {
|
||||
return;
|
||||
}
|
||||
let configNode = tsquery.query(
|
||||
configFileContents,
|
||||
`ObjectLiteralExpression`
|
||||
)?.[0];
|
||||
|
||||
const arrowFunctionReturnStatement = tsquery.query(
|
||||
configFileContents,
|
||||
`ArrowFunction Block ReturnStatement ObjectLiteralExpression`
|
||||
)?.[0];
|
||||
|
||||
if (arrowFunctionReturnStatement) {
|
||||
configNode = arrowFunctionReturnStatement;
|
||||
}
|
||||
|
||||
return configNode;
|
||||
}
|
||||
|
||||
function findCoverageNode(testNode: ts.Node) {
|
||||
let coverageNode: ts.Node | undefined;
|
||||
testNode.forEachChild((child) => {
|
||||
if (ts.isPropertyAssignment(child) && child.name.getText() === 'coverage') {
|
||||
coverageNode = child.initializer;
|
||||
}
|
||||
});
|
||||
return coverageNode;
|
||||
}
|
||||
@ -0,0 +1,291 @@
|
||||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
||||
import { Tree, addProjectConfiguration } from '@nx/devkit';
|
||||
import fixCoverageThreshold from './vitest-coverage-threshold';
|
||||
|
||||
describe('vitest-coverage-threshold migration', () => {
|
||||
let tree: Tree;
|
||||
|
||||
beforeEach(() => {
|
||||
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
|
||||
});
|
||||
|
||||
it('should not do anything if no coverage', async () => {
|
||||
addProject1(tree, 'demo');
|
||||
await fixCoverageThreshold(tree);
|
||||
expect(tree.read('apps/demo/vite.config.ts', 'utf-8')).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should not do anything if coverage but no thresholds', async () => {
|
||||
addProject2(tree, 'demo2');
|
||||
await fixCoverageThreshold(tree);
|
||||
expect(tree.read('demo2/vite.config.ts', 'utf-8')).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should move thresholds in threshold object - has 2', async () => {
|
||||
addProject3(tree, 'demo3');
|
||||
await fixCoverageThreshold(tree);
|
||||
expect(tree.read('demo3/vite.config.ts', 'utf-8')).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should move thresholds in threshold object - has 3', async () => {
|
||||
addProject4(tree, 'demo4');
|
||||
await fixCoverageThreshold(tree);
|
||||
expect(tree.read('demo4/vite.config.ts', 'utf-8')).toMatchSnapshot();
|
||||
});
|
||||
it('should move thresholds in threshold object - has all', async () => {
|
||||
addProject5(tree, 'demo5');
|
||||
await fixCoverageThreshold(tree);
|
||||
expect(tree.read('demo5/vite.config.ts', 'utf-8')).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should move thresholds in threshold object - has 1', async () => {
|
||||
addProject6(tree, 'demo6');
|
||||
await fixCoverageThreshold(tree);
|
||||
expect(tree.read('demo6/vite.config.ts', 'utf-8')).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
function addProject1(tree: Tree, name: string) {
|
||||
addProjectConfiguration(tree, name, {
|
||||
root: `apps/${name}`,
|
||||
sourceRoot: `apps/${name}/src`,
|
||||
targets: {
|
||||
test: {
|
||||
executor: '@nx/vite:test',
|
||||
options: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
tree.write(
|
||||
`apps/${name}/vite.config.ts`,
|
||||
`
|
||||
/// <reference types="vitest" />
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
|
||||
export default defineConfig({
|
||||
cacheDir: '../../node_modules/.vite/${name}',
|
||||
test: {
|
||||
globals: true,
|
||||
cache: {
|
||||
dir: '../../node_modules/.vitest',
|
||||
},
|
||||
environment: 'jsdom',
|
||||
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
||||
},
|
||||
});
|
||||
|
||||
`
|
||||
);
|
||||
}
|
||||
|
||||
function addProject2(tree: Tree, name: string) {
|
||||
addProjectConfiguration(tree, name, {
|
||||
root: `${name}`,
|
||||
sourceRoot: `${name}/src`,
|
||||
targets: {
|
||||
test: {
|
||||
executor: '@nx/vite:test',
|
||||
options: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
tree.write(
|
||||
`${name}/vite.config.ts`,
|
||||
`
|
||||
/// <reference types="vitest" />
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
|
||||
export default defineConfig({
|
||||
cacheDir: '../../node_modules/.vite/${name}',
|
||||
test: {
|
||||
globals: true,
|
||||
cache: {
|
||||
dir: '../node_modules/.vitest',
|
||||
},
|
||||
environment: 'jsdom',
|
||||
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
||||
reporters: ['default'],
|
||||
coverage: {
|
||||
reportsDirectory: '../coverage/${name}',
|
||||
provider: 'v8',
|
||||
},
|
||||
},
|
||||
});
|
||||
`
|
||||
);
|
||||
}
|
||||
|
||||
function addProject3(tree: Tree, name: string) {
|
||||
addProjectConfiguration(tree, name, {
|
||||
root: `${name}`,
|
||||
sourceRoot: `${name}/src`,
|
||||
targets: {
|
||||
test: {
|
||||
executor: '@nx/vite:test',
|
||||
options: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
tree.write(
|
||||
`${name}/vite.config.ts`,
|
||||
`
|
||||
/// <reference types="vitest" />
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
|
||||
export default defineConfig({
|
||||
cacheDir: '../../node_modules/.vite/${name}',
|
||||
test: {
|
||||
globals: true,
|
||||
cache: {
|
||||
dir: '../node_modules/.vitest',
|
||||
},
|
||||
environment: 'jsdom',
|
||||
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
||||
reporters: ['default'],
|
||||
coverage: {
|
||||
reportsDirectory: '../coverage/${name}',
|
||||
provider: 'v8',
|
||||
lines: 100,
|
||||
statements: 100,
|
||||
},
|
||||
},
|
||||
});
|
||||
`
|
||||
);
|
||||
}
|
||||
|
||||
function addProject4(tree: Tree, name: string) {
|
||||
addProjectConfiguration(tree, name, {
|
||||
root: `${name}`,
|
||||
sourceRoot: `${name}/src`,
|
||||
targets: {
|
||||
test: {
|
||||
executor: '@nx/vite:test',
|
||||
options: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
tree.write(
|
||||
`${name}/vite.config.ts`,
|
||||
`
|
||||
/// <reference types="vitest" />
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
|
||||
export default defineConfig({
|
||||
cacheDir: '../../node_modules/.vite/${name}',
|
||||
test: {
|
||||
globals: true,
|
||||
cache: {
|
||||
dir: '../node_modules/.vitest',
|
||||
},
|
||||
environment: 'jsdom',
|
||||
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
||||
reporters: ['default'],
|
||||
coverage: {
|
||||
reportsDirectory: '../coverage/${name}',
|
||||
provider: 'v8',
|
||||
lines: 100,
|
||||
statements: 100,
|
||||
branches: 75,
|
||||
},
|
||||
},
|
||||
});
|
||||
`
|
||||
);
|
||||
}
|
||||
|
||||
function addProject5(tree: Tree, name: string) {
|
||||
addProjectConfiguration(tree, name, {
|
||||
root: `${name}`,
|
||||
sourceRoot: `${name}/src`,
|
||||
targets: {
|
||||
test: {
|
||||
executor: '@nx/vite:test',
|
||||
options: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
tree.write(
|
||||
`${name}/vite.config.ts`,
|
||||
`
|
||||
/// <reference types="vitest" />
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
|
||||
export default defineConfig({
|
||||
cacheDir: '../../node_modules/.vite/${name}',
|
||||
test: {
|
||||
globals: true,
|
||||
cache: {
|
||||
dir: '../node_modules/.vitest',
|
||||
},
|
||||
environment: 'jsdom',
|
||||
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
||||
reporters: ['default'],
|
||||
coverage: {
|
||||
reportsDirectory: '../coverage/${name}',
|
||||
provider: 'v8',
|
||||
lines: 100,
|
||||
statements: 100,
|
||||
branches: 75,
|
||||
functions: 60,
|
||||
},
|
||||
},
|
||||
});
|
||||
`
|
||||
);
|
||||
}
|
||||
function addProject6(tree: Tree, name: string) {
|
||||
addProjectConfiguration(tree, name, {
|
||||
root: `${name}`,
|
||||
sourceRoot: `${name}/src`,
|
||||
targets: {
|
||||
test: {
|
||||
executor: '@nx/vite:test',
|
||||
options: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
tree.write(
|
||||
`${name}/vite.config.ts`,
|
||||
`
|
||||
/// <reference types="vitest" />
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
|
||||
export default defineConfig({
|
||||
cacheDir: '../../node_modules/.vite/${name}',
|
||||
test: {
|
||||
globals: true,
|
||||
cache: {
|
||||
dir: '../node_modules/.vitest',
|
||||
},
|
||||
environment: 'jsdom',
|
||||
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
||||
reporters: ['default'],
|
||||
coverage: {
|
||||
reportsDirectory: '../coverage/${name}',
|
||||
provider: 'v8',
|
||||
branches: 75,
|
||||
},
|
||||
},
|
||||
});
|
||||
`
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
import {
|
||||
ProjectConfiguration,
|
||||
Tree,
|
||||
formatFiles,
|
||||
getProjects,
|
||||
joinPathFragments,
|
||||
} from '@nx/devkit';
|
||||
import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils';
|
||||
import { fixCoverage } from './lib/fix-coverage';
|
||||
|
||||
export default async function fixCoverageThreshold(tree: Tree) {
|
||||
const projects = getProjects(tree);
|
||||
forEachExecutorOptions(tree, '@nx/vite:test', (_options, projectName) => {
|
||||
const projectConfig: ProjectConfiguration = projects.get(
|
||||
projectName
|
||||
) as ProjectConfiguration;
|
||||
const configPath = findViteConfig(tree, projectConfig.root);
|
||||
if (!configPath || !tree.exists(configPath)) {
|
||||
return;
|
||||
}
|
||||
const configContents = tree.read(configPath, 'utf-8') as string;
|
||||
|
||||
const updatedConfigContents = fixCoverage(configContents);
|
||||
|
||||
if (updatedConfigContents) {
|
||||
tree.write(configPath, updatedConfigContents);
|
||||
}
|
||||
});
|
||||
|
||||
await formatFiles(tree);
|
||||
}
|
||||
|
||||
function findViteConfig(tree: Tree, searchRoot: string) {
|
||||
const allowsExt = ['js', 'mjs', 'ts', 'cjs', 'mts', 'cts'];
|
||||
|
||||
for (const ext of allowsExt) {
|
||||
if (tree.exists(joinPathFragments(searchRoot, `vite.config.${ext}`))) {
|
||||
return joinPathFragments(searchRoot, `vite.config.${ext}`);
|
||||
} else if (
|
||||
tree.exists(joinPathFragments(searchRoot, `vitest.config.${ext}`))
|
||||
) {
|
||||
return joinPathFragments(searchRoot, `vitest.config.${ext}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
export const nxVersion = require('../../package.json').version;
|
||||
export const viteVersion = '^5.0.0';
|
||||
export const vitestVersion = '~0.34.6';
|
||||
export const vitestVersion = '^1.0.4';
|
||||
export const vitePluginReactVersion = '^4.2.0';
|
||||
export const vitePluginReactSwcVersion = '^3.5.0';
|
||||
export const jsdomVersion = '~22.1.0';
|
||||
@ -9,5 +9,5 @@ export const happyDomVersion = '~9.20.3';
|
||||
export const edgeRuntimeVmVersion = '~3.0.2';
|
||||
|
||||
// Coverage providers
|
||||
export const vitestCoverageV8Version = '~0.34.6';
|
||||
export const vitestCoverageIstanbulVersion = '~0.34.6';
|
||||
export const vitestCoverageV8Version = '^1.0.4';
|
||||
export const vitestCoverageIstanbulVersion = '^1.0.4';
|
||||
|
||||
@ -113,8 +113,8 @@ exports[`lib should add vue, vite and vitest to package.json 1`] = `
|
||||
"@typescript-eslint/eslint-plugin": "^6.13.2",
|
||||
"@typescript-eslint/parser": "^6.13.2",
|
||||
"@vitejs/plugin-vue": "^4.5.0",
|
||||
"@vitest/coverage-v8": "~0.34.6",
|
||||
"@vitest/ui": "~0.34.6",
|
||||
"@vitest/coverage-v8": "^1.0.4",
|
||||
"@vitest/ui": "^1.0.4",
|
||||
"@vue/eslint-config-prettier": "7.1.0",
|
||||
"@vue/eslint-config-typescript": "^11.0.3",
|
||||
"@vue/test-utils": "^2.4.1",
|
||||
@ -126,7 +126,7 @@ exports[`lib should add vue, vite and vitest to package.json 1`] = `
|
||||
"prettier": "^2.6.2",
|
||||
"typescript": "~5.2.2",
|
||||
"vite": "^5.0.0",
|
||||
"vitest": "~0.34.6",
|
||||
"vitest": "^1.0.4",
|
||||
"vue-tsc": "^1.8.8",
|
||||
},
|
||||
"name": "@proj/source",
|
||||
|
||||
459
pnpm-lock.yaml
generated
459
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user