Skip to content

Commit df8a41e

Browse files
fix(test): keep vitest default excludes (#63)
* test: cover default excludes in shared vitest config * fix(test): keep vitest default excludes --------- Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
1 parent 1f085b9 commit df8a41e

3 files changed

Lines changed: 59 additions & 2 deletions

File tree

‎.changeset/nested-modules-skip.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bomb.sh/tools": patch
3+
---
4+
5+
`test` CLI command keeps vitest's default excludes, so test files inside nested `node_modules` are no longer collected.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { realpath } from 'node:fs/promises';
2+
import { fileURLToPath } from 'node:url';
3+
import { x } from 'tinyexec';
4+
import { describe, it, expect } from 'vitest';
5+
import { createFixture } from './index.ts';
6+
7+
const bin = fileURLToPath(new URL('../bin.ts', import.meta.url));
8+
9+
describe('shared vitest config', () => {
10+
it('skips test files inside nested node_modules', async () => {
11+
const fixture = await createFixture({
12+
'package.json': { name: 'root', private: true, type: 'module' },
13+
packages: {
14+
core: {
15+
'package.json': { name: '@demo/core', type: 'module' },
16+
src: {
17+
'a.test.ts':
18+
"import { it, expect } from 'vitest';\nit('ok', () => { expect(1).toBe(1); });\n",
19+
},
20+
},
21+
},
22+
examples: {
23+
basic: {
24+
node_modules: {
25+
'@demo': {
26+
core: ({ symlink }) => symlink('../../../../packages/core'),
27+
},
28+
},
29+
},
30+
},
31+
});
32+
const root = await realpath(fileURLToPath(fixture.root));
33+
34+
await x(
35+
process.execPath,
36+
[
37+
'--experimental-strip-types',
38+
'--no-warnings',
39+
bin,
40+
'test',
41+
'--reporter=json',
42+
'--outputFile=report.json',
43+
],
44+
{ nodeOptions: { cwd: root }, throwOnError: false },
45+
);
46+
47+
const report = (await fixture.json('report.json')) as { testResults: { name: string }[] };
48+
expect(report.testResults.map((file) => file.name.slice(root.length + 1))).toEqual([
49+
'packages/core/src/a.test.ts',
50+
]);
51+
});
52+
});

‎src/test-utils/vitest.config.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { fileURLToPath } from 'node:url';
2-
import { defineConfig } from 'vitest/config';
2+
import { configDefaults, defineConfig } from 'vitest/config';
33

44
export default defineConfig({
55
test: {
6-
exclude: ['dist/**', 'node_modules/**'],
6+
exclude: [...configDefaults.exclude, 'dist/**'],
77
// oxlint/knip spawn real binaries in integration tests; 5s is not
88
// enough headroom on a loaded machine.
99
testTimeout: 15_000,

0 commit comments

Comments
 (0)