Skip to content

Commit 783bd98

Browse files
gtm-nayandummdidummRich-Harris
authored
chore: swap mocha with vitest (#8584)
Also swap out the require hook hacks with a less-hacky-but-still-somewhat-hacky loader for the Svelte files --------- Co-authored-by: Simon Holthausen <[email protected]> Co-authored-by: Rich Harris <[email protected]>
1 parent 202d119 commit 783bd98

File tree

516 files changed

+3885
-3449
lines changed

Some content is hidden

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

516 files changed

+3885
-3449
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
cache: pnpm
3737
- run: pnpm install --frozen-lockfile
3838
- run: pnpm playwright install chromium
39-
- run: pnpm test:integration
39+
- run: pnpm test
4040
env:
4141
CI: true
4242
Lint:
@@ -50,28 +50,3 @@ jobs:
5050
node-version: 16
5151
cache: pnpm
5252
- run: 'pnpm i && pnpm format:check && pnpm lint'
53-
Unit:
54-
runs-on: ${{ matrix.os }}
55-
timeout-minutes: 10
56-
strategy:
57-
matrix:
58-
include:
59-
- node-version: 16
60-
os: ubuntu-latest
61-
- node-version: 16
62-
os: windows-latest
63-
- node-version: 16
64-
os: macOS-latest
65-
- node-version: 18
66-
os: ubuntu-latest
67-
- node-version: 20
68-
os: ubuntu-latest
69-
steps:
70-
- uses: actions/checkout@v3
71-
- uses: pnpm/[email protected]
72-
- uses: actions/setup-node@v3
73-
with:
74-
node-version: ${{ matrix.node-version }}
75-
cache: pnpm
76-
- run: pnpm install
77-
- run: pnpm test:unit

.mocharc.js

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

.mocharc.unit.js

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

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ src/compiler/compile/internal_exports.ts
1010
/test/**/_expected*
1111
/test/**/_actual*
1212
/test/**/expected*
13+
/test/**/_output
1314
/types

codemod-lazy-props.mjs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { existsSync, fstat, readFileSync, readdirSync, writeFileSync } from 'fs';
2+
import { resolve } from 'path';
3+
import { parse } from 'acorn';
4+
import { walk } from 'estree-walker';
5+
import { inspect } from 'util';
6+
7+
import { p, print } from 'code-red';
8+
9+
const samples = resolve(`vitest/runtime/runtime/samples`);
10+
11+
for (const dir of readdirSync(samples)) {
12+
const cwd = resolve(samples, dir);
13+
const file = resolve(cwd, '_config.js');
14+
15+
if (!existsSync(file)) continue;
16+
const contents = readFileSync(file, 'utf-8');
17+
const ast = parse(contents, {
18+
sourceType: 'module',
19+
ecmaVersion: 'latest',
20+
sourceFile: file,
21+
ranges: true
22+
});
23+
24+
walk(ast, {
25+
enter(node) {
26+
if (
27+
node.type === 'ExportDefaultDeclaration' &&
28+
node.declaration.type === 'ObjectExpression'
29+
) {
30+
this.skip();
31+
32+
const props = node.declaration.properties.find((prop) => prop.key.name === 'props');
33+
if (!props) return;
34+
const { range } = props;
35+
36+
const [start, end] = range;
37+
38+
const code =
39+
contents.slice(0, start) +
40+
print(p`get ${props.key}() { return ${props.value}}`).code +
41+
contents.slice(end);
42+
43+
writeFileSync(file, code);
44+
}
45+
}
46+
});
47+
}

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@
8383
"scripts": {
8484
"format:fix": "prettier . --cache --plugin-search-dir=. --write",
8585
"format:check": "prettier . --cache --plugin-search-dir=. --check",
86-
"test": "npm run test:unit && npm run test:integration && echo \"manually check that there are no type errors in test/types by opening the files in there\"",
87-
"test:integration": "mocha --exit",
88-
"test:unit": "mocha --config .mocharc.unit.js --exit",
89-
"quicktest": "mocha --exit",
86+
"test": "vitest run && echo \"manually check that there are no type errors in test/types by opening the files in there\"",
9087
"build": "rollup -c && npm run tsd",
9188
"prepare": "npm run build",
9289
"dev": "rollup -cw",
@@ -140,12 +137,12 @@
140137
"eslint-plugin-import": "^2.27.5",
141138
"eslint-plugin-svelte3": "^4.0.0",
142139
"estree-walker": "^3.0.3",
140+
"happy-dom": "^9.18.3",
143141
"is-reference": "^3.0.1",
144142
"jsdom": "^21.1.1",
145143
"kleur": "^4.1.5",
146144
"locate-character": "^2.0.5",
147145
"magic-string": "^0.30.0",
148-
"mocha": "^10.2.0",
149146
"periscopic": "^3.1.0",
150147
"prettier": "^2.8.8",
151148
"prettier-plugin-svelte": "^2.10.0",
@@ -155,7 +152,8 @@
155152
"tiny-glob": "^0.2.9",
156153
"tslib": "^2.5.0",
157154
"typescript": "^5.0.4",
158-
"util": "^0.12.5"
155+
"util": "^0.12.5",
156+
"vitest": "^0.31.0"
159157
},
160158
"packageManager": "[email protected]"
161159
}

0 commit comments

Comments
 (0)