From ab6504514d23e74dd5ef0c653238fb36c48e689a Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Mon, 1 Nov 2021 16:43:03 +0800 Subject: [PATCH] test: add a test case for issue #3040 --- packages/playground/resolve/__tests__/resolve.spec.ts | 4 ++++ packages/playground/resolve/index.html | 8 ++++++++ packages/playground/resolve/ts-extension/hello.ts | 1 + packages/playground/resolve/ts-extension/index.ts | 3 +++ packages/playground/resolve/vite.config.js | 2 +- 5 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 packages/playground/resolve/ts-extension/hello.ts create mode 100644 packages/playground/resolve/ts-extension/index.ts diff --git a/packages/playground/resolve/__tests__/resolve.spec.ts b/packages/playground/resolve/__tests__/resolve.spec.ts index b94be689371b22..b1524e1e42aa08 100644 --- a/packages/playground/resolve/__tests__/resolve.spec.ts +++ b/packages/playground/resolve/__tests__/resolve.spec.ts @@ -54,6 +54,10 @@ test('dont add extension to directory name (./dir-with-ext.js/index.js)', async expect(await page.textContent('.dir-with-ext')).toMatch('[success]') }) +test('a ts module can import another ts module using its corresponding js file name', async () => { + expect(await page.textContent('.ts-extension')).toMatch('[success]') +}) + test('filename with dot', async () => { expect(await page.textContent('.dot')).toMatch('[success]') }) diff --git a/packages/playground/resolve/index.html b/packages/playground/resolve/index.html index a121c5c8a68ca1..9dc6525fcd7a43 100644 --- a/packages/playground/resolve/index.html +++ b/packages/playground/resolve/index.html @@ -33,6 +33,11 @@

Resolve to non-duplicated file extension

Don't add extensions to directory names

fail

+

+ A ts module can import another ts module using its corresponding js file name +

+

fail

+

Resolve file name containing dot

fail

@@ -119,6 +124,9 @@

resolve package that contains # in path

import { file as dirWithExtMsg } from './dir-with-ext' text('.dir-with-ext', dirWithExtMsg) + import { msg as tsExtensionMsg } from './ts-extension' + text('.ts-extension', tsExtensionMsg) + // filename with dot import { bar } from './util/bar.util' text('.dot', bar()) diff --git a/packages/playground/resolve/ts-extension/hello.ts b/packages/playground/resolve/ts-extension/hello.ts new file mode 100644 index 00000000000000..0189355c3fe06f --- /dev/null +++ b/packages/playground/resolve/ts-extension/hello.ts @@ -0,0 +1 @@ +export const msg = '[success] use .js extension to import a ts module' diff --git a/packages/playground/resolve/ts-extension/index.ts b/packages/playground/resolve/ts-extension/index.ts new file mode 100644 index 00000000000000..e095619ee4d716 --- /dev/null +++ b/packages/playground/resolve/ts-extension/index.ts @@ -0,0 +1,3 @@ +import { msg } from './hello.js' + +export { msg } diff --git a/packages/playground/resolve/vite.config.js b/packages/playground/resolve/vite.config.js index a05d51bb5b8e45..e7d531097add7c 100644 --- a/packages/playground/resolve/vite.config.js +++ b/packages/playground/resolve/vite.config.js @@ -2,7 +2,7 @@ const virtualFile = '@virtual-file' module.exports = { resolve: { - extensions: ['.mjs', '.js', '.es'], + extensions: ['.mjs', '.js', '.es', '.ts'], mainFields: ['custom', 'module'], conditions: ['custom'] },