diff --git a/.changeset/nested-modules-skip.md b/.changeset/nested-modules-skip.md new file mode 100644 index 0000000..a70b6ba --- /dev/null +++ b/.changeset/nested-modules-skip.md @@ -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. diff --git a/src/test-utils/vitest.config.test.ts b/src/test-utils/vitest.config.test.ts new file mode 100644 index 0000000..ff9b8d7 --- /dev/null +++ b/src/test-utils/vitest.config.test.ts @@ -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', + ]); + }); +}); diff --git a/src/test-utils/vitest.config.ts b/src/test-utils/vitest.config.ts index aff097e..593f80c 100644 --- a/src/test-utils/vitest.config.ts +++ b/src/test-utils/vitest.config.ts @@ -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,