Skip to content

Commit

Permalink
test: add a test case for issue vitejs#3040
Browse files Browse the repository at this point in the history
  • Loading branch information
sodatea committed Nov 1, 2021
1 parent 012ab61 commit ab65045
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/playground/resolve/__tests__/resolve.spec.ts
Expand Up @@ -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]')
})
Expand Down
8 changes: 8 additions & 0 deletions packages/playground/resolve/index.html
Expand Up @@ -33,6 +33,11 @@ <h2>Resolve to non-duplicated file extension</h2>
<h2>Don't add extensions to directory names</h2>
<p class="dir-with-ext">fail</p>

<h2>
A ts module can import another ts module using its corresponding js file name
</h2>
<p class="ts-extension">fail</p>

<h2>Resolve file name containing dot</h2>
<p class="dot">fail</p>

Expand Down Expand Up @@ -119,6 +124,9 @@ <h2>resolve package that contains # in path</h2>
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())
Expand Down
1 change: 1 addition & 0 deletions packages/playground/resolve/ts-extension/hello.ts
@@ -0,0 +1 @@
export const msg = '[success] use .js extension to import a ts module'
3 changes: 3 additions & 0 deletions packages/playground/resolve/ts-extension/index.ts
@@ -0,0 +1,3 @@
import { msg } from './hello.js'

export { msg }
2 changes: 1 addition & 1 deletion packages/playground/resolve/vite.config.js
Expand Up @@ -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']
},
Expand Down

0 comments on commit ab65045

Please sign in to comment.