diff --git a/docs/user/config/index.md b/docs/user/config/index.md index 2e66eba6e9..9046ec0099 100644 --- a/docs/user/config/index.md +++ b/docs/user/config/index.md @@ -54,20 +54,18 @@ module.exports = { Any preset can also be used with other options. If you're already using another preset, you might want only some specific settings from the chosen `ts-jest` preset. -In this case you'll need to use the JavaScript version of Jest config: +In this case you'll need to use the JavaScript version of Jest config (comment/uncomment according to your use-case): ```js // jest.config.js -const tsJestPresets = require('ts-jest/presets'); - -const preset = tsJestPresets.defaults -// const preset = tsJestPresets.jsWithTs -// const preset = tsJestPresets.jsWithBabel +const { defaults: tsjPreset } = require('ts-jest/presets'); +// const { jsWithTs: tsjPreset } = require('ts-jest/presets'); +// const { jsWithBabel: tsjPreset } = require('ts-jest/presets'); module.exports = { // [...] transform: { - ...preset.transform, + ...tsjPreset.transform, // [...] } } diff --git a/e2e/__tests__/__snapshots__/test-helpers.test.ts.snap b/e2e/__tests__/__snapshots__/test-helpers.test.ts.snap new file mode 100644 index 0000000000..94c6eb5028 --- /dev/null +++ b/e2e/__tests__/__snapshots__/test-helpers.test.ts.snap @@ -0,0 +1,63 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`test-helpers 1`] = ` + × jest --no-cache + ↳ exit code: 1 + ===[ STDOUT ]=================================================================== + + ===[ STDERR ]=================================================================== + PASS ./pass.spec.ts + FAIL ./fail.spec.ts + ● Test suite failed to run + + TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option): + fail.spec.ts:7:10 - error TS2554: Expected 0 arguments, but got 1. + + 7 expect(mocked(foo)('hello')).toBeUndefined() + ~~~~~~~~~~~~~~~~~~~~ + fail.spec.ts:9:46 - error TS2345: Argument of type '42' is not assignable to parameter of type 'string'. + + 9 expect(mocked(bar, true).dummy.deep.deeper(42)).toBeUndefined() + ~~ + + ts-jest[root] (WARN) The \`mocked\` helper has been moved to \`ts-jest/utils\`. Use \`import { mocked } from 'ts-jest/utils'\` instead. + PASS ./deprecated.spec.ts + + Test Suites: 1 failed, 2 passed, 3 total + Tests: 3 passed, 3 total + Snapshots: 0 total + Time: XXs + Ran all test suites. + ================================================================================ +`; + +exports[`with esModuleInterop set to false 1`] = ` + × jest --no-cache + ↳ exit code: 1 + ===[ STDOUT ]=================================================================== + + ===[ STDERR ]=================================================================== + PASS ./pass.spec.ts + FAIL ./fail.spec.ts + ● Test suite failed to run + + TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option): + fail.spec.ts:7:10 - error TS2554: Expected 0 arguments, but got 1. + + 7 expect(mocked(foo)('hello')).toBeUndefined() + ~~~~~~~~~~~~~~~~~~~~ + fail.spec.ts:9:46 - error TS2345: Argument of type '42' is not assignable to parameter of type 'string'. + + 9 expect(mocked(bar, true).dummy.deep.deeper(42)).toBeUndefined() + ~~ + + ts-jest[root] (WARN) The \`mocked\` helper has been moved to \`ts-jest/utils\`. Use \`import { mocked } from 'ts-jest/utils'\` instead. + PASS ./deprecated.spec.ts + + Test Suites: 1 failed, 2 passed, 3 total + Tests: 3 passed, 3 total + Snapshots: 0 total + Time: XXs + Ran all test suites. + ================================================================================ +`; diff --git a/src/cli/cli.spec.ts b/src/cli/cli.spec.ts index 9297646f84..2938ab81f1 100644 --- a/src/cli/cli.spec.ts +++ b/src/cli/cli.spec.ts @@ -154,7 +154,7 @@ Jest configuration written to "${normalize('/foo/bar/jest.config.foo.js')}". expect(fs.writeFileSync.mock.calls).toEqual([ [ normalize('/foo/bar/jest.config.foo.js'), - `const tsjPreset = require('ts-jest/presets/js-with-ts'); + `const { jsWithTs: tsjPreset } = require('ts-jest/presets'); module.exports = { ...tsjPreset, diff --git a/src/cli/helpers/presets.ts b/src/cli/helpers/presets.ts index a220a67f84..1289a7dbeb 100644 --- a/src/cli/helpers/presets.ts +++ b/src/cli/helpers/presets.ts @@ -38,7 +38,7 @@ const definePreset = (fullName: string): TsJestPresetDescriptor => ({ return require(`../../../${fullName.replace(/^ts-jest\//, '')}/jest-preset`) }, jsImport(varName = 'tsjPreset') { - return `const ${varName} = require('${this.fullName}')` + return `const { ${this.jsVarName}: ${varName} } = require('ts-jest/presets')` }, get isDefault() { return fullName === JestPresetNames.default