diff --git a/e2e/__tests__/module-kinds/__snapshots__/es2015-esm.test.ts.snap b/e2e/__tests__/module-kinds/__snapshots__/es2015-esm.test.ts.snap deleted file mode 100644 index d0454b4f41..0000000000 --- a/e2e/__tests__/module-kinds/__snapshots__/es2015-esm.test.ts.snap +++ /dev/null @@ -1,1021 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Module es2015 with preset default-esm run with options: {"module":"es2015","allowSyntheticDefaultImports":false} with template default 1`] = ` - × jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting \`esModuleInterop\` to \`true\` in your TypeScript configuration file (usually \`tsconfig.json\`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. - PASS ./import-legacy.spec.ts - PASS ./import-star.spec.ts - ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"/lib"' can only be default-imported using the 'esModuleInterop' flag - - 1 import lib from './lib' - ~~~ - - lib.d.ts:5:1 - 5 export = lib - ~~~~~~~~~~~~ - This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. - FAIL ./import-default.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-default.spec.ts:4:22) - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module es2015 with preset default-esm run with options: {"module":"es2015","allowSyntheticDefaultImports":true} with template default 1`] = ` - × jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - PASS ./import-legacy.spec.ts - PASS ./import-star.spec.ts - FAIL ./import-default.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-default.spec.ts:4:22) - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module es2015 with preset default-esm run with options: {"module":"es2015","esModuleInterop":false} with template default 1`] = ` - × jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting \`esModuleInterop\` to \`true\` in your TypeScript configuration file (usually \`tsconfig.json\`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. - PASS ./import-legacy.spec.ts - PASS ./import-star.spec.ts - FAIL ./import-default.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-default.spec.ts:4:22) - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module es2015 with preset default-esm run with options: {"module":"es2015","esModuleInterop":true} with template default 1`] = ` - × jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - PASS ./import-legacy.spec.ts - ts-jest[ts-compiler] (WARN) import-star.spec.ts:5:10 - error TS2349: This expression is not callable. - Type 'typeof lib' has no call signatures. - - 5 expect(lib()).toBe('foo') - ~~~ - - import-star.spec.ts:1:1 - 1 import * as lib from './lib' - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead. - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - PASS ./import-default.spec.ts - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module es2015 with preset default-esm run with options: {"module":"es2015"} with template default 1`] = ` - × jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting \`esModuleInterop\` to \`true\` in your TypeScript configuration file (usually \`tsconfig.json\`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. - PASS ./import-legacy.spec.ts - PASS ./import-star.spec.ts - FAIL ./import-default.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-default.spec.ts:4:22) - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module es2015 with preset js-with-babel-esm run with options: {"module":"es2015","allowSyntheticDefaultImports":false} with template with-babel-7 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"/lib"' can only be default-imported using the 'allowSyntheticDefaultImports' flag - - 1 import lib from './lib' - ~~~ - - lib.d.ts:5:1 - 5 export = lib - ~~~~~~~~~~~~ - This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag. - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module es2015 with preset js-with-babel-esm run with options: {"module":"es2015","allowSyntheticDefaultImports":false} with template with-babel-7-string-config 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"/lib"' can only be default-imported using the 'allowSyntheticDefaultImports' flag - - 1 import lib from './lib' - ~~~ - - lib.d.ts:5:1 - 5 export = lib - ~~~~~~~~~~~~ - This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag. - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module es2015 with preset js-with-babel-esm run with options: {"module":"es2015","allowSyntheticDefaultImports":true} with template with-babel-7 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module es2015 with preset js-with-babel-esm run with options: {"module":"es2015","allowSyntheticDefaultImports":true} with template with-babel-7-string-config 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module es2015 with preset js-with-babel-esm run with options: {"module":"es2015","esModuleInterop":false} with template with-babel-7 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"/lib"' can only be default-imported using the 'allowSyntheticDefaultImports' flag - - 1 import lib from './lib' - ~~~ - - lib.d.ts:5:1 - 5 export = lib - ~~~~~~~~~~~~ - This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag. - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module es2015 with preset js-with-babel-esm run with options: {"module":"es2015","esModuleInterop":false} with template with-babel-7-string-config 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"/lib"' can only be default-imported using the 'allowSyntheticDefaultImports' flag - - 1 import lib from './lib' - ~~~ - - lib.d.ts:5:1 - 5 export = lib - ~~~~~~~~~~~~ - This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag. - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module es2015 with preset js-with-babel-esm run with options: {"module":"es2015","esModuleInterop":true} with template with-babel-7 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - ts-jest[ts-compiler] (WARN) import-star.spec.ts:5:10 - error TS2349: This expression is not callable. - Type 'typeof lib' has no call signatures. - - 5 expect(lib()).toBe('foo') - ~~~ - - import-star.spec.ts:1:1 - 1 import * as lib from './lib' - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead. - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module es2015 with preset js-with-babel-esm run with options: {"module":"es2015","esModuleInterop":true} with template with-babel-7-string-config 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - ts-jest[ts-compiler] (WARN) import-star.spec.ts:5:10 - error TS2349: This expression is not callable. - Type 'typeof lib' has no call signatures. - - 5 expect(lib()).toBe('foo') - ~~~ - - import-star.spec.ts:1:1 - 1 import * as lib from './lib' - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead. - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module es2015 with preset js-with-babel-esm run with options: {"module":"es2015"} with template with-babel-7 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"/lib"' can only be default-imported using the 'allowSyntheticDefaultImports' flag - - 1 import lib from './lib' - ~~~ - - lib.d.ts:5:1 - 5 export = lib - ~~~~~~~~~~~~ - This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag. - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module es2015 with preset js-with-babel-esm run with options: {"module":"es2015"} with template with-babel-7-string-config 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"/lib"' can only be default-imported using the 'allowSyntheticDefaultImports' flag - - 1 import lib from './lib' - ~~~ - - lib.d.ts:5:1 - 5 export = lib - ~~~~~~~~~~~~ - This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag. - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module es2015 with preset js-with-ts-esm run with options: {"module":"es2015","allowSyntheticDefaultImports":false} with template default 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting \`esModuleInterop\` to \`true\` in your TypeScript configuration file (usually \`tsconfig.json\`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. - PASS ./import-legacy.spec.ts - PASS ./import-star.spec.ts - ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"/lib"' can only be default-imported using the 'esModuleInterop' flag - - 1 import lib from './lib' - ~~~ - - lib.d.ts:5:1 - 5 export = lib - ~~~~~~~~~~~~ - This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. - FAIL ./import-default.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-default.spec.ts:4:22) - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module es2015 with preset js-with-ts-esm run with options: {"module":"es2015","allowSyntheticDefaultImports":true} with template default 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - PASS ./import-legacy.spec.ts - PASS ./import-star.spec.ts - FAIL ./import-default.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-default.spec.ts:4:22) - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module es2015 with preset js-with-ts-esm run with options: {"module":"es2015","esModuleInterop":false} with template default 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting \`esModuleInterop\` to \`true\` in your TypeScript configuration file (usually \`tsconfig.json\`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. - PASS ./import-legacy.spec.ts - PASS ./import-star.spec.ts - FAIL ./import-default.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-default.spec.ts:4:22) - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module es2015 with preset js-with-ts-esm run with options: {"module":"es2015","esModuleInterop":true} with template default 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - PASS ./import-legacy.spec.ts - ts-jest[ts-compiler] (WARN) import-star.spec.ts:5:10 - error TS2349: This expression is not callable. - Type 'typeof lib' has no call signatures. - - 5 expect(lib()).toBe('foo') - ~~~ - - import-star.spec.ts:1:1 - 1 import * as lib from './lib' - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead. - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - PASS ./import-default.spec.ts - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module es2015 with preset js-with-ts-esm run with options: {"module":"es2015"} with template default 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting \`esModuleInterop\` to \`true\` in your TypeScript configuration file (usually \`tsconfig.json\`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. - PASS ./import-legacy.spec.ts - PASS ./import-star.spec.ts - FAIL ./import-default.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-default.spec.ts:4:22) - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; diff --git a/e2e/__tests__/module-kinds/__snapshots__/esnext-esm.test.ts.snap b/e2e/__tests__/module-kinds/__snapshots__/esnext-esm.test.ts.snap deleted file mode 100644 index dcb65bee5f..0000000000 --- a/e2e/__tests__/module-kinds/__snapshots__/esnext-esm.test.ts.snap +++ /dev/null @@ -1,1021 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Module esnext with preset default-esm run with options: {"module":"esnext","allowSyntheticDefaultImports":false} with template default 1`] = ` - × jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting \`esModuleInterop\` to \`true\` in your TypeScript configuration file (usually \`tsconfig.json\`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. - PASS ./import-legacy.spec.ts - PASS ./import-star.spec.ts - ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"/lib"' can only be default-imported using the 'esModuleInterop' flag - - 1 import lib from './lib' - ~~~ - - lib.d.ts:5:1 - 5 export = lib - ~~~~~~~~~~~~ - This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. - FAIL ./import-default.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-default.spec.ts:4:22) - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module esnext with preset default-esm run with options: {"module":"esnext","allowSyntheticDefaultImports":true} with template default 1`] = ` - × jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - PASS ./import-legacy.spec.ts - PASS ./import-star.spec.ts - FAIL ./import-default.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-default.spec.ts:4:22) - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module esnext with preset default-esm run with options: {"module":"esnext","esModuleInterop":false} with template default 1`] = ` - × jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting \`esModuleInterop\` to \`true\` in your TypeScript configuration file (usually \`tsconfig.json\`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. - PASS ./import-legacy.spec.ts - PASS ./import-star.spec.ts - FAIL ./import-default.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-default.spec.ts:4:22) - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module esnext with preset default-esm run with options: {"module":"esnext","esModuleInterop":true} with template default 1`] = ` - × jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - PASS ./import-legacy.spec.ts - ts-jest[ts-compiler] (WARN) import-star.spec.ts:5:10 - error TS2349: This expression is not callable. - Type 'typeof lib' has no call signatures. - - 5 expect(lib()).toBe('foo') - ~~~ - - import-star.spec.ts:1:1 - 1 import * as lib from './lib' - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead. - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - PASS ./import-default.spec.ts - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module esnext with preset default-esm run with options: {"module":"esnext"} with template default 1`] = ` - × jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting \`esModuleInterop\` to \`true\` in your TypeScript configuration file (usually \`tsconfig.json\`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. - PASS ./import-legacy.spec.ts - PASS ./import-star.spec.ts - FAIL ./import-default.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-default.spec.ts:4:22) - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module esnext with preset js-with-babel-esm run with options: {"module":"esnext","allowSyntheticDefaultImports":false} with template with-babel-7 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"/lib"' can only be default-imported using the 'allowSyntheticDefaultImports' flag - - 1 import lib from './lib' - ~~~ - - lib.d.ts:5:1 - 5 export = lib - ~~~~~~~~~~~~ - This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag. - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module esnext with preset js-with-babel-esm run with options: {"module":"esnext","allowSyntheticDefaultImports":false} with template with-babel-7-string-config 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"/lib"' can only be default-imported using the 'allowSyntheticDefaultImports' flag - - 1 import lib from './lib' - ~~~ - - lib.d.ts:5:1 - 5 export = lib - ~~~~~~~~~~~~ - This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag. - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module esnext with preset js-with-babel-esm run with options: {"module":"esnext","allowSyntheticDefaultImports":true} with template with-babel-7 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module esnext with preset js-with-babel-esm run with options: {"module":"esnext","allowSyntheticDefaultImports":true} with template with-babel-7-string-config 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module esnext with preset js-with-babel-esm run with options: {"module":"esnext","esModuleInterop":false} with template with-babel-7 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"/lib"' can only be default-imported using the 'allowSyntheticDefaultImports' flag - - 1 import lib from './lib' - ~~~ - - lib.d.ts:5:1 - 5 export = lib - ~~~~~~~~~~~~ - This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag. - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module esnext with preset js-with-babel-esm run with options: {"module":"esnext","esModuleInterop":false} with template with-babel-7-string-config 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"/lib"' can only be default-imported using the 'allowSyntheticDefaultImports' flag - - 1 import lib from './lib' - ~~~ - - lib.d.ts:5:1 - 5 export = lib - ~~~~~~~~~~~~ - This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag. - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module esnext with preset js-with-babel-esm run with options: {"module":"esnext","esModuleInterop":true} with template with-babel-7 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - ts-jest[ts-compiler] (WARN) import-star.spec.ts:5:10 - error TS2349: This expression is not callable. - Type 'typeof lib' has no call signatures. - - 5 expect(lib()).toBe('foo') - ~~~ - - import-star.spec.ts:1:1 - 1 import * as lib from './lib' - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead. - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module esnext with preset js-with-babel-esm run with options: {"module":"esnext","esModuleInterop":true} with template with-babel-7-string-config 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - ts-jest[ts-compiler] (WARN) import-star.spec.ts:5:10 - error TS2349: This expression is not callable. - Type 'typeof lib' has no call signatures. - - 5 expect(lib()).toBe('foo') - ~~~ - - import-star.spec.ts:1:1 - 1 import * as lib from './lib' - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead. - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module esnext with preset js-with-babel-esm run with options: {"module":"esnext"} with template with-babel-7 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"/lib"' can only be default-imported using the 'allowSyntheticDefaultImports' flag - - 1 import lib from './lib' - ~~~ - - lib.d.ts:5:1 - 5 export = lib - ~~~~~~~~~~~~ - This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag. - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module esnext with preset js-with-babel-esm run with options: {"module":"esnext"} with template with-babel-7-string-config 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[ts-compiler] (WARN) import-legacy.spec.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. - - 1 import lib = require('./lib') - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - FAIL ./import-legacy.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-legacy.spec.ts:4:22) - - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"/lib"' can only be default-imported using the 'allowSyntheticDefaultImports' flag - - 1 import lib from './lib' - ~~~ - - lib.d.ts:5:1 - 5 export = lib - ~~~~~~~~~~~~ - This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag. - PASS ./import-default.spec.ts - - Test Suites: 2 failed, 1 passed, 3 total - Tests: 2 failed, 1 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module esnext with preset js-with-ts-esm run with options: {"module":"esnext","allowSyntheticDefaultImports":false} with template default 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting \`esModuleInterop\` to \`true\` in your TypeScript configuration file (usually \`tsconfig.json\`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. - PASS ./import-legacy.spec.ts - PASS ./import-star.spec.ts - ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"/lib"' can only be default-imported using the 'esModuleInterop' flag - - 1 import lib from './lib' - ~~~ - - lib.d.ts:5:1 - 5 export = lib - ~~~~~~~~~~~~ - This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. - FAIL ./import-default.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-default.spec.ts:4:22) - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module esnext with preset js-with-ts-esm run with options: {"module":"esnext","allowSyntheticDefaultImports":true} with template default 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - PASS ./import-legacy.spec.ts - PASS ./import-star.spec.ts - FAIL ./import-default.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-default.spec.ts:4:22) - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module esnext with preset js-with-ts-esm run with options: {"module":"esnext","esModuleInterop":false} with template default 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting \`esModuleInterop\` to \`true\` in your TypeScript configuration file (usually \`tsconfig.json\`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. - PASS ./import-legacy.spec.ts - PASS ./import-star.spec.ts - FAIL ./import-default.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-default.spec.ts:4:22) - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module esnext with preset js-with-ts-esm run with options: {"module":"esnext","esModuleInterop":true} with template default 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - PASS ./import-legacy.spec.ts - ts-jest[ts-compiler] (WARN) import-star.spec.ts:5:10 - error TS2349: This expression is not callable. - Type 'typeof lib' has no call signatures. - - 5 expect(lib()).toBe('foo') - ~~~ - - import-star.spec.ts:1:1 - 1 import * as lib from './lib' - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead. - FAIL ./import-star.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "object" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-star.spec.ts:4:22) - - PASS ./import-default.spec.ts - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`Module esnext with preset js-with-ts-esm run with options: {"module":"esnext"} with template default 1`] = ` - × node --experimental-vm-modules node_modules/.bin/jest --no-cache - ↳ exit code: 1 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting \`esModuleInterop\` to \`true\` in your TypeScript configuration file (usually \`tsconfig.json\`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. - PASS ./import-legacy.spec.ts - PASS ./import-star.spec.ts - FAIL ./import-default.spec.ts - ● import default - - expect(received).toBe(expected) // Object.is equality - - Expected: "function" - Received: "undefined" - - 2 | - 3 | test('import default', () => { - > 4 | expect(typeof lib).toBe('function') - | ^ - 5 | expect(lib()).toBe('foo') - 6 | expect(lib.bar).toBe('bar') - 7 | }) - - at Object. (import-default.spec.ts:4:22) - - Test Suites: 1 failed, 2 passed, 3 total - Tests: 1 failed, 2 passed, 3 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; diff --git a/e2e/__tests__/module-kinds/es2015-esm.test.ts b/e2e/__tests__/module-kinds/es2015-esm.test.ts deleted file mode 100644 index f97a2e6279..0000000000 --- a/e2e/__tests__/module-kinds/es2015-esm.test.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { AllPreset, esmOnly as describe, runTestCases } from './helpers' - -describe.each([ - AllPreset.DEFAULT_ESM, - AllPreset.JS_WITH_TS_ESM, - AllPreset.JS_WITH_BABEL_ESM -])('Module es2015 with preset %s', (preset) => { - runTestCases('es2015', preset) -}) diff --git a/e2e/__tests__/module-kinds/esnext-esm.test.ts b/e2e/__tests__/module-kinds/esnext-esm.test.ts deleted file mode 100644 index e1870ad5b2..0000000000 --- a/e2e/__tests__/module-kinds/esnext-esm.test.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { AllPreset, esmOnly as describe, runTestCases } from './helpers' - -describe.each([ - AllPreset.DEFAULT_ESM, - AllPreset.JS_WITH_TS_ESM, - AllPreset.JS_WITH_BABEL_ESM -])('Module esnext with preset %s', (preset) => { - runTestCases('esnext', preset) -}) diff --git a/src/compiler/__snapshots__/ts-compiler.spec.ts.snap b/src/compiler/__snapshots__/ts-compiler.spec.ts.snap index 4b61a77801..972e486d86 100644 --- a/src/compiler/__snapshots__/ts-compiler.spec.ts.snap +++ b/src/compiler/__snapshots__/ts-compiler.spec.ts.snap @@ -171,3 +171,15 @@ exports[`TsCompiler isolatedModule true should compile js file for allowJs true version: 3 ================================================================================ `; + +exports[`TsCompiler isolatedModule true support ESM should transpile codes to correct syntax with supportsStaticESM and useESM options 1`] = `99`; + +exports[`TsCompiler isolatedModule true support ESM should transpile codes to correct syntax with supportsStaticESM and useESM options 2`] = `99`; + +exports[`TsCompiler isolatedModule true support ESM should transpile codes to correct syntax with supportsStaticESM and useESM options 3`] = `99`; + +exports[`TsCompiler isolatedModule true support ESM should transpile codes to correct syntax with supportsStaticESM and useESM options 4`] = `1`; + +exports[`TsCompiler isolatedModule true support ESM should transpile codes to correct syntax with supportsStaticESM and useESM options 5`] = `1`; + +exports[`TsCompiler isolatedModule true support ESM should transpile codes to correct syntax with supportsStaticESM and useESM options 6`] = `1`; diff --git a/src/compiler/ts-compiler.spec.ts b/src/compiler/ts-compiler.spec.ts index 8a56d085ab..8dffda3d31 100644 --- a/src/compiler/ts-compiler.spec.ts +++ b/src/compiler/ts-compiler.spec.ts @@ -1,6 +1,7 @@ import { readFileSync } from 'fs' import { LogLevels } from 'bs-logger' import { join } from 'path' +import ts from 'typescript' import { TS_JEST_OUT_DIR } from '../config/config-set' import { makeCompiler } from '../__helpers__/fakers' @@ -160,6 +161,57 @@ const t: string = f(5) ).not.toThrowError() }) }) + + describe('support ESM', () => { + test.each([ + { + supportsStaticESM: true, + useESM: true, + moduleKind: 'esnext', + }, + { + supportsStaticESM: true, + useESM: true, + moduleKind: 'amd', + }, + { + supportsStaticESM: true, + useESM: true, + moduleKind: undefined, + }, + { + supportsStaticESM: false, + useESM: true, + moduleKind: 'esnext', + }, + { + supportsStaticESM: true, + useESM: false, + moduleKind: 'amd', + }, + { + supportsStaticESM: false, + useESM: false, + moduleKind: 'es2015', + }, + ])('should transpile codes to correct syntax with supportsStaticESM and useESM options', (data) => { + const transpileModuleSpy = (ts.transpileModule = jest.fn().mockReturnValueOnce({ + outputText: 'var foo = 1', + diagnostics: [], + sourceMapText: '{}', + })) + const fileContent = `const foo = import('./foo')` + const fileName = 'foo.ts' + + const compiler = makeCompiler({ + tsJestConfig: { ...baseTsJestConfig, tsconfig: { module: data.moduleKind as any }, useESM: data.useESM }, + }) + compiler.getCompiledOutput(fileContent, fileName, data.supportsStaticESM) + + expect(transpileModuleSpy).toHaveBeenCalled() + expect(transpileModuleSpy.mock.calls[0][1].compilerOptions.module).toMatchSnapshot() + }) + }) }) describe('isolatedModule false', () => { diff --git a/src/compiler/ts-compiler.ts b/src/compiler/ts-compiler.ts index 3ece6ee559..6285036ec5 100644 --- a/src/compiler/ts-compiler.ts +++ b/src/compiler/ts-compiler.ts @@ -1,13 +1,14 @@ import { LogContexts, Logger, LogLevels } from 'bs-logger' import memoize from 'lodash.memoize' import { basename, normalize, relative } from 'path' -import type { +import { EmitOutput, LanguageService, LanguageServiceHost, ParsedCommandLine, ResolvedModuleFull, TranspileOutput, + ModuleKind, } from 'typescript' import { updateOutput } from './compiler-utils' @@ -17,6 +18,8 @@ import type { CompilerInstance, ResolvedModulesMap, StringMap, TTypeScript } fro import { rootLogger } from '../utils/logger' import { Errors, interpolate } from '../utils/messages' +const AVAILABLE_ESM_MODULE_KINDS = [ModuleKind.ES2015, ModuleKind.ES2020, ModuleKind.ESNext] + /** * @internal */ @@ -41,6 +44,10 @@ export class TsCompiler implements CompilerInstance { } private _createLanguageService(): void { + const compilerOptions = { + ...this._parsedTsConfig.options, + module: ModuleKind.CommonJS, + } const serviceHostTraceCtx = { namespace: 'ts:serviceHost', call: null, @@ -60,11 +67,7 @@ export class TsCompiler implements CompilerInstance { realpath: this._ts.sys.realpath && memoize(this._ts.sys.realpath), getDirectories: memoize(this._ts.sys.getDirectories), } - const moduleResolutionCache = this._ts.createModuleResolutionCache( - this.configSet.cwd, - (x) => x, - this._parsedTsConfig.options, - ) + const moduleResolutionCache = this._ts.createModuleResolutionCache(this.configSet.cwd, (x) => x, compilerOptions) /* istanbul ignore next */ const serviceHost: LanguageServiceHost = { getProjectVersion: () => String(this._projectVersion), @@ -109,15 +112,15 @@ export class TsCompiler implements CompilerInstance { realpath: this._ts.sys.realpath && memoize(this._ts.sys.realpath), getNewLine: () => LINE_FEED, getCurrentDirectory: () => this.configSet.cwd, - getCompilationSettings: () => this._parsedTsConfig.options, - getDefaultLibFileName: () => this._ts.getDefaultLibFilePath(this._parsedTsConfig.options), + getCompilationSettings: () => compilerOptions, + getDefaultLibFileName: () => this._ts.getDefaultLibFilePath(compilerOptions), getCustomTransformers: () => this.configSet.customTransformers, resolveModuleNames: (moduleNames: string[], containingFile: string): (ResolvedModuleFull | undefined)[] => moduleNames.map((moduleName) => { const { resolvedModule } = this._ts.resolveModuleName( moduleName, containingFile, - this._parsedTsConfig.options, + compilerOptions, moduleResolutionHost, moduleResolutionCache, ) @@ -138,7 +141,7 @@ export class TsCompiler implements CompilerInstance { return (this._languageService?.getProgram()?.getSourceFile(fileName) as any)?.resolvedModules } - getCompiledOutput(fileContent: string, fileName: string): string { + getCompiledOutput(fileContent: string, fileName: string, supportsStaticESM: boolean): string { if (this._languageService) { this._logger.debug({ fileName }, 'getCompiledOutput(): compiling using language service') @@ -164,12 +167,25 @@ export class TsCompiler implements CompilerInstance { return updateOutput(output.outputFiles[1].text, fileName, output.outputFiles[0].text) } else { + let moduleKind = this._parsedTsConfig.options.module + if (supportsStaticESM && this.configSet.useESM) { + moduleKind = + !moduleKind || (moduleKind && !AVAILABLE_ESM_MODULE_KINDS.includes(moduleKind)) + ? ModuleKind.ESNext + : moduleKind + } else { + moduleKind = ModuleKind.CommonJS + } + this._logger.debug({ fileName }, 'getCompiledOutput(): compiling as isolated module') const result: TranspileOutput = this._ts.transpileModule(fileContent, { fileName, transformers: this.configSet.customTransformers, - compilerOptions: this._parsedTsConfig.options, + compilerOptions: { + ...this._parsedTsConfig.options, + module: moduleKind, + }, reportDiagnostics: this.configSet.shouldReportDiagnostics(fileName), }) if (result.diagnostics && this.configSet.shouldReportDiagnostics(fileName)) { diff --git a/src/compiler/ts-jest-compiler.ts b/src/compiler/ts-jest-compiler.ts index d76ea05621..ce82353d46 100644 --- a/src/compiler/ts-jest-compiler.ts +++ b/src/compiler/ts-jest-compiler.ts @@ -17,7 +17,7 @@ export class TsJestCompiler implements CompilerInstance { return this._compilerInstance.getResolvedModulesMap(fileContent, fileName) } - getCompiledOutput(fileContent: string, fileName: string): string { - return this._compilerInstance.getCompiledOutput(fileContent, fileName) + getCompiledOutput(fileContent: string, fileName: string, supportsStaticESM = false): string { + return this._compilerInstance.getCompiledOutput(fileContent, fileName, supportsStaticESM) } } diff --git a/src/config/config-set.spec.ts b/src/config/config-set.spec.ts index 187c3c3ea4..6d26891a94 100644 --- a/src/config/config-set.spec.ts +++ b/src/config/config-set.spec.ts @@ -47,8 +47,7 @@ describe('parsedTsConfig', () => { }) it('should override some options', () => { - expect(get({ tsconfig: { module: 'esnext' as any, inlineSources: false } }).options).toMatchObject({ - module: ts.ModuleKind.CommonJS, + expect(get({ tsconfig: { inlineSources: false } }).options).toMatchObject({ inlineSources: true, }) }) @@ -70,19 +69,19 @@ describe('parsedTsConfig', () => { }) }) - it('should warn about possibly wrong module config and set synth. default imports', () => { + it('should warn about possibly wrong module config and set synth. default imports with module None/AMD/UMD/System', () => { const target = logTargetMock() target.clear() const cs = createConfigSet({ tsJestConfig: { - tsconfig: { module: 'ES6', esModuleInterop: false } as any, + tsconfig: { module: 'AMD', esModuleInterop: false } as any, diagnostics: { warnOnly: true, pretty: false }, }, resolve: null, }) expect(cs.parsedTsConfig.options).toMatchObject({ - module: ts.ModuleKind.CommonJS, + module: ts.ModuleKind.AMD, allowSyntheticDefaultImports: true, esModuleInterop: false, }) @@ -692,7 +691,6 @@ describe('_resolveTsConfig', () => { expect(parseConfig.mock.calls[0][4]).toBe(tscfgPathStub) expect(conf.options.allowSyntheticDefaultImports).toEqual(true) expect(conf.errors).toMatchSnapshot() - expect(cs.parsedTsConfig.options.module).toEqual(ts.ModuleKind.CommonJS) }) it('should use given tsconfig path', () => { @@ -715,7 +713,6 @@ describe('_resolveTsConfig', () => { expect(parseConfig.mock.calls[0][2]).toBe('/foo') expect(parseConfig.mock.calls[0][4]).toBe(tscfgPathStub) expect(conf.errors).toMatchSnapshot() - expect(cs.parsedTsConfig.options.module).not.toEqual(ts.ModuleKind.CommonJS) }) }) @@ -756,7 +753,6 @@ describe('_resolveTsConfig', () => { expect(parseConfig.mock.calls[0][4]).toBe(tscfgPathStub) expect(conf.options.allowSyntheticDefaultImports).toEqual(true) expect(conf.errors).toMatchSnapshot() - expect(cs.parsedTsConfig.options.module).toEqual(ts.ModuleKind.CommonJS) }) it('should use given tsconfig path', () => { @@ -779,7 +775,6 @@ describe('_resolveTsConfig', () => { expect(parseConfig.mock.calls[0][2]).toBe('/foo') expect(parseConfig.mock.calls[0][4]).toBe(tscfgPathStub) expect(conf.errors).toMatchSnapshot() - expect(cs.parsedTsConfig.options.module).not.toEqual(ts.ModuleKind.CommonJS) }) }) @@ -820,7 +815,6 @@ describe('_resolveTsConfig', () => { expect(parseConfig.mock.calls[0][4]).toBe(tscfgPathStub) expect(conf.options.allowSyntheticDefaultImports).toBeUndefined() expect(conf.errors).toEqual([]) - expect(cs.parsedTsConfig.options.module).toEqual(ts.ModuleKind.CommonJS) }) it('should use given tsconfig path', () => { @@ -843,7 +837,6 @@ describe('_resolveTsConfig', () => { expect(parseConfig.mock.calls[0][2]).toBe('/foo') expect(parseConfig.mock.calls[0][4]).toBe(tscfgPathStub) expect(conf.errors).toEqual([]) - expect(cs.parsedTsConfig.options.module).not.toEqual(ts.ModuleKind.CommonJS) }) }) @@ -884,7 +877,6 @@ describe('_resolveTsConfig', () => { expect(parseConfig.mock.calls[0][4]).toBe(tscfgPathStub) expect(conf.errors).toEqual([]) expect(conf.options.allowSyntheticDefaultImports).toEqual(true) - expect(cs.parsedTsConfig.options.module).toEqual(ts.ModuleKind.CommonJS) }) it('should use given tsconfig path', () => { @@ -908,7 +900,6 @@ describe('_resolveTsConfig', () => { expect(parseConfig.mock.calls[0][4]).toBe(tscfgPathStub) expect(conf.errors).toEqual([]) expect(conf.options.allowSyntheticDefaultImports).toEqual(true) - expect(cs.parsedTsConfig.options.module).not.toEqual(ts.ModuleKind.CommonJS) }) }) }) diff --git a/src/config/config-set.ts b/src/config/config-set.ts index 7aad574819..9780597082 100644 --- a/src/config/config-set.ts +++ b/src/config/config-set.ts @@ -12,7 +12,7 @@ import type { Config } from '@jest/types' import { LogContexts, Logger } from 'bs-logger' import { existsSync, readFileSync } from 'fs' import { globsToMatcher } from 'jest-util' -import json5 = require('json5') +import json5 from 'json5' import { dirname, extname, isAbsolute, join, normalize, resolve } from 'path' import { CompilerOptions, @@ -20,6 +20,7 @@ import { Diagnostic, FormatDiagnosticsHost, ParsedCommandLine, + ModuleKind, ScriptTarget, } from 'typescript' @@ -115,6 +116,7 @@ export class ConfigSet { tsCacheDir: string | undefined parsedTsConfig!: ParsedCommandLine | Record customTransformers: CustomTransformers = Object.create(null) + useESM = false /** * @internal */ @@ -183,7 +185,7 @@ export class ConfigSet { this.logger.debug({ compilerModule: this.compilerModule }, 'normalized compiler module config via ts-jest option') this._backportJestCfg() - this._setupTsJestCfg(options) + this._setupConfigSet(options) this._resolveTsCacheDir() this._matchablePatterns = [...this._jestCfg.testMatch, ...this._jestCfg.testRegex].filter( (pattern) => @@ -215,7 +217,10 @@ export class ConfigSet { /** * @internal */ - private _setupTsJestCfg(options: TsJestGlobalOptions): void { + private _setupConfigSet(options: TsJestGlobalOptions): void { + // useESM + this.useESM = options.useESM ?? false + // babel config (for babel-jest) default is undefined so we don't need to have fallback like tsConfig if (!options.babelConfig) { this.logger.debug('babel is disabled') @@ -244,12 +249,7 @@ export class ConfigSet { } this.logger.debug({ babelConfig: this.babelConfig }, 'normalized babel config via ts-jest option') - } - if (!this.babelConfig) { - this._overriddenCompilerOptions.module = this.jestConfig.extensionsToTreatAsEsm.length - ? undefined - : this.compilerModule.ModuleKind.CommonJS - } else { + this.babelJestTransformer = importer .babelJest(ImportReasons.BabelJest) .createTransformer(this.babelConfig) as BabelJestTransformer @@ -412,19 +412,19 @@ export class ConfigSet { const finalOptions = result.options // Target ES2015 output by default (instead of ES3). if (finalOptions.target === undefined) { - finalOptions.target = ts.ScriptTarget.ES2015 + finalOptions.target = ScriptTarget.ES2015 } // check the module interoperability const target = finalOptions.target // compute the default if not set - const defaultModule = [ts.ScriptTarget.ES3, ts.ScriptTarget.ES5].includes(target) - ? ts.ModuleKind.CommonJS - : ts.ModuleKind.ESNext + const defaultModule = [ScriptTarget.ES3, ScriptTarget.ES5].includes(target) + ? ModuleKind.CommonJS + : ModuleKind.ESNext const moduleValue = finalOptions.module ?? defaultModule if ( - 'module' in forcedOptions && - moduleValue !== forcedOptions.module && + !this.babelConfig && + moduleValue !== ModuleKind.CommonJS && !(finalOptions.esModuleInterop || finalOptions.allowSyntheticDefaultImports) ) { result.errors.push({ diff --git a/src/ts-jest-transformer.ts b/src/ts-jest-transformer.ts index 9ab85ea1f9..5d755d2287 100644 --- a/src/ts-jest-transformer.ts +++ b/src/ts-jest-transformer.ts @@ -156,7 +156,7 @@ export class TsJestTransformer implements Transformer { result = fileContent } else if (isJsFile || isTsFile) { // transpile TS code (source maps are included) - result = this._compiler.getCompiledOutput(fileContent, filePath) + result = this._compiler.getCompiledOutput(fileContent, filePath, transformOptions.supportsStaticESM) } else { // we should not get called for files with other extension than js[x], ts[x] and d.ts, // TypeScript will bail if we try to compile, and if it was to call babel, users can diff --git a/src/types.ts b/src/types.ts index 2dbaa54b9a..ef041cfd15 100644 --- a/src/types.ts +++ b/src/types.ts @@ -132,6 +132,12 @@ export interface TsJestGlobalOptions { * exporting the content of the file as a string */ stringifyContentPathRegex?: string | RegExp + + /** + * Tell `ts-jest` to transform codes to ESM format. This only works in combination with `jest-runtime` ESM option + * `supportsStaticESM` true which is passed into Jest transformer + */ + useESM?: boolean } interface TsJestConfig$tsConfig$file { @@ -191,7 +197,7 @@ export type StringMap = Map export interface CompilerInstance { getResolvedModulesMap(fileContent: string, fileName: string): ResolvedModulesMap - getCompiledOutput(fileContent: string, fileName: string): string + getCompiledOutput(fileContent: string, fileName: string, supportsStaticESM: boolean): string } /** * @internal diff --git a/website/docs/esm-support.md b/website/docs/esm-support.md new file mode 100644 index 0000000000..15646234f6 --- /dev/null +++ b/website/docs/esm-support.md @@ -0,0 +1,10 @@ +--- +title: ESM Support +--- + +To use `ts-jest` with ESM support, you'll first need to check [ESM Jest documentation](https://jestjs.io/docs/en/ecmascript-modules). + +`ts-jest` supports ESM via a config option `useESM`. When this option is enabled and depending on which files Jest supports +ESM, `ts-jest` will transform codes to ESM syntax. There are also 3 presets to use with `useESM` option. + +More information see [useESM option](options/useESM.md) and [ESM presets](presets.md) diff --git a/website/docs/options.md b/website/docs/options.md index 63953d5e06..3851567fe8 100644 --- a/website/docs/options.md +++ b/website/docs/options.md @@ -65,6 +65,7 @@ All options have default values which should fit most of the projects. Click on | [**`diagnostics`**][diagnostics] | [Diagnostics related configuration.][diagnostics] | `boolean`\|`object` | _enabled_ | | [**`babelConfig`**][babelConfig] | [Babel(Jest) related configuration.][babelConfig] | `boolean`\|`string`\|`object` | _disabled_ | | [**`stringifyContentPathRegex`**][stringifyContentPathRegex] | [Files which will become modules returning self content.][stringifyContentPathRegex] | `string`\|`RegExp` | _disabled_ | +| [**`useESM`**][useESM] | [Enable ESM support][useESM] | `boolean` | _auto_ | [compiler]: options/compiler [tsconfig]: options/tsconfig @@ -74,3 +75,4 @@ All options have default values which should fit most of the projects. Click on [diagnostics]: options/diagnostics [babelConfig]: options/babelConfig [stringifyContentPathRegex]: options/stringifyContentPathRegex +[useESM]: options/useESM diff --git a/website/docs/options/useESM.md b/website/docs/options/useESM.md new file mode 100644 index 0000000000..e1fe4bf54a --- /dev/null +++ b/website/docs/options/useESM.md @@ -0,0 +1,37 @@ +--- +title: useESM option +--- + +The `useESM` option allows `ts-jest` to transform codes to ESM syntax **if possible**. + +The default value is **false**, `ts-jest` will transform codes to `CommonJS` syntax. + +Currently `ts-jest` only supports this option in combination with `isolatedModule: true`. + +### Examples + +```js +// jest.config.js +module.exports = { + // [...] + globals: { + 'ts-jest': { + useESM: true, + }, + }, +} +``` + +```json5 +// OR package.json +{ + // [...] + "jest": { + "globals": { + "ts-jest": { + "useESM": true, + } + } + } +} +``` diff --git a/website/sidebars.js b/website/sidebars.js index abb55355dd..15e9696ec6 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -13,6 +13,10 @@ module.exports = { type: 'doc', id: 'test-helpers', }, + { + type: 'doc', + id: 'esm-support', + }, { type: 'doc', id: 'react-native',