Skip to content

Commit 0b076b4

Browse files
committed
test(napi/parser): fix and clarify exclude tests logic (#14409)
Fix a bug in Vitest config for `napi/parser` package. When providing `exclude` property, should extend the default to prevent Vitest searching `node_modules` for test files ([docs](https://vitest.dev/config/)). Also refactor to clarify the logic of which tests are skipped depending on different `env` vars.
1 parent 3192574 commit 0b076b4

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

napi/parser/vitest.config.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
import { defineConfig } from 'vitest/config';
1+
import { configDefaults, defineConfig } from 'vitest/config';
22

33
const { env, platform } = process;
44
const isEnabled = envValue => envValue === 'true' || envValue === '1';
5-
const exclude = new Set<string>();
6-
if (!isEnabled(env.RUN_LAZY_TESTS)) {
7-
exclude.add('lazy-deserialization.test.ts');
8-
if (!isEnabled(env.RUN_RAW_TESTS) && !isEnabled(env.RUN_RAW_RANGE_TESTS)) exclude.add('parse-raw.test.ts');
9-
}
10-
// TinyPool doesn't seem to work on Windows with Vitest
5+
6+
const runLazyTests = isEnabled(env.RUN_LAZY_TESTS);
7+
let runRawTests = runLazyTests || isEnabled(env.RUN_RAW_TESTS) || isEnabled(env.RUN_RAW_RANGE_TESTS);
8+
9+
// Raw tests use `tinypool`, which doesn't seem to work on Windows with Vitest
1110
// Ref: https://github.com/vitest-dev/vitest/issues/8201
12-
if (platform === 'win32') {
13-
exclude.add('parse-raw.test.ts');
14-
}
11+
if (platform === 'win32') runRawTests = false;
12+
13+
const exclude = [...configDefaults.exclude];
14+
if (!runRawTests) exclude.push('parse-raw.test.ts');
15+
if (!runLazyTests) exclude.push('lazy-deserialization.test.ts');
1516

1617
export default defineConfig({
1718
test: {
1819
diff: {
1920
expand: false,
2021
},
21-
exclude: [...exclude],
22+
exclude,
2223
},
2324
plugins: [
2425
// Enable Codspeed plugin in CI only

0 commit comments

Comments
 (0)