diff --git a/e2e/esm-features/__tests__/esm-features.spec.ts b/e2e/esm-features/__tests__/esm-features.spec.ts new file mode 100644 index 0000000000..fba4c75f17 --- /dev/null +++ b/e2e/esm-features/__tests__/esm-features.spec.ts @@ -0,0 +1,34 @@ +import jsonImportAssertion from '../src/foo.json' assert { type: 'json' } + +const topLevelAwait = await import('../src/foo.json') + +const itWithRunNode18Above = (...args: Parameters) => { + 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') + }) +}) diff --git a/e2e/esm-features/jest-compiler-esm.config.ts b/e2e/esm-features/jest-compiler-esm.config.ts new file mode 100644 index 0000000000..0f7344b195 --- /dev/null +++ b/e2e/esm-features/jest-compiler-esm.config.ts @@ -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: '/tsconfig-esm.spec.json', + useESM: true, + }, + ], + }, +} satisfies JestConfigWithTsJest diff --git a/e2e/esm-features/jest-transpiler-esm.config.ts b/e2e/esm-features/jest-transpiler-esm.config.ts new file mode 100644 index 0000000000..c718fd33e5 --- /dev/null +++ b/e2e/esm-features/jest-transpiler-esm.config.ts @@ -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: '/tsconfig-esm.spec.json', + isolatedModules: true, + useESM: true, + }, + ], + }, +} satisfies JestConfigWithTsJest diff --git a/e2e/esm-features/package.json b/e2e/esm-features/package.json new file mode 100644 index 0000000000..23ad05951a --- /dev/null +++ b/e2e/esm-features/package.json @@ -0,0 +1,4 @@ +{ + "name": "esm-features", + "private": true +} diff --git a/e2e/esm-features/src/foo.json b/e2e/esm-features/src/foo.json new file mode 100644 index 0000000000..611137476d --- /dev/null +++ b/e2e/esm-features/src/foo.json @@ -0,0 +1,3 @@ +{ + "name": "hello" +} diff --git a/e2e/esm-features/tsconfig-esm.spec.json b/e2e/esm-features/tsconfig-esm.spec.json new file mode 100644 index 0000000000..fc8520e737 --- /dev/null +++ b/e2e/esm-features/tsconfig-esm.spec.json @@ -0,0 +1,3 @@ +{ + "extends": "./tsconfig.json" +} diff --git a/e2e/esm-features/tsconfig.json b/e2e/esm-features/tsconfig.json new file mode 100644 index 0000000000..4e65ad7abd --- /dev/null +++ b/e2e/esm-features/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../tsconfig-esm.spec.json" +}