Skip to content

Commit 1cfa530

Browse files
chore(repo): test migration to vitest. phase 3 (#1977)
* test(auto-install,pluginutils,run): migrate phase 3 packages to vitest * chore: remove redundant vitest include glob --------- Co-authored-by: CharlieHelps <charlie@charlielabs.ai>
1 parent 2de0d62 commit 1cfa530

21 files changed

+357
-431
lines changed

.config/vitest.config.mts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { defineConfig } from 'vitest/config';
22
import path from 'node:path';
33

4+
const isAutoInstallPackage = path.basename(process.cwd()) === 'auto-install';
5+
46
export default defineConfig({
57
test: {
68
// Enable global APIs for CommonJS test files.
79
globals: true,
8-
// Phase 1/2 packages use runtime-style, *.test, and a few named entrypoints.
10+
// Phase 1/2/3 packages use runtime-style, top-level test files, *.test, and a few named entrypoints.
911
include: [
10-
'test/test.{js,mjs,cjs,ts,mts,cts}',
12+
'test/*.{js,mjs,cjs,ts,mts,cts}',
1113
'test/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts}',
1214
'test/{as-input-plugin,as-output-plugin,form,function,misc,sourcemaps}.{js,mjs,cjs,ts,mts,cts}'
1315
],
@@ -20,6 +22,8 @@ export default defineConfig({
2022
'**/test/snapshots/**',
2123
'**/test/types.ts'
2224
],
25+
// These tests switch process cwd and invoke package managers; run files serially there.
26+
fileParallelism: !isAutoInstallPackage,
2327
// Keep snapshots in the same location used by Ava.
2428
resolveSnapshotPath: (testPath, snapExt) =>
2529
path.join(path.dirname(testPath), 'snapshots', path.basename(testPath) + snapExt)

packages/auto-install/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 --noEmit"
3939
},
4040
"files": [
@@ -69,15 +69,5 @@
6969
"rollup": "^4.0.0-24",
7070
"typescript": "^4.8.3"
7171
},
72-
"types": "./types/index.d.ts",
73-
"ava": {
74-
"workerThreads": false,
75-
"files": [
76-
"!**/fixtures/**",
77-
"!**/output/**",
78-
"!**/helpers/**",
79-
"!**/recipes/**",
80-
"!**/types.ts"
81-
]
82-
}
72+
"types": "./types/index.d.ts"
8373
}
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const { readFileSync } = require('fs');
22
const { join } = require('path');
33

4-
const test = require('ava');
54
const del = require('del');
65
const { nodeResolve } = require('@rollup/plugin-node-resolve');
76
const { rollup } = require('rollup');
@@ -14,8 +13,7 @@ const input = join(cwd, '../input.js');
1413

1514
process.chdir(cwd);
1615

17-
test('npm, bare', async (t) => {
18-
t.timeout(50000);
16+
test('npm, bare', async () => {
1917
await rollup({
2018
input,
2119
output: {
@@ -24,10 +22,10 @@ test('npm, bare', async (t) => {
2422
},
2523
plugins: [autoInstall(), nodeResolve()]
2624
});
27-
t.snapshot(readFileSync('package.json', 'utf-8'));
28-
t.truthy(readFileSync('package-lock.json', 'utf-8').includes('"node-noop"'));
29-
});
25+
expect(readFileSync('package.json', 'utf-8')).toMatchSnapshot();
26+
expect(readFileSync('package-lock.json', 'utf-8').includes('"node-noop"')).toBeTruthy();
27+
}, 50000);
3028

31-
test.after(async () => {
29+
afterAll(async () => {
3230
await del(['node_modules', 'package.json', 'package-lock.json']);
3331
});

packages/auto-install/test/npm.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const { readFileSync, writeFileSync } = require('fs');
22
const { join } = require('path');
33

4-
const test = require('ava');
54
const del = require('del');
65
const { nodeResolve } = require('@rollup/plugin-node-resolve');
76
const { rollup } = require('rollup');
@@ -16,27 +15,29 @@ const pkgFile = join(cwd, 'package.json');
1615

1716
process.chdir(cwd);
1817

19-
test('invalid manager', (t) => {
20-
t.timeout(50000);
21-
const error = t.throws(
22-
() =>
18+
test('invalid manager', () => {
19+
const error = (() => {
20+
try {
2321
rollup({
2422
input,
2523
output: {
2624
file,
2725
format: 'cjs'
2826
},
2927
plugins: [autoInstall({ pkgFile, manager: 'foo' }), nodeResolve()]
30-
}),
31-
{
32-
instanceOf: RangeError
28+
});
29+
} catch (caught) {
30+
return caught;
3331
}
34-
);
35-
t.snapshot(error.message);
36-
});
3732

38-
test('npm', async (t) => {
39-
t.timeout(50000);
33+
return null;
34+
})();
35+
36+
expect(error).toBeInstanceOf(RangeError);
37+
expect(error.message).toMatchSnapshot();
38+
}, 50000);
39+
40+
test('npm', async () => {
4041
await rollup({
4142
input,
4243
output: {
@@ -45,10 +46,10 @@ test('npm', async (t) => {
4546
},
4647
plugins: [autoInstall({ pkgFile, manager }), nodeResolve()]
4748
});
48-
t.snapshot(readFileSync('package.json', 'utf-8'));
49-
});
49+
expect(readFileSync('package.json', 'utf-8')).toMatchSnapshot();
50+
}, 50000);
5051

51-
test.after(async () => {
52+
afterAll(async () => {
5253
await del(['node_modules', 'package-lock.json']);
5354
writeFileSync(pkgFile, '{}');
5455
});

packages/auto-install/test/pnpm-bare.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const { readFileSync } = require('fs');
22
const { join } = require('path');
33

4-
const test = require('ava');
54
const del = require('del');
65
const { nodeResolve } = require('@rollup/plugin-node-resolve');
76
const { rollup } = require('rollup');
@@ -14,8 +13,7 @@ const input = join(cwd, '../input.js');
1413

1514
process.chdir(cwd);
1615

17-
test('pnpm, bare', async (t) => {
18-
t.timeout(50000);
16+
test('pnpm, bare', async () => {
1917
await rollup({
2018
input,
2119
output: {
@@ -26,9 +24,9 @@ test('pnpm, bare', async (t) => {
2624
});
2725
const json = JSON.parse(readFileSync('package.json', 'utf-8'));
2826
// snapshots for this are a nightmare cross-platform
29-
t.truthy('node-noop' in json.dependencies);
30-
});
27+
expect('node-noop' in json.dependencies).toBeTruthy();
28+
}, 50000);
3129

32-
test.after(async () => {
30+
afterAll(async () => {
3331
await del(['node_modules', 'package.json', 'pnpm-lock.yaml']);
3432
});

packages/auto-install/test/pnpm.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const { readFileSync, writeFileSync } = require('fs');
22
const { join } = require('path');
33

4-
const test = require('ava');
54
const del = require('del');
65
const { nodeResolve } = require('@rollup/plugin-node-resolve');
76
const { rollup } = require('rollup');
@@ -14,8 +13,7 @@ const input = join(cwd, '../input.js');
1413

1514
process.chdir(cwd);
1615

17-
test('pnpm', async (t) => {
18-
t.timeout(50000);
16+
test('pnpm', async () => {
1917
await rollup({
2018
input,
2119
output: {
@@ -27,10 +25,10 @@ test('pnpm', async (t) => {
2725

2826
const json = JSON.parse(readFileSync('package.json', 'utf-8'));
2927
// snapshots for this are a nightmare cross-platform
30-
t.truthy('node-noop' in json.dependencies);
31-
});
28+
expect('node-noop' in json.dependencies).toBeTruthy();
29+
}, 50000);
3230

33-
test.after(async () => {
31+
afterAll(async () => {
3432
await del(['node_modules', 'package.json']);
3533
writeFileSync('pnpm-lock.yaml', '');
3634
});
-25 Bytes
Binary file not shown.
22 Bytes
Binary file not shown.

packages/auto-install/test/yarn-bare.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const { readFileSync } = require('fs');
22
const { join } = require('path');
33

4-
const test = require('ava');
54
const del = require('del');
65
const { nodeResolve } = require('@rollup/plugin-node-resolve');
76
const { rollup } = require('rollup');
@@ -14,8 +13,7 @@ const input = join(cwd, '../input.js');
1413

1514
process.chdir(cwd);
1615

17-
test('yarn, bare', async (t) => {
18-
t.timeout(50000);
16+
test('yarn, bare', async () => {
1917
await rollup({
2018
input,
2119
output: {
@@ -30,9 +28,9 @@ test('yarn, bare', async (t) => {
3028
});
3129
const lockFile = readFileSync('yarn.lock', 'utf-8');
3230
// snapshots for this are a nightmare cross-platform
33-
t.truthy(/yarn\.bare\s+node-noop/.test(lockFile));
34-
});
31+
expect(/yarn\.bare\s+node-noop/.test(lockFile)).toBeTruthy();
32+
}, 50000);
3533

36-
test.after(async () => {
34+
afterAll(async () => {
3735
await del(['node_modules', 'package.json', 'yarn.lock']);
3836
});

packages/auto-install/test/yarn.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const { readFileSync, writeFileSync } = require('fs');
22
const { join } = require('path');
33

4-
const test = require('ava');
54
const del = require('del');
65
const { nodeResolve } = require('@rollup/plugin-node-resolve');
76
const { rollup } = require('rollup');
@@ -14,8 +13,7 @@ const input = join(cwd, '../input.js');
1413

1514
process.chdir(cwd);
1615

17-
test('yarn', async (t) => {
18-
t.timeout(50000);
16+
test('yarn', async () => {
1917
await rollup({
2018
input,
2119
output: {
@@ -27,10 +25,10 @@ test('yarn', async (t) => {
2725
});
2826
const lockFile = readFileSync('yarn.lock', 'utf-8');
2927
// snapshots for this are a nightmare cross-platform
30-
t.truthy(/yarn\s+node-noop/.test(lockFile));
31-
});
28+
expect(/yarn\s+node-noop/.test(lockFile)).toBeTruthy();
29+
}, 50000);
3230

33-
test.after(async () => {
31+
afterAll(async () => {
3432
await del(['node_modules', 'package.json']);
3533
writeFileSync('yarn.lock', '');
3634
});

0 commit comments

Comments
 (0)