Skip to content

Commit 796cd55

Browse files
chore(repo): test migration to vitest. phase 1 (#1975)
* test: migrate phase1 packages from ava to vitest * test: fix prettier formatting in migrated test files * test(inject): avoid obsolete win32 snapshot * test: skip win32-gated vitest cases --------- Co-authored-by: CharlieHelps <charlie@charlielabs.ai>
1 parent 8a6e5a9 commit 796cd55

File tree

73 files changed

+540
-1448
lines changed

Some content is hidden

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

73 files changed

+540
-1448
lines changed

.config/vitest.config.mts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import path from 'node:path';
33

44
export default defineConfig({
55
test: {
6-
// Store snapshots next to each test in a .snapshots folder
6+
// Enable global APIs for CommonJS test files.
7+
globals: true,
8+
// Phase 1 packages use runtime-style test entrypoints.
9+
include: ['test/test.{js,mjs,cjs,ts,mts,cts}'],
10+
// Keep snapshots in the same location used by Ava.
711
resolveSnapshotPath: (testPath, snapExt) =>
8-
path.join(path.dirname(testPath), '.snapshots', path.basename(testPath) + snapExt)
12+
path.join(path.dirname(testPath), 'snapshots', path.basename(testPath) + snapExt)
913
},
1014
resolve: {
1115
// Allow importing the current package under test via `~package`

packages/beep/package.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
"ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov",
2222
"ci:lint": "pnpm lint",
2323
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
24-
"ci:test": "ava --verbose",
24+
"ci:test": "pnpm test -- --reporter=verbose",
2525
"release": "pnpm --workspace-root package:release $(pwd)",
26-
"test": "ava"
26+
"test": "vitest --config ../../.config/vitest.config.mts run"
2727
},
2828
"files": [
2929
"lib/",
@@ -49,13 +49,5 @@
4949
"rollup": "^4.0.0-24",
5050
"strip-ansi": "^7.0.1"
5151
},
52-
"types": "types/index.d.ts",
53-
"ava": {
54-
"files": [
55-
"!**/fixtures/**",
56-
"!**/helpers/**",
57-
"!**/output/**",
58-
"!**/recipes/**"
59-
]
60-
}
52+
"types": "types/index.d.ts"
6153
}

packages/beep/test/snapshots/test.js.md

Lines changed: 0 additions & 13 deletions
This file was deleted.
-13 Bytes
Binary file not shown.

packages/beep/test/test.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
const test = require('ava');
21
const execa = require('execa');
32

43
const options = { cwd: __dirname };
54

6-
test('pass', async (t) => {
5+
test('pass', async () => {
76
const args = '--config fixtures/pass.config.js'.split(' ');
87
const { stderr } = await execa('rollup', args, options);
98
const { default: strip } = await import('strip-ansi');
109

11-
t.snapshot(strip(stderr.replace(/\d+ms|[\d.]+s/, '<time>ms')));
10+
expect(strip(stderr.replace(/\d+ms|[\d.]+s/, '<time>ms'))).toMatchSnapshot();
1211
});
1312

14-
test('error', async (t) => {
13+
test('error', async () => {
1514
const args = '--config fixtures/error.config.js'.split(' ');
1615
const throws = async () => execa('rollup', args, options);
1716

18-
const { stderr } = await t.throwsAsync(throws);
19-
t.truthy(stderr.indexOf('\x07'));
17+
const error = await throws().then(
18+
() => null,
19+
(caught) => caught
20+
);
21+
expect(error).not.toBeNull();
22+
const { stderr } = error;
23+
expect(stderr.indexOf('\x07')).toBeTruthy();
2024
});

packages/buble/package.json

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
"ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov",
2929
"ci:lint": "pnpm build && pnpm lint",
3030
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
31-
"ci:test": "pnpm test -- --verbose",
31+
"ci:test": "pnpm test -- --reporter=verbose",
3232
"prebuild": "del-cli dist",
3333
"prepare": "if [ ! -d 'dist' ]; then pnpm build; fi",
3434
"prerelease": "pnpm build",
3535
"pretest": "pnpm build",
3636
"release": "pnpm --workspace-root package:release $(pwd)",
37-
"test": "ava",
37+
"test": "vitest --config ../../.config/vitest.config.mts run",
3838
"test:ts": "tsc types/index.d.ts test/types.ts --noEmit"
3939
},
4040
"files": [
@@ -73,15 +73,5 @@
7373
"source-map": "^0.7.4",
7474
"typescript": "^4.8.3"
7575
},
76-
"types": "./types/index.d.ts",
77-
"ava": {
78-
"workerThreads": false,
79-
"files": [
80-
"!**/fixtures/**",
81-
"!**/output/**",
82-
"!**/helpers/**",
83-
"!**/recipes/**",
84-
"!**/types.ts"
85-
]
86-
}
76+
"types": "./types/index.d.ts"
8777
}

packages/buble/test/test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const test = require('ava');
21
const rollup = require('rollup');
32

43
const buble = require('..');
@@ -22,12 +21,14 @@ function getChunksFromBundle(bundle) {
2221
.then(getChunksFromGenerated);
2322
}
2423

25-
test('transforms files', async (t) => {
24+
test('transforms files', async () => {
2625
const bundle = await rollup.rollup({
2726
input: `${__dirname}/fixtures/basic/main.js`,
2827
plugins: [buble()]
2928
});
3029
const generated = await getChunksFromBundle(bundle);
31-
t.is(generated.length, 1);
32-
t.is(generated[0].code, 'function main () { return 42; }\n\nexport { main as default };\n');
30+
expect(generated.length).toBe(1);
31+
expect(generated[0].code).toBe(
32+
'function main () { return 42; }\n\nexport { main as default };\n'
33+
);
3334
});

packages/data-uri/package.json

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
"ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov",
2929
"ci:lint": "pnpm build && pnpm lint",
3030
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
31-
"ci:test": "pnpm test -- --verbose",
31+
"ci:test": "pnpm test -- --reporter=verbose",
3232
"prebuild": "del-cli dist",
3333
"prepare": "if [ ! -d 'dist' ]; then pnpm build; fi",
3434
"prerelease": "pnpm build",
3535
"pretest": "pnpm build --sourcemap",
3636
"release": "pnpm --workspace-root package:release $(pwd)",
37-
"test": "ava",
37+
"test": "vitest --config ../../.config/vitest.config.mts run",
3838
"test:ts": "tsc --noEmit"
3939
},
4040
"files": [
@@ -70,15 +70,5 @@
7070
"rollup": "^4.0.0-24",
7171
"typescript": "^4.8.3"
7272
},
73-
"types": "./types/index.d.ts",
74-
"ava": {
75-
"workerThreads": false,
76-
"files": [
77-
"!**/fixtures/**",
78-
"!**/output/**",
79-
"!**/helpers/**",
80-
"!**/recipes/**",
81-
"!**/types.ts"
82-
]
83-
}
73+
"types": "./types/index.d.ts"
8474
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import batman from 'data:application/json;base64, eyAiYmF0bWFuIjogInRydWUiIH0=';
22

3-
t.truthy(batman.batman);
4-
t.snapshot(batman);
3+
expect(batman.batman).toBeTruthy();
4+
expect(batman).toMatchSnapshot();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'data:text/javascript, t.truthy(true);';
1+
import 'data:text/javascript, expect(true).toBeTruthy();';
22
import { batman } from 'data:text/javascript, export const batman = true;\nconst joker = false;\nexport default joker;';
33

4-
t.snapshot(batman);
4+
expect(batman).toMatchSnapshot();

0 commit comments

Comments
 (0)