Skip to content

Commit 2b83896

Browse files
committed
feat(vitest): modernize AE and support Vitest 4
1 parent 3057faa commit 2b83896

14 files changed

Lines changed: 1773 additions & 238 deletions

File tree

packages/e2e-cypress/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
// We don't have this problem with Jest twin `installQuasarPlugin` as Jest adds a compilation step anyway and lodash-es
1818
// transpilation is performed in there
1919
"module": "commonjs",
20+
"moduleResolution": "node",
2021
"skipLibCheck": true,
2122
// Without this, TS won't be able to load correctly Quasar deep imports into `injectDevServer` (eg. `@quasar/app/lib/helpers/get-quasar-ctx`)
2223
"esModuleInterop": true,

packages/unit-vitest/.npmignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
.thumbs.db
3+
.eslintignore
4+
.eslintrc.js
5+
tsconfig.json

packages/unit-vitest/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,17 @@ Please check out ["@vue/test-utils" official documentation](https://vue-test-uti
6464

6565
If you're migrating from Jest to Vitest, please check out the official [migration guide](https://vitest.dev/guide/migration.html#migrating-from-jest).
6666

67-
### Upgrade from Vitest AE v0.4 to v1.0 onwards
67+
### Upgrade from Vitest AE v1.x to v2.0 onwards
6868

69-
All changes are related to Vitest v1.0 breaking changes, Quasar first-party helpers haven't changed.
69+
Quasar first-party helpers haven't changed.
70+
All changes are related to Vitest v4.0 breaking changes or ecosystem deprecations.
7071

71-
- Upgrade Node to v18 or newer, v20 is preferred due to some quirks in v18;
72-
- Upgrade all Vitest related dependencies, especially `@vue/test-utils`, `vitest` and `@vitest/ui`, which minimum peer dependencies versions has been bumped. If you don't want to upgrade these dependencies manually, you can just re-install the AE and it will update all dependencies for you;
72+
- Upgrade Node to v20.19.0 or newer, but v22.12.0 is preferred. Those versions has been chosen to get `require`-working-with-ESM feature enabled by default, since many packages (e.g. `happy-dom`) rely on;
73+
- (**optional**) Upgrade `typescript` to v5.8 or later, which supports `require`-working-with-ESM feature;
7374
- (**optional**) Upgrade `vue` and `quasar` dependencies to the latest version;
74-
- Rename `vitest.config.[js|ts]` to `vitest.config.[mjs|mts]` or switch your project to "ESM by default" adding `"type": "module"` option in `package.json`. Check out [here](https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated) why CJS build and syntax are deprecated in Vite 5;
75-
- Vitest 1.0 requires Vite 5, thus you'll need to upgrade `@quasar/app-vite` to v2. If you can't migrate away from v1 yet, you can use this [workaround](https://github.com/quasarframework/quasar/issues/14077#issuecomment-1851463530) until you can migrate. We do test against the setup using that workaround, to ease the migration, but bear in mind that we don't consider it as "officially supported" and we will stop testing against it in the near future;
76-
- Follow Vitest [upgrade guide](https://vitest.dev/guide/migration.html#migrating-from-vitest-0-34-6) to upgrade from Vitest v34.6 to v1.0
75+
- Upgrade `@quasar/app-vite` to v2.4 or later, which uses Vite 7;
76+
- Upgrade all Vitest related packages, in particular `vitest` and `@vitest/ui` to v4.0 or later. If you don't want to upgrade these dependencies manually, you can just re-install the AE and it will update all dependencies for you. Vitest v1, v2 and v3 are no longer supported;
77+
- Follow Vitest [upgrade guide](https://vitest.dev/guide/migration#vitest-4) to upgrade from Vitest v3.0 to v4.0;
7778

7879
### installQuasarPlugin(options)
7980

packages/unit-vitest/package.json

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "@quasar/quasar-app-extension-testing-unit-vitest",
3-
"version": "1.2.4",
3+
"version": "2.0.0",
4+
"type": "module",
45
"license": "MIT",
56
"description": "A Quasar App Extension for running tests with Vitest",
67
"contributors": [
@@ -21,32 +22,50 @@
2122
"publishConfig": {
2223
"access": "public"
2324
},
24-
"main": "dist/main.js",
25-
"typings": "dist/types/main.d.ts",
25+
"main": "./dist/helpers/main.js",
26+
"module": "./dist/helpers/main.js",
27+
"types": "./dist/helpers/main.d.ts",
28+
"exports": {
29+
".": {
30+
"import": "./src/helpers/main.ts"
31+
},
32+
"./package.json": "./package.json",
33+
"./dist/index": "./src/index.ts",
34+
"./dist/install": "./src/install.ts"
35+
},
2636
"engines": {
27-
"node": "^30 || ^28 || ^26 || ^24 || ^22 || ^20 || ^18",
28-
"npm": ">= 9.5",
37+
"node": "^30 || ^28 || ^26 || ^24 || ^22.12.0 || ^20.19.0",
38+
"npm": ">= 10",
2939
"yarn": ">= 1.22.19"
3040
},
3141
"dependencies": {
32-
"happy-dom": "^15.0.0",
42+
"es-toolkit": "^1.42.0",
43+
"happy-dom": "^20.0.10",
3344
"lodash-es": "^4.17.21",
3445
"vite-tsconfig-paths": "^5.1.4"
3546
},
47+
"devDependenciesComments": {
48+
"@quasar/app-vite": "Only used to typecheck AE TS files",
49+
"@quasar/vite-plugin": "Only used to typecheck vitest.config.ts, provided by @quasar/app-vite",
50+
"@vitejs/plugin-vue": "Only used to typecheck vitest.config.ts"
51+
},
3652
"devDependencies": {
53+
"@quasar/app-vite": "^2.4.0",
3754
"@types/lodash-es": "^4.17.12",
38-
"@vitest/ui": "^3.2.4",
55+
"@vitejs/plugin-vue": "^6.0.2",
56+
"@vitest/ui": "^4.0.13",
3957
"@vue/test-utils": "^2.4.6",
40-
"quasar": "^2.18.1",
41-
"rimraf": "^6.0.1",
42-
"vitest": "^3.2.4",
43-
"vue": "^3.5.13"
58+
"quasar": "^2.18.6",
59+
"rimraf": "^6.1.2",
60+
"vitest": "^4.0.13",
61+
"vue": "^3.5.25"
4462
},
4563
"peerDependencies": {
46-
"@vitest/ui": "^1.1.0 || ^2.0.0 || ^3.0.0",
47-
"@vue/test-utils": "^2.4.3",
64+
"@quasar/app-vite": "^2.4.0",
65+
"@vitest/ui": "^4.0.0",
66+
"@vue/test-utils": "^2.4.6",
4867
"quasar": "^2.12.7",
49-
"vitest": "^1.6.1 || ^2.1.9 || ^3.0.5",
68+
"vitest": "^4.0.0",
5069
"vue": "^3.3.4"
5170
},
5271
"peerDependenciesMeta": {

packages/unit-vitest/src/index.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/unit-vitest/src/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Quasar App Extension index/runner script
3+
* (runs on each dev/build)
4+
*
5+
* Docs: https://quasar.dev/app-extensions/development-guide/index-api
6+
*/
7+
8+
import { IndexAPI } from '@quasar/app-vite';
9+
10+
export default function index(api: IndexAPI) {
11+
api.compatibleWith('quasar', '^2.12.7');
12+
api.compatibleWith('@quasar/app-vite', '^2.4.0');
13+
}

packages/unit-vitest/src/install.js

Lines changed: 0 additions & 100 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { InstallAPI } from '@quasar/app-vite';
2+
import { merge } from 'es-toolkit';
3+
4+
type PackageJson = Record<string, Record<string, string>>;
5+
6+
function getCompatibleDevDependencies(
7+
aeDevDependencies: PackageJson[string],
8+
packageNames: (keyof typeof aeDevDependencies)[],
9+
) {
10+
const devDependencies: PackageJson[string] = {};
11+
12+
for (const packageName of packageNames) {
13+
devDependencies[packageName] = aeDevDependencies[packageName];
14+
}
15+
16+
return devDependencies;
17+
}
18+
19+
export default async function (api: InstallAPI) {
20+
// We use devDependencies instead of peerDependencies because devDependencies are usually the latest version
21+
// and peerDependencies could contain a string supporting multiple major versions (e.g. "cypress": "^12.2.0 || ^13.1.0")
22+
const { devDependencies: aeDevDependencies } = (await import(
23+
// We can't import it statically, it would cause a problem with the built output folder structure
24+
// and `@quasar/app-vite` expects to find AE files (install.js, etc) at the first level of the `dist` folder
25+
import.meta.dirname + '../package.json'
26+
)) as PackageJson;
27+
28+
const extendPackageJson: PackageJson = {
29+
devDependencies: getCompatibleDevDependencies(aeDevDependencies, [
30+
'@vue/test-utils',
31+
'vitest',
32+
]),
33+
};
34+
35+
api.compatibleWith('quasar', '^2.12.7');
36+
api.compatibleWith('vue', '^3.3.4');
37+
api.compatibleWith('@quasar/app-vite', '^2.4.0');
38+
39+
api.render(
40+
`./templates/${(await api.hasTypescript()) ? '' : 'no-'}typescript`,
41+
);
42+
43+
if ((api.prompts.options as string[]).includes('ui')) {
44+
const ui: PackageJson = {
45+
devDependencies: getCompatibleDevDependencies(aeDevDependencies, [
46+
'@vitest/ui',
47+
]),
48+
};
49+
50+
ui.scripts = {
51+
'test:unit:ui': 'vitest --ui',
52+
};
53+
54+
merge(extendPackageJson, ui);
55+
}
56+
57+
const scripts = {
58+
scripts: {
59+
test: 'echo "See package.json => scripts for available tests." && exit 0',
60+
'test:unit': 'vitest',
61+
'test:unit:ci': 'vitest run',
62+
},
63+
};
64+
merge(extendPackageJson, scripts);
65+
66+
api.extendPackageJson(extendPackageJson);
67+
68+
if (await api.hasLint()) {
69+
api.onExitLog(
70+
'Check out https://github.com/quasarframework/quasar-testing/tree/dev/packages/unit-vitest to see how to add proper Vitest linting configuration to your project.',
71+
);
72+
}
73+
}

packages/unit-vitest/src/prompts.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)