Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nested-modules-skip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bomb.sh/tools": patch
---

`test` CLI command keeps vitest's default excludes, so test files inside nested `node_modules` are no longer collected.
52 changes: 52 additions & 0 deletions src/test-utils/vitest.config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { realpath } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { x } from 'tinyexec';
import { describe, it, expect } from 'vitest';
import { createFixture } from './index.ts';

const bin = fileURLToPath(new URL('../bin.ts', import.meta.url));

describe('shared vitest config', () => {
it('skips test files inside nested node_modules', async () => {
const fixture = await createFixture({
'package.json': { name: 'root', private: true, type: 'module' },
packages: {
core: {
'package.json': { name: '@demo/core', type: 'module' },
src: {
'a.test.ts':
"import { it, expect } from 'vitest';\nit('ok', () => { expect(1).toBe(1); });\n",
},
},
},
examples: {
basic: {
node_modules: {
'@demo': {
core: ({ symlink }) => symlink('../../../../packages/core'),
},
},
},
},
});
const root = await realpath(fileURLToPath(fixture.root));

await x(
process.execPath,
[
'--experimental-strip-types',
'--no-warnings',
bin,
'test',
'--reporter=json',
'--outputFile=report.json',
],
{ nodeOptions: { cwd: root }, throwOnError: false },
);

const report = (await fixture.json('report.json')) as { testResults: { name: string }[] };
expect(report.testResults.map((file) => file.name.slice(root.length + 1))).toEqual([
'packages/core/src/a.test.ts',
]);
});
});
4 changes: 2 additions & 2 deletions src/test-utils/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vitest/config';
import { configDefaults, defineConfig } from 'vitest/config';

export default defineConfig({
test: {
exclude: ['dist/**', 'node_modules/**'],
exclude: [...configDefaults.exclude, 'dist/**'],
// oxlint/knip spawn real binaries in integration tests; 5s is not
// enough headroom on a loaded machine.
testTimeout: 15_000,
Expand Down
Loading