diff --git a/.gitignore b/.gitignore index 2bc7ab13..0483ffa3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,8 +9,8 @@ reports/ # Mutation testing temp files .stryker-tmp -# TypeScript transpilation cache -.testy-cache +# TypeScript transpilation temporary files +*.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 = [];