Skip to content

Commit 5b036e8

Browse files
dominikgbluwy
andauthored
refactor: replace jest with vitest using a similar approach as vite (#337)
* refactor: replace jest with vitest using a similar approach as vite * ci: check if 2 workers are faster than one * fix: update unit test * fix: update ~utils types * chore: increase connect url timeout * chore: remove unused await * chore: try 1 thread * fix: preserve temp dir on ci, align env names to TEST_ * fix: vitest uses posix paths on windows * ci: try 4 threads * fix: return to 1 thread on ci * ci: use windows-latest again and add node18 * chore: run build tests before serve tests because they are less likely to fail * refactor: convert test apps to esm, rebuild kit-node app with latest kit, update execa and node-fetch, fix issue with fetch on node18 * fix: revert preprocess-with-vite to cjs hoping it finds stylus correctly again, fetch as util * fix: force glob to version that includes fix for breaking windows change * fix: stabilize local tests by limiting max threads, improve untilUpdated utility, remove useless code * chore: clean up test Co-authored-by: bluwy <[email protected]>
1 parent a6a8e00 commit 5b036e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1045
-3041
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ indent_size = 2
88
charset = utf-8
99
trim_trailing_whitespace = true
1010

11-
[{**/package.json, **/README.md, docs/**/*.md}]
11+
[{package.json,README.md, docs/**/*.md}]
1212
indent_style = space

.eslintrc.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,23 +145,10 @@ module.exports = {
145145
node: true,
146146
browser: true
147147
},
148-
// Can't extend in overrides: https://github.com/eslint/eslint/issues/8813
149-
// "extends": ["plugin:jest/recommended"]
150-
plugins: ['jest'],
151148
rules: {
152-
'jest/no-disabled-tests': 'warn',
153-
'jest/no-focused-tests': 'error',
154-
'jest/no-identical-title': 'error',
155-
'jest/prefer-to-have-length': 'warn',
156-
'jest/valid-expect': 'error'
157-
}
158-
},
159-
{
160-
files: ['scripts/**'],
161-
env: {
162-
jest: true,
163-
node: true,
164-
browser: false
149+
'node/no-extraneous-import': 'off',
150+
'node/no-missing-import': 'off',
151+
'node/no-unused-import': 'off'
165152
}
166153
},
167154
{

.github/workflows/ci.yml

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# build and test on linux, windows, mac with node 14, 16, 17
1+
# build and test on linux, windows, mac with node 14, 16, 18
22
name: CI
33

44
on:
@@ -50,7 +50,7 @@ jobs:
5050
if: (${{ success() }} || ${{ failure() }})
5151
run: pnpm audit
5252

53-
# this is the test matrix, it runs with node16 on linux,windows,macos + node14,17 on linux
53+
# this is the test matrix, it runs with node16 on linux,windows,macos + node14,18 on linux
5454
# it is skipped if the build step of the checks job wasn't successful (still runs if lint or audit fail)
5555
test:
5656
needs: checks
@@ -61,10 +61,12 @@ jobs:
6161
fail-fast: false
6262
matrix:
6363
node: [16]
64-
os: [ubuntu-latest, macos-latest, windows-2019]
64+
os: [ubuntu-latest, macos-latest, windows-latest]
6565
include:
6666
- node: 14
6767
os: ubuntu-latest
68+
- node: 18
69+
os: ubuntu-latest
6870
steps:
6971
- uses: actions/checkout@v3
7072
- uses: actions/setup-node@v3
@@ -86,7 +88,7 @@ jobs:
8688
- name: build
8789
run: pnpm build:ci
8890
- name: run tests
89-
run: pnpm test:ci
91+
run: pnpm test
9092
- name: archive tests temp directory
9193
if: failure()
9294
shell: bash
@@ -97,17 +99,4 @@ jobs:
9799
name: test-failure-${{github.run_id}}-${{ matrix.os }}-${{ matrix.node }}
98100
path: |
99101
test-temp.tar
100-
temp/serve/jest-results.json
101-
temp/serve/junit.xml
102-
temp/build/jest-results.json
103-
temp/build/junit.xml
104102
pnpm-debug.log
105-
- uses: actions/upload-artifact@v3
106-
if: success()
107-
with:
108-
name: test-success-${{github.run_id}}-${{ matrix.os }}-${{ matrix.node }}
109-
path: |
110-
temp/serve/jest-results.json
111-
temp/serve/junit.xml
112-
temp/build/jest-results.json
113-
temp/build/junit.xml

jest.config.js

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

package.json

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@
55
"dev": "pnpm --dir packages/vite-plugin-svelte dev",
66
"build:ci": "pnpm --dir packages/vite-plugin-svelte build:ci",
77
"build": "pnpm --dir packages/vite-plugin-svelte build",
8-
"test": "run-s test:serve test:build",
9-
"test:serve": "jest",
10-
"test:serve:debug": "cross-env DEBUG=pw:api VITE_DEBUG_SERVE=1 node --inspect-brk ./node_modules/jest/bin/jest --runInBand",
11-
"test:build": "cross-env VITE_TEST_BUILD=1 jest",
12-
"test:build:debug": "cross-env DEBUG=pw:api VITE_TEST_BUILD=1 VITE_PRESERVE_BUILD_ARTIFACTS=1 node --inspect-brk ./node_modules/jest/bin/jest --runInBand",
13-
"test:ci": "run-s test:ci:serve test:ci:build",
14-
"test:ci:serve": "cross-env VITE_PRESERVE_BUILD_ARTIFACTS=1 jest --verbose --no-cache --runInBand --force-exit --ci --json --outputFile=\"temp/serve/jest-results.json\"",
15-
"test:ci:build": "cross-env VITE_TEST_BUILD=1 VITE_PRESERVE_BUILD_ARTIFACTS=1 jest --verbose --no-cache --runInBand --force-exit --ci --json --outputFile=\"temp/build/jest-results.json\"",
8+
"test": "run-s -c test:unit test:build test:serve",
9+
"test:unit": "vitest run",
10+
"test:serve": "vitest run -c vitest.config.e2e.ts",
11+
"test:build": "cross-env TEST_BUILD=1 vitest run -c vitest.config.e2e.ts",
1612
"lint": "eslint --ignore-path .gitignore '**/*.{js,ts,svelte,html,svx,md}'",
1713
"lint:fix": "pnpm lint --fix",
1814
"format": "prettier --ignore-path .gitignore '**/*.{css,scss,svelte,html,js,ts,svx,md}' --check",
@@ -25,7 +21,6 @@
2521
"@changesets/cli": "^2.22.0",
2622
"@svitejs/changesets-changelog-github-compact": "^0.1.1",
2723
"@types/fs-extra": "^9.0.13",
28-
"@types/jest": "^27.5.0",
2924
"@types/node": "^17.0.21",
3025
"@types/semver": "^7.3.9",
3126
"@typescript-eslint/eslint-plugin": "^5.22.0",
@@ -35,36 +30,32 @@
3530
"eslint": "^8.15.0",
3631
"eslint-config-prettier": "^8.5.0",
3732
"eslint-plugin-html": "^6.2.0",
38-
"eslint-plugin-jest": "^26.1.5",
3933
"eslint-plugin-markdown": "^2.2.1",
4034
"eslint-plugin-node": "^11.1.0",
4135
"eslint-plugin-prettier": "^4.0.0",
4236
"eslint-plugin-svelte3": "^4.0.0",
43-
"execa": "^5.1.1",
37+
"execa": "^6.1.0",
4438
"fs-extra": "^10.1.0",
4539
"husky": "^7.0.4",
46-
"jest": "^27.5.1",
47-
"jest-environment-node": "^27.5.1",
48-
"jest-junit": "^13.2.0",
4940
"lint-staged": "^12.4.1",
50-
"node-fetch": "^2.6.7",
41+
"node-fetch": "^3.2.4",
5142
"npm-run-all": "^4.1.5",
5243
"playwright-core": "^1.21.1",
5344
"prettier": "^2.6.2",
5445
"prettier-plugin-svelte": "^2.7.0",
5546
"rimraf": "^3.0.2",
5647
"svelte": "^3.48.0",
57-
"ts-jest": "^27.1.4",
5848
"typescript": "^4.6.4",
59-
"vite": "^2.9.8"
49+
"vite": "^2.9.8",
50+
"vitest": "^0.12.6"
6051
},
6152
"lint-staged": {
6253
"*.{js,ts,svelte,html,md,svx}": "eslint --fix",
6354
"*.{css,scss,svelte,html,js,ts,svx,md}": [
6455
"prettier --write"
6556
]
6657
},
67-
"packageManager": "[email protected]",
58+
"packageManager": "[email protected]",
6859
"engines": {
6960
"pnpm": "^7.1.0",
7061
"yarn": "forbidden, use pnpm",
@@ -73,7 +64,8 @@
7364
},
7465
"pnpm": {
7566
"overrides": {
76-
"@sveltejs/vite-plugin-svelte": "workspace:*"
67+
"@sveltejs/vite-plugin-svelte": "workspace:*",
68+
"glob@^7": "^7.2.3"
7769
}
7870
}
7971
}

packages/e2e-tests/autoprefixer-browerslist/__tests__/autoprefixer-browerslist.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { isBuild, findAssetFile } from '../../testUtils';
1+
import { expect, test } from 'vitest';
2+
import { isBuild, findAssetFile, page } from '~utils';
23

34
test('should prefix position: sticky for code in source tree', async () => {
45
const stickyStyle = isBuild

packages/e2e-tests/autoprefixer-browerslist/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
"svelte": "^3.48.0",
1919
"svelte-preprocess": "^4.10.6",
2020
"vite": "^2.9.8"
21-
}
21+
},
22+
"type": "module"
2223
}

packages/e2e-tests/autoprefixer-browerslist/svelte.config.cjs

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import sveltePreprocess from 'svelte-preprocess';
2+
import path from 'path';
3+
import { fileURLToPath } from 'url';
4+
5+
export default {
6+
preprocess: sveltePreprocess({
7+
postcss: {
8+
// tests are run on project root and postcss-load-config uses cwd as default so force correct path here
9+
configFilePath: path.join(path.dirname(fileURLToPath(import.meta.url)), 'postcss.config.cjs')
10+
}
11+
})
12+
};

0 commit comments

Comments
 (0)