Update test framework: fix run_tests.py to support all test files, add auto-import-check for test files

This commit is contained in:
qiaoxinjiu
2026-05-09 15:11:30 +08:00
parent eb053a347f
commit eaba8328da
21739 changed files with 2236758 additions and 719 deletions

View File

@@ -0,0 +1,6 @@
import { register } from 'node:module'
register('./typescript-loader.mjs', import.meta.url)
register('../../hook.mjs', import.meta.url)
await import('node:util')

View File

@@ -0,0 +1,26 @@
/**
* This simulates what something like `tsx` (https://github.com/privatenumber/tsx)
* will do: it will try to resolve a URL with a `.js` extension to a `.ts` extension.
*
* Combined with the test case in the adjacent `multiple-loaders.test.mjs` file,
* this forces `import-in-the-middle` into what used to be a failure state: where
* `context.parentURL` is a `node:*` specifier and the `specifier` refers to a file
* that does not exist.
*
* See https://github.com/nodejs/node/issues/52987 for more details.
*/
export async function resolve (specifier, context, defaultResolve) {
if (!specifier.endsWith('.js') && !specifier.endsWith('.mjs')) {
return await defaultResolve(specifier, context)
}
try {
return await defaultResolve(specifier.replace(/\.m?js/, '.ts'), context)
} catch (err) {
if (err.code !== 'ERR_MODULE_NOT_FOUND') {
throw err
}
return await defaultResolve(specifier, context)
}
}