Skip to content

Commit

Permalink
feat(vite): update to vitest v1 (nrwl#20747)
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini authored Dec 14, 2023
1 parent 85fa68b commit cac2c17
Show file tree
Hide file tree
Showing 15 changed files with 967 additions and 227 deletions.
29 changes: 11 additions & 18 deletions e2e/vite/src/vite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,37 +240,30 @@ 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: {
dir: '../../node_modules/.vitest',
},
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,
}
},
},
});
`;
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand All @@ -371,4 +371,3 @@
]
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export default defineConfig({
// },
test: {
setupFiles: ['./test-setup.ts'],
setupFiles: ['test-setup.ts'],
globals: true,
cache: {
dir: '../node_modules/.vitest',
Expand Down Expand Up @@ -810,7 +810,7 @@ export default defineConfig({
// },
test: {
setupFiles: ['./test-setup.ts'],
setupFiles: ['test-setup.ts'],
globals: true,
cache: {
dir: '../../node_modules/.vitest',
Expand Down Expand Up @@ -1118,7 +1118,7 @@ export default defineConfig({
// },
test: {
setupFiles: ['./test-setup.ts'],
setupFiles: ['test-setup.ts'],
globals: true,
cache: {
dir: './node_modules/.vitest',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
26 changes: 26 additions & 0 deletions packages/vite/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"peerDependencies": {
"vite": "^5.0.0",
"vitest": ">=0.34.6"
"vitest": "^1.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand All @@ -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",
}
Expand All @@ -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",
}
Expand All @@ -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",
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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}'],
},
});
"
`;
Loading

0 comments on commit cac2c17

Please sign in to comment.