From 94dd18b1a61f799d8d97a7f58757f81760c0b8ba Mon Sep 17 00:00:00 2001 From: Nahuel Garbezza Date: Wed, 28 Oct 2026 16:07:42 -0300 Subject: [PATCH 1/2] fix(typescript): write transpiled test next to the original so relative imports resolve Closes #450 Co-Authored-By: Claude Sonnet 5.5 --- .gitignore | 3 ++- lib/typescript/typescript_transpiler.js | 8 ++------ tests/core/fixtures/loader_fixture_dependency.ts | 2 ++ tests/core/fixtures/loader_fixture_imports_local.ts | 4 ++++ tests/core/test_file_loader_test.js | 10 ++++++++++ 5 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 tests/core/fixtures/loader_fixture_dependency.ts create mode 100644 tests/core/fixtures/loader_fixture_imports_local.ts diff --git a/.gitignore b/.gitignore index 2bc7ab13..4acb2567 100644 --- a/.gitignore +++ b/.gitignore @@ -9,8 +9,9 @@ reports/ # Mutation testing temp files .stryker-tmp -# TypeScript transpilation cache +# TypeScript transpilation cache and temporary files .testy-cache +*.ts.testy-tmp.js # JSDoc doc/jsdoc/ diff --git a/lib/typescript/typescript_transpiler.js b/lib/typescript/typescript_transpiler.js index de8f163b..11bf3043 100644 --- a/lib/typescript/typescript_transpiler.js +++ b/lib/typescript/typescript_transpiler.js @@ -9,12 +9,8 @@ export class TypescriptTranspiler { const tsCode = fs.readFileSync(filePath, 'utf8'); const jsCode = await this.transpileTypeScript(tsCode); - const tempDir = path.join(process.cwd(), '.testy-cache'); - if (!fs.existsSync(tempDir)) { - fs.mkdirSync(tempDir, { recursive: true }); - } - - const tempFilePath = path.join(tempDir, `${path.basename(filePath)}.js`); + // Written next to the original so relative imports keep resolving against the same directory. + const tempFilePath = path.join(path.dirname(filePath), `${path.basename(filePath)}.testy-tmp.js`); fs.writeFileSync(tempFilePath, jsCode); return { importPath: tempFilePath }; diff --git a/tests/core/fixtures/loader_fixture_dependency.ts b/tests/core/fixtures/loader_fixture_dependency.ts new file mode 100644 index 00000000..aa125d7f --- /dev/null +++ b/tests/core/fixtures/loader_fixture_dependency.ts @@ -0,0 +1,2 @@ +// Fixture used by test_file_loader_test.js: a local TypeScript module imported by another fixture. +export const dependencyMarker: string = 'loader-fixture-dependency-ts'; diff --git a/tests/core/fixtures/loader_fixture_imports_local.ts b/tests/core/fixtures/loader_fixture_imports_local.ts new file mode 100644 index 00000000..844258cd --- /dev/null +++ b/tests/core/fixtures/loader_fixture_imports_local.ts @@ -0,0 +1,4 @@ +// Fixture used by test_file_loader_test.js: a TypeScript module that imports a sibling module via a relative path. +import { dependencyMarker } from './loader_fixture_dependency.ts'; + +export const importedMarker: string = dependencyMarker; diff --git a/tests/core/test_file_loader_test.js b/tests/core/test_file_loader_test.js index e284950a..57126333 100644 --- a/tests/core/test_file_loader_test.js +++ b/tests/core/test_file_loader_test.js @@ -78,6 +78,16 @@ suite('TestFileLoader', () => { }); }); + test('loads a TypeScript file that imports a sibling module through a relative path', async() => { + await withRunner(async runner => { + const loader = new TestFileLoader(ui, runner); + + await loader.loadAll([fixturesDir], /loader_fixture_imports_local\.ts$/u); + + assert.that(fakeProcess.lastExitCode()).isNull(); + }); + }); + test('uses the injected module loader to evaluate matched files', async() => { await withRunner(async runner => { const seen = []; From 0bcad8e75699c8b47cfd3860375884767481acd9 Mon Sep 17 00:00:00 2001 From: Nahuel Garbezza Date: Wed, 28 Oct 2026 16:10:22 -0300 Subject: [PATCH 2/2] chore: drop unused .testy-cache entry from .gitignore Co-Authored-By: Claude Sonnet 5.5 --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 4acb2567..0483ffa3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,8 +9,7 @@ reports/ # Mutation testing temp files .stryker-tmp -# TypeScript transpilation cache and temporary files -.testy-cache +# TypeScript transpilation temporary files *.ts.testy-tmp.js # JSDoc