From b9b7aef15ab4660c9c5e598169b344e2173900f7 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Fri, 10 Apr 2026 12:39:33 +0200 Subject: [PATCH] test: speed up .only --- scripts/test.mjs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/scripts/test.mjs b/scripts/test.mjs index 4b07d6021..5c8410069 100644 --- a/scripts/test.mjs +++ b/scripts/test.mjs @@ -8,6 +8,7 @@ // Node 20 does not support --experimental-strip-types flag. import {spawn, execSync} from 'node:child_process'; +import {readFile} from 'node:fs/promises'; import path from 'node:path'; import process from 'node:process'; @@ -38,10 +39,27 @@ if (userArgs.length > 0) { } } else { const isNode20 = process.version.startsWith('v20.'); - if (isNode20) { - files.push('build/tests'); - } else { - files.push('build/tests/**/*.test.js'); + if (flags.includes('--test-only')) { + if (isNode20) { + throw new Error(`--test-only is not supported for Node 20`); + } + const {glob} = await import('node:fs/promises'); + for await (const tsFile of glob('tests/**/*.test.ts')) { + const content = await readFile(tsFile, 'utf8'); + if (content.includes('.only(')) { + files.push(path.join('build', tsFile.replace(/\.ts$/, '.js'))); + } + } + if (files.length === 0) { + console.warn('no files contain .only'); + process.exit(0); + } + } else if (files.length === 0) { + if (isNode20) { + files.push('build/tests'); + } else { + files.push('build/tests/**/*.test.js'); + } } }