From d63f905b7b589a76f57ef3c3c5e895d8111c83e5 Mon Sep 17 00:00:00 2001 From: Laurin Quast Date: Sat, 9 Jul 2022 10:34:23 +0200 Subject: [PATCH] test: .js extension in import --- src/test/index.spec.ts | 16 ++++++++++++++++ tests/import-with-js-extension/foo.ts | 1 + tests/import-with-js-extension/index.ts | 5 +++++ 3 files changed, 22 insertions(+) create mode 100644 tests/import-with-js-extension/foo.ts create mode 100644 tests/import-with-js-extension/index.ts diff --git a/src/test/index.spec.ts b/src/test/index.spec.ts index ca4c2cf85..c25d9f263 100644 --- a/src/test/index.spec.ts +++ b/src/test/index.spec.ts @@ -197,6 +197,22 @@ test.suite('ts-node', (test) => { expect(stdout).toBe('hello world\n'); }); + test.suite('should support js extension', (test) => { + test('test', async () => { + const { err, stdout } = await exec( + [ + CMD_TS_NODE_WITHOUT_PROJECT_FLAG, + '-pe "import { main } from \'./index\';main()"', + ].join(' '), + { + cwd: join(TEST_DIR, 'import-with-js-extension'), + } + ); + expect(err).toBe(null); + expect(stdout).toBe('hello world\n'); + }); + }); + test.suite('should support cts when module = CommonJS', (test) => { test.runIf(tsSupportsMtsCtsExtensions); test('test', async (t) => { diff --git a/tests/import-with-js-extension/foo.ts b/tests/import-with-js-extension/foo.ts new file mode 100644 index 000000000..2a30e7110 --- /dev/null +++ b/tests/import-with-js-extension/foo.ts @@ -0,0 +1 @@ +export const helloWorld = 'hello world'; diff --git a/tests/import-with-js-extension/index.ts b/tests/import-with-js-extension/index.ts new file mode 100644 index 000000000..c2e07ac37 --- /dev/null +++ b/tests/import-with-js-extension/index.ts @@ -0,0 +1,5 @@ +import { helloWorld } from './foo.js'; + +export function main() { + console.log(helloWorld); +}