-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add e2e test case for ESM features
- Loading branch information
Showing
7 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import jsonImportAssertion from '../src/foo.json' assert { type: 'json' } | ||
|
||
const topLevelAwait = await import('../src/foo.json') | ||
|
||
const itWithRunNode18Above = (...args: Parameters<typeof it>) => { | ||
const [major] = process.versions.node.split('.').map(Number) | ||
if (major > 16) { | ||
// eslint-disable-next-line jest/valid-title,jest/expect-expect,jest/no-disabled-tests | ||
return it(...args) | ||
} | ||
|
||
// eslint-disable-next-line jest/valid-title,jest/expect-expect,jest/no-disabled-tests | ||
return it.skip(...args) | ||
} | ||
|
||
describe('esm-features', () => { | ||
it('should work with import.meta', () => { | ||
expect(import.meta.jest).toBeDefined() | ||
}) | ||
|
||
it('should work with import assertion', () => { | ||
expect(jsonImportAssertion.name).toBe('hello') | ||
}) | ||
|
||
itWithRunNode18Above('should work with import attributes', async () => { | ||
const jsonImportAttrs = await import('../src/foo.json', { with: { type: 'json' } }) | ||
// eslint-disable-next-line jest/no-standalone-expect | ||
expect(jsonImportAttrs.default.name).toBe('hello') | ||
}) | ||
|
||
it('should work with top-level await', () => { | ||
expect(topLevelAwait.default.name).toBe('hello') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' | ||
|
||
export default { | ||
displayName: 'esm-features-compiler-esm', | ||
extensionsToTreatAsEsm: ['.ts'], | ||
transform: { | ||
[TS_TRANSFORM_PATTERN]: [ | ||
'ts-jest', | ||
{ | ||
tsconfig: '<rootDir>/tsconfig-esm.spec.json', | ||
useESM: true, | ||
}, | ||
], | ||
}, | ||
} satisfies JestConfigWithTsJest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' | ||
|
||
export default { | ||
displayName: 'esm-features-transpiler-esm', | ||
extensionsToTreatAsEsm: ['.ts'], | ||
transform: { | ||
[TS_TRANSFORM_PATTERN]: [ | ||
'ts-jest', | ||
{ | ||
tsconfig: '<rootDir>/tsconfig-esm.spec.json', | ||
isolatedModules: true, | ||
useESM: true, | ||
}, | ||
], | ||
}, | ||
} satisfies JestConfigWithTsJest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "esm-features", | ||
"private": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "hello" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "./tsconfig.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "../tsconfig-esm.spec.json" | ||
} |