├── .editorconfig ├── .gitattributes ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── bug.yml │ ├── config.yml │ ├── feature.yml │ └── question.yml ├── PULL_REQUEST_TEMPLATE.md ├── SUPPORT.md ├── actions │ └── setup-workspace │ │ └── action.yml └── workflows │ ├── ci.yml │ ├── doc-ci.yml │ ├── prepare-cache.yml │ ├── release-and-publish.yml │ └── test.yml ├── .gitignore ├── .husky ├── commit-msg ├── post-commit └── pre-commit ├── .lintstagedrc ├── .npmignore ├── .npmrc ├── .prettierignore ├── .prettierrc ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── TROUBLESHOOTING.md ├── cli.js ├── commitlint.config.ts ├── e2e ├── const-enum │ ├── __tests__ │ │ └── const-enum.spec.ts │ ├── jest-compiler-cjs.config.ts │ ├── jest-compiler-esm.config.ts │ ├── jest-transpiler-cjs.config.ts │ ├── jest-transpiler-esm.config.ts │ ├── package.json │ ├── src │ │ ├── bar-constant.ts │ │ ├── foo-constant.d.ts │ │ └── foo-constant.js │ ├── tsconfig-cjs-transpiler.spec.json │ ├── tsconfig-cjs.spec.json │ ├── tsconfig-esm-transpiler.spec.json │ └── tsconfig-esm.spec.json ├── enum │ ├── __tests__ │ │ └── enum.spec.ts │ ├── jest-compiler-cjs.config.ts │ ├── jest-compiler-esm.config.ts │ ├── jest-transpiler-cjs.config.ts │ ├── jest-transpiler-esm.config.ts │ ├── package.json │ ├── src │ │ └── bar-constant.ts │ ├── tsconfig-cjs-transpiler.spec.json │ ├── tsconfig-cjs.spec.json │ ├── tsconfig-esm-transpiler.spec.json │ └── tsconfig-esm.spec.json ├── esm-features │ ├── __tests__ │ │ └── esm-features.spec.ts │ ├── jest-compiler-esm.config.ts │ ├── jest-transpiler-esm.config.ts │ ├── package.json │ ├── src │ │ └── foo.json │ ├── tsconfig-esm-transpiler.spec.json │ ├── tsconfig-esm.spec.json │ └── tsconfig.json ├── extend-ts-jest │ ├── __tests__ │ │ └── extend-ts-jest.spec.ts │ ├── jest-compiler-cjs.config.ts │ ├── jest-compiler-esm.config.ts │ ├── jest-transpiler-cjs.config.ts │ ├── jest-transpiler-esm.config.ts │ ├── package.json │ ├── src │ │ └── foo-transformer.js │ ├── tsconfig-cjs-transpiler.spec.json │ ├── tsconfig-cjs.spec.json │ ├── tsconfig-esm-transpiler.spec.json │ └── tsconfig-esm.spec.json ├── hoist-jest │ ├── __tests__ │ │ └── hoist-import-jest.spec.ts │ ├── jest-compiler-cjs.config.ts │ ├── jest-transpiler-cjs.config.ts │ ├── package.json │ ├── src │ │ ├── a.js │ │ ├── b.js │ │ └── c.js │ ├── tsconfig-cjs-transpiler.spec.json │ ├── tsconfig-cjs.spec.json │ └── tsconfig.json ├── package-lock.json ├── package.json ├── presets │ ├── __tests__ │ │ └── presets.spec.ts │ ├── jest-compiler-cjs.config.ts │ ├── jest-compiler-esm.config.ts │ ├── jest-transpiler-cjs.config.ts │ ├── jest-transpiler-esm.config.ts │ ├── package.json │ ├── tsconfig-cjs-transpiler.spec.json │ ├── tsconfig-cjs.spec.json │ ├── tsconfig-esm-transpiler.spec.json │ └── tsconfig-esm.spec.json ├── source-map │ ├── __tests__ │ │ ├── __snapshots__ │ │ │ └── source-map.spec.ts.snap │ │ └── source-map.spec.ts │ ├── jest-compiler-cjs.config.ts │ ├── jest-compiler-esm.config.ts │ ├── jest-transpiler-cjs.config.ts │ ├── jest-transpiler-esm.config.ts │ ├── package.json │ ├── src │ │ ├── error.test-error.js │ │ └── jest-fake.config.js │ ├── tsconfig-cjs-transpiler.spec.json │ └── tsconfig-esm-transpiler.spec.json ├── test-utils │ ├── __tests__ │ │ └── test-utils.spec.ts │ ├── jest-compiler-cjs.config.ts │ ├── jest-compiler-esm.config.ts │ ├── jest-transpiler-cjs.config.ts │ ├── jest-transpiler-esm.config.ts │ ├── package.json │ ├── tsconfig-cjs-transpiler.spec.json │ └── tsconfig-esm-transpiler.spec.json ├── transform-js │ ├── __tests__ │ │ └── transform-js.spec.ts │ ├── jest-compiler-cjs.config.ts │ ├── jest-compiler-esm.config.ts │ ├── jest-transpiler-cjs.config.ts │ ├── jest-transpiler-esm.config.ts │ ├── package.json │ ├── src │ │ └── stateful.js │ ├── tsconfig-cjs-transpiler.spec.json │ ├── tsconfig-cjs.spec.json │ ├── tsconfig-esm-transpiler.spec.json │ ├── tsconfig-esm.spec.json │ └── tsconfig.json ├── transformer-in-ts │ ├── __tests__ │ │ └── transformer-in-ts.spec.ts │ ├── jest-compiler-cjs.config.ts │ ├── jest-compiler-esm.config.ts │ ├── jest-transpiler-cjs.config.ts │ ├── jest-transpiler-esm.config.ts │ ├── package.json │ ├── tsconfig-cjs-transpiler.spec.json │ └── tsconfig-esm-transpiler.spec.json ├── transformer-options │ ├── __tests__ │ │ └── transformer-options.spec.tsx │ ├── jest-compiler-cjs.config.ts │ ├── jest-compiler-esm.config.ts │ ├── jest-transpiler-cjs.config.ts │ ├── jest-transpiler-esm.config.ts │ ├── package.json │ ├── src │ │ └── App.tsx │ ├── tsconfig-cjs-transpiler.spec.json │ ├── tsconfig-cjs.spec.json │ ├── tsconfig-esm-transpiler.spec.json │ ├── tsconfig-esm.spec.json │ └── tsconfig.json ├── tsconfig-cjs.spec.json ├── tsconfig-esm.spec.json └── tsconfig-js.json ├── eslint.config.mjs ├── examples ├── js-with-babel │ ├── babel.config.js │ ├── jest-esm-isolated.config.ts │ ├── jest-esm.config.ts │ ├── jest-isolated.config.ts │ ├── jest.config.ts │ ├── package.json │ ├── src │ │ ├── welcome-message.spec.ts │ │ ├── welcome-message.ts │ │ └── welcome-person.js │ ├── tsconfig-esm-isolated.json │ ├── tsconfig-esm.json │ ├── tsconfig-isolated.json │ └── tsconfig.json ├── js-with-ts │ ├── jest-esm-isolated.config.ts │ ├── jest-esm.config.ts │ ├── jest-isolated.config.ts │ ├── jest.config.ts │ ├── package.json │ ├── src │ │ ├── welcome-message.spec.ts │ │ └── welcome-message.ts │ ├── tsconfig-esm-isolated.json │ ├── tsconfig-esm.json │ ├── tsconfig-isolated.json │ └── tsconfig.json ├── monorepo-app │ ├── jest-esm-isolated.config.ts │ ├── jest-esm.config.ts │ ├── jest-isolated.config.ts │ ├── jest.config.ts │ ├── package.json │ ├── shared │ │ ├── package.json │ │ ├── src │ │ │ ├── async-welcome-message.ts │ │ │ ├── default-welcome-message.ts │ │ │ └── welcome-message.ts │ │ └── tsconfig.json │ ├── tsconfig.base.json │ ├── tsconfig.json │ ├── type-commonjs │ │ ├── jest-esm-isolated.config.ts │ │ ├── jest-esm.config.ts │ │ ├── jest-isolated.config.ts │ │ ├── jest.config.ts │ │ ├── package.json │ │ ├── test │ │ │ └── welcome-message.spec.ts │ │ ├── tsconfig-esm-isolated.json │ │ ├── tsconfig-esm.json │ │ ├── tsconfig-isolated.json │ │ └── tsconfig.json │ └── type-module │ │ ├── jest-esm-isolated.config.ts │ │ ├── jest-esm.config.ts │ │ ├── jest-isolated.config.ts │ │ ├── jest.config.ts │ │ ├── package.json │ │ ├── test │ │ └── welcome-message.spec.ts │ │ ├── tsconfig-esm-isolated.json │ │ ├── tsconfig-esm.json │ │ ├── tsconfig-isolated.json │ │ └── tsconfig.json ├── package-lock.json ├── package.json ├── react-app │ ├── .gitignore │ ├── README.md │ ├── config │ │ └── jest │ │ │ ├── cssTransform.js │ │ │ └── fileTransform.js │ ├── index.html │ ├── jest-esm-isolated.config.ts │ ├── jest-esm.config.ts │ ├── jest-isolated.config.ts │ ├── jest.config.ts │ ├── package.json │ ├── public │ │ └── vite.svg │ ├── src │ │ ├── App.css │ │ ├── App.test.tsx │ │ ├── App.tsx │ │ ├── assets │ │ │ └── react.svg │ │ ├── index.css │ │ ├── main.tsx │ │ ├── setupTests.ts │ │ └── vite-env.d.ts │ ├── tsconfig-esm-isolated.spec.json │ ├── tsconfig-esm.spec.json │ ├── tsconfig-isolated.spec.json │ ├── tsconfig.json │ ├── tsconfig.node.json │ ├── tsconfig.spec.json │ └── vite.config.ts ├── ts-only │ ├── jest-esm-isolated.config.ts │ ├── jest-esm.config.ts │ ├── jest-isolated.config.ts │ ├── jest.config.ts │ ├── package.json │ ├── src │ │ ├── welcome-message.spec.ts │ │ └── welcome-message.ts │ ├── tsconfig-esm-isolated.json │ ├── tsconfig-esm.json │ ├── tsconfig-isolated.json │ └── tsconfig.json └── tsconfig-base.spec.json ├── icon.png ├── jest-e2e-cjs.config.ts ├── jest-e2e-esm.config.ts ├── jest-preset.js ├── jest.config.ts ├── legacy.js ├── package-lock.json ├── package.json ├── preprocessor.js ├── presets ├── default-esm-legacy │ └── jest-preset.js ├── default-esm │ └── jest-preset.js ├── default-legacy │ └── jest-preset.js ├── default │ └── jest-preset.js ├── index.d.ts ├── index.js ├── js-with-babel-esm-legacy │ └── jest-preset.js ├── js-with-babel-esm │ └── jest-preset.js ├── js-with-babel-legacy │ └── jest-preset.js ├── js-with-babel │ └── jest-preset.js ├── js-with-ts-esm-legacy │ └── jest-preset.js ├── js-with-ts-esm │ └── jest-preset.js ├── js-with-ts-legacy │ └── jest-preset.js └── js-with-ts │ └── jest-preset.js ├── renovate.json ├── scripts ├── create-bundle.js ├── lib │ ├── bundle.js │ ├── logger.js │ └── paths.js ├── post-build.js └── test-examples.js ├── sonar-project.properties ├── src ├── __helpers__ │ ├── dedent-string.ts │ ├── fakers.ts │ ├── mocks.ts │ ├── setup-jest.ts │ └── workspace-root.ts ├── __mocks__ │ ├── .babelrc-foo │ ├── babel-foo.config.cjs │ ├── babel-foo.config.js │ ├── dummy-transformer.js │ ├── empty.ts │ ├── funny-transformer.ts │ ├── hummy-transformer.js │ ├── index.ts │ ├── package-foo.json │ ├── thing.ts │ ├── thing1.ts │ ├── thing2.ts │ └── tsconfig-mocks.json ├── cli │ ├── __snapshots__ │ │ └── cli.spec.ts.snap │ ├── cli.spec.ts │ ├── config │ │ ├── init.ts │ │ └── migrate.ts │ ├── help.ts │ ├── helpers │ │ └── presets.ts │ └── index.ts ├── config │ ├── __snapshots__ │ │ └── paths-to-module-name-mapper.spec.ts.snap │ ├── index.ts │ ├── paths-to-module-name-mapper.spec.ts │ ├── paths-to-module-name-mapper.ts │ └── types.ts ├── constants.ts ├── index.spec.ts ├── index.ts ├── legacy │ ├── __snapshots__ │ │ └── ts-jest-transformer.spec.ts.snap │ ├── compiler │ │ ├── __snapshots__ │ │ │ └── ts-compiler.spec.ts.snap │ │ ├── compiler-utils.ts │ │ ├── index.ts │ │ ├── ts-compiler.spec.ts │ │ ├── ts-compiler.ts │ │ ├── ts-jest-compiler.spec.ts │ │ └── ts-jest-compiler.ts │ ├── config │ │ ├── __snapshots__ │ │ │ └── config-set.spec.ts.snap │ │ ├── config-set.spec.ts │ │ └── config-set.ts │ ├── index.ts │ ├── ts-jest-transformer.spec.ts │ └── ts-jest-transformer.ts ├── presets │ ├── __snapshots__ │ │ └── create-jest-preset.spec.ts.snap │ ├── all-presets.ts │ ├── create-jest-preset.spec.ts │ └── create-jest-preset.ts ├── raw-compiler-options.ts ├── transformers │ ├── README.md │ ├── __snapshots__ │ │ └── hoist-jest.spec.ts.snap │ ├── hoist-jest.spec.ts │ └── hoist-jest.ts ├── transpilers │ └── typescript │ │ ├── transpile-module.spec.ts │ │ └── transpile-module.ts ├── types.ts └── utils │ ├── __mocks__ │ └── logger.ts │ ├── __snapshots__ │ └── backports.spec.ts.snap │ ├── backports.spec.ts │ ├── backports.ts │ ├── get-package-version.spec.ts │ ├── get-package-version.ts │ ├── importer.spec.ts │ ├── importer.ts │ ├── index.ts │ ├── json.spec.ts │ ├── json.ts │ ├── jsonable-value.spec.ts │ ├── jsonable-value.ts │ ├── logger.spec.ts │ ├── logger.ts │ ├── memoize.spec.ts │ ├── memoize.ts │ ├── messages.spec.ts │ ├── messages.ts │ ├── normalize-slashes.spec.ts │ ├── normalize-slashes.ts │ ├── sha1.spec.ts │ ├── sha1.ts │ └── ts-error.ts ├── tsconfig.base.json ├── tsconfig.build.json ├── tsconfig.eslint.json ├── tsconfig.json └── website ├── .gitignore ├── README.md ├── docs ├── babel7-or-ts.md ├── contributing.md ├── debugging.md ├── getting-started │ ├── installation.md │ ├── options.md │ ├── options │ │ ├── astTransformers.md │ │ ├── babelConfig.md │ │ ├── compiler.md │ │ ├── diagnostics.md │ │ ├── isolatedModules.md │ │ ├── stringifyContentPathRegex.md │ │ ├── tsconfig.md │ │ └── useESM.md │ ├── paths-mapping.md │ ├── presets.md │ └── version-checking.md ├── guides │ ├── esm-support.md │ ├── hybrid-node-module.md │ ├── mock-es6-class.md │ ├── react-native.md │ ├── troubleshooting.md │ └── using-with-monorepo.md ├── introduction.md ├── migration.md └── processing.md ├── docusaurus.config.ts ├── package-lock.json ├── package.json ├── sidebars.js ├── src ├── css │ └── custom.css └── pages │ ├── index.tsx │ ├── styles.module.css │ └── versions.tsx ├── static ├── .nojekyll ├── img │ ├── discord.svg │ ├── documentation.png │ ├── github.png │ ├── logo.png │ ├── logo.svg │ ├── pull-request.png │ └── troubleshooting.png └── manifest.json ├── tsconfig.json ├── versioned_docs ├── version-26.5 │ ├── babel7-or-ts.md │ ├── contributing.md │ ├── debugging.md │ ├── getting-started │ │ ├── installation.md │ │ ├── options.md │ │ ├── options │ │ │ ├── astTransformers.md │ │ │ ├── babelConfig.md │ │ │ ├── compiler.md │ │ │ ├── diagnostics.md │ │ │ ├── isolatedModules.md │ │ │ ├── stringifyContentPathRegex.md │ │ │ └── tsconfig.md │ │ ├── paths-mapping.md │ │ ├── presets.md │ │ └── version-checking.md │ ├── guides │ │ ├── esm-support.md │ │ ├── mock-es6-class.md │ │ ├── react-native.md │ │ ├── test-helpers.md │ │ ├── troubleshooting.md │ │ └── using-with-monorepo.md │ ├── introduction.md │ ├── migration.md │ └── processing.md ├── version-27.0 │ ├── babel7-or-ts.md │ ├── contributing.md │ ├── debugging.md │ ├── getting-started │ │ ├── installation.md │ │ ├── options.md │ │ ├── options │ │ │ ├── astTransformers.md │ │ │ ├── babelConfig.md │ │ │ ├── compiler.md │ │ │ ├── diagnostics.md │ │ │ ├── isolatedModules.md │ │ │ ├── stringifyContentPathRegex.md │ │ │ ├── tsconfig.md │ │ │ └── useESM.md │ │ ├── paths-mapping.md │ │ ├── presets.md │ │ └── version-checking.md │ ├── guides │ │ ├── esm-support.md │ │ ├── mock-es6-class.md │ │ ├── react-native.md │ │ ├── test-helpers.md │ │ ├── troubleshooting.md │ │ └── using-with-monorepo.md │ ├── introduction.md │ ├── migration.md │ └── processing.md ├── version-27.1 │ ├── babel7-or-ts.md │ ├── contributing.md │ ├── debugging.md │ ├── getting-started │ │ ├── installation.md │ │ ├── options.md │ │ ├── options │ │ │ ├── astTransformers.md │ │ │ ├── babelConfig.md │ │ │ ├── compiler.md │ │ │ ├── diagnostics.md │ │ │ ├── isolatedModules.md │ │ │ ├── stringifyContentPathRegex.md │ │ │ ├── tsconfig.md │ │ │ └── useESM.md │ │ ├── paths-mapping.md │ │ ├── presets.md │ │ └── version-checking.md │ ├── guides │ │ ├── esm-support.md │ │ ├── mock-es6-class.md │ │ ├── react-native.md │ │ ├── test-helpers.md │ │ ├── troubleshooting.md │ │ └── using-with-monorepo.md │ ├── introduction.md │ ├── migration.md │ └── processing.md ├── version-28.0 │ ├── babel7-or-ts.md │ ├── contributing.md │ ├── debugging.md │ ├── getting-started │ │ ├── installation.md │ │ ├── options.md │ │ ├── options │ │ │ ├── astTransformers.md │ │ │ ├── babelConfig.md │ │ │ ├── compiler.md │ │ │ ├── diagnostics.md │ │ │ ├── isolatedModules.md │ │ │ ├── stringifyContentPathRegex.md │ │ │ ├── tsconfig.md │ │ │ └── useESM.md │ │ ├── paths-mapping.md │ │ ├── presets.md │ │ └── version-checking.md │ ├── guides │ │ ├── esm-support.md │ │ ├── mock-es6-class.md │ │ ├── react-native.md │ │ ├── troubleshooting.md │ │ └── using-with-monorepo.md │ ├── introduction.md │ ├── migration.md │ └── processing.md ├── version-29.0 │ ├── babel7-or-ts.md │ ├── contributing.md │ ├── debugging.md │ ├── getting-started │ │ ├── installation.md │ │ ├── options.md │ │ ├── options │ │ │ ├── astTransformers.md │ │ │ ├── babelConfig.md │ │ │ ├── compiler.md │ │ │ ├── diagnostics.md │ │ │ ├── isolatedModules.md │ │ │ ├── stringifyContentPathRegex.md │ │ │ ├── tsconfig.md │ │ │ └── useESM.md │ │ ├── paths-mapping.md │ │ ├── presets.md │ │ └── version-checking.md │ ├── guides │ │ ├── esm-support.md │ │ ├── mock-es6-class.md │ │ ├── react-native.md │ │ ├── troubleshooting.md │ │ └── using-with-monorepo.md │ ├── introduction.md │ ├── migration.md │ └── processing.md ├── version-29.2 │ ├── babel7-or-ts.md │ ├── contributing.md │ ├── debugging.md │ ├── getting-started │ │ ├── installation.md │ │ ├── options.md │ │ ├── options │ │ │ ├── astTransformers.md │ │ │ ├── babelConfig.md │ │ │ ├── compiler.md │ │ │ ├── diagnostics.md │ │ │ ├── isolatedModules.md │ │ │ ├── stringifyContentPathRegex.md │ │ │ ├── tsconfig.md │ │ │ └── useESM.md │ │ ├── paths-mapping.md │ │ ├── presets.md │ │ └── version-checking.md │ ├── guides │ │ ├── esm-support.md │ │ ├── mock-es6-class.md │ │ ├── react-native.md │ │ ├── troubleshooting.md │ │ └── using-with-monorepo.md │ ├── introduction.md │ ├── migration.md │ └── processing.md └── version-29.3 │ ├── babel7-or-ts.md │ ├── contributing.md │ ├── debugging.md │ ├── getting-started │ ├── installation.md │ ├── options.md │ ├── options │ │ ├── astTransformers.md │ │ ├── babelConfig.md │ │ ├── compiler.md │ │ ├── diagnostics.md │ │ ├── isolatedModules.md │ │ ├── stringifyContentPathRegex.md │ │ ├── tsconfig.md │ │ └── useESM.md │ ├── paths-mapping.md │ ├── presets.md │ └── version-checking.md │ ├── guides │ ├── esm-support.md │ ├── hybrid-node-module.md │ ├── mock-es6-class.md │ ├── react-native.md │ ├── troubleshooting.md │ └── using-with-monorepo.md │ ├── introduction.md │ ├── migration.md │ └── processing.md ├── versioned_sidebars ├── version-26.5-sidebars.json ├── version-27.0-sidebars.json ├── version-27.1-sidebars.json ├── version-28.0-sidebars.json ├── version-29.0-sidebars.json ├── version-29.2-sidebars.json └── version-29.3-sidebars.json └── versions.json /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | root = true 3 | indent_style = space 4 | indent_size = 2 5 | charset = utf-8 6 | end_of_line = lf 7 | insert_final_newline = true 8 | trim_trailing_whitespace = true 9 | 10 | [*.md] 11 | trim_trailing_whitespace = false 12 | 13 | [*.snap] 14 | trim_trailing_whitespace = false 15 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | package-lock.json -diff -merge 2 | package-lock.json linguist-generated=true 3 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # These owners will be the default owners for everything in 2 | # the repo. Unless a later match takes precedence, 3 | # @global-owner1 and @global-owner2 will be requested for 4 | # review when someone opens a pull request. 5 | * @kulshekhar 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature.yml: -------------------------------------------------------------------------------- 1 | name: Feature Proposal 🚀 2 | description: Submit a proposal for a new feature 3 | title: '[Feature]: ' 4 | labels: ['🚀 Feature Request'] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | ### Thank you for taking the time to suggest a new feature! 10 | - type: textarea 11 | id: description 12 | attributes: 13 | label: '🚀 Feature Proposal' 14 | description: A clear and concise description of what the feature is. 15 | validations: 16 | required: true 17 | - type: textarea 18 | id: solution 19 | attributes: 20 | label: Motivation 21 | description: Outline your motivation for the proposal. How will it make `ts-jest` better? 22 | validations: 23 | required: true 24 | - type: textarea 25 | id: alternatives 26 | attributes: 27 | label: Example 28 | description: Describe how this feature would be used. 29 | validations: 30 | required: false 31 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.yml: -------------------------------------------------------------------------------- 1 | name: 'Questions / Help 💬' 2 | description: If you have questions, please check Reactiflux or StackOverflow 3 | title: '[Please read the message below]' 4 | labels: ['💬 Question'] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | ## Questions and Help 💬 10 | 11 | This issue tracker is reserved for bug reports and feature proposals. 12 | 13 | For anything else, such as questions or getting help, please see: 14 | 15 | - [The Jest help page](https://jestjs.io/help) 16 | - Our [online documentation](https://kulshekhar.github.io/ts-jest) 17 | - Our [discussion](https://github.com/kulshekhar/ts-jest/discussions) 18 | - [Jest `#testing` channel in Reactiflux](https://discord.gg/j6FKKQQrW9) 19 | - The [jestjs](https://stackoverflow.com/questions/tagged/jestjs) tag on [StackOverflow](https://stackoverflow.com/questions/ask) 20 | - The [ts-jest](https://stackoverflow.com/questions/tagged/ts-jest) tag on [StackOverflow](https://stackoverflow.com/questions/ask) 21 | - type: checkboxes 22 | id: no-post 23 | attributes: 24 | label: | 25 | Please do not submit this issue. 26 | description: | 27 | :bangbang:   This issue will be closed. :bangbang: 28 | options: 29 | - label: I understand 30 | required: true 31 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Summary 4 | 5 | 6 | 7 | ## Test plan 8 | 9 | 10 | 11 | ## Does this PR introduce a breaking change? 12 | 13 | - [ ] Yes 14 | - [ ] No 15 | 16 | 17 | 18 | ## Other information 19 | -------------------------------------------------------------------------------- /.github/SUPPORT.md: -------------------------------------------------------------------------------- 1 | Please note this issue tracker is not a help forum. We recommend using [StackOverflow](https://stackoverflow.com/questions/tagged/ts-jest) or our [Slack channel](https://bit.ly/3bRHFPQ) for questions. 2 | -------------------------------------------------------------------------------- /.github/actions/setup-workspace/action.yml: -------------------------------------------------------------------------------- 1 | name: Setup workspace 2 | 3 | inputs: 4 | os: 5 | required: true 6 | type: string 7 | node-version: 8 | required: true 9 | type: string 10 | 11 | permissions: # added using https://github.com/step-security/secure-workflows 12 | contents: read 13 | 14 | runs: 15 | using: composite 16 | steps: 17 | - name: Restore cached node modules ♻️ 18 | id: cache-npm 19 | uses: actions/cache@v4 20 | with: 21 | path: '**/node_modules' 22 | key: ${{ inputs.os }}-${{ inputs.node }}-build-${{ hashFiles('**/package-lock.json') }} 23 | 24 | - name: Setup Node version ⚙️ 25 | uses: actions/setup-node@v4 26 | if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }} 27 | with: 28 | cache: npm 29 | cache-dependency-path: '**/package-lock.json' 30 | node-version: ${{ inputs.node }} 31 | 32 | - name: Install and build 🔧 33 | if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }} 34 | run: npm ci --prefer-offline 35 | shell: bash 36 | -------------------------------------------------------------------------------- /.github/workflows/prepare-cache.yml: -------------------------------------------------------------------------------- 1 | name: Prepare CI cache 2 | 3 | on: 4 | workflow_call: 5 | inputs: 6 | os: 7 | required: true 8 | type: string 9 | node-version: 10 | required: true 11 | type: string 12 | 13 | permissions: # added using https://github.com/step-security/secure-workflows 14 | contents: read 15 | 16 | jobs: 17 | prepare-npm-cache: 18 | name: Prepare npm cache for Node v${{ inputs.node-version }} on ${{ inputs.os }} 19 | runs-on: ${{ inputs.os }} 20 | 21 | steps: 22 | - name: Checkout 🛎️ 23 | uses: actions/checkout@v4 24 | with: 25 | fetch-depth: 20 26 | fetch-tags: false 27 | 28 | - name: Setup workspace ⚙️ 29 | uses: ./.github/actions/setup-workspace 30 | with: 31 | os: ${{ inputs.os }} 32 | node-version: ${{ inputs.node-version }} 33 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | workflow_call: 5 | inputs: 6 | os: 7 | required: true 8 | type: string 9 | node-version: 10 | required: true 11 | type: string 12 | 13 | permissions: # added using https://github.com/step-security/secure-workflows 14 | contents: read 15 | 16 | jobs: 17 | test: 18 | permissions: 19 | checks: write 20 | contents: read 21 | name: Run tests on Node v${{ inputs.node-version }} on ${{ inputs.os }} 22 | runs-on: ${{ inputs.os }} 23 | 24 | steps: 25 | - name: Checkout 🛎️ 26 | uses: actions/checkout@v4 27 | with: 28 | fetch-depth: 20 29 | fetch-tags: false 30 | 31 | - name: Setup workspace ⚙️ 32 | uses: ./.github/actions/setup-workspace 33 | with: 34 | os: ${{ inputs.os }} 35 | node-version: ${{ inputs.node-version }} 36 | 37 | - name: Build 🔧 38 | run: npm run build 39 | 40 | - name: Run tests 🧪 41 | run: npm run test 42 | env: 43 | CI: true 44 | DISABLE_MOCKED_WARNING: true 45 | 46 | - name: Run e2e tests 🧪 47 | run: | 48 | npm run test-e2e-cjs 49 | npm run test-e2e-esm 50 | 51 | - name: Run tests in example projects 🧪 52 | run: npm run test-examples 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | 3 | # Logs 4 | logs 5 | *.log 6 | npm-debug.log* 7 | 8 | # nodist config for testing in different versions of node 9 | .node-version 10 | 11 | # Runtime data 12 | pids 13 | *.pid 14 | *.seed 15 | 16 | # Directory for instrumented libs generated by jscoverage/JSCover 17 | lib-cov 18 | 19 | # Coverage directory used by tools like istanbul 20 | coverage 21 | 22 | # nyc test coverage 23 | .nyc_output 24 | 25 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 26 | .grunt 27 | 28 | # node-waf configuration 29 | .lock-wscript 30 | 31 | # Compiled binary addons (http://nodejs.org/api/addons.html) 32 | build/Release 33 | 34 | # Dependency directories 35 | node_modules 36 | jspm_packages 37 | 38 | # Optional npm cache directory 39 | .npm 40 | 41 | # Optional REPL history 42 | .node_repl_history 43 | 44 | .vscode 45 | .idea 46 | .cache 47 | 48 | # is linked to the temp dir of the os 49 | .ts-jest-digest 50 | 51 | # binaries 52 | *.tgz 53 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | commitlint --edit $1 2 | -------------------------------------------------------------------------------- /.husky/post-commit: -------------------------------------------------------------------------------- 1 | git reset 2 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | lint-staged 2 | -------------------------------------------------------------------------------- /.lintstagedrc: -------------------------------------------------------------------------------- 1 | { 2 | "*.{js,cjs,mjs,jsx,ts,tsx}": ["eslint --fix"], 3 | "*.{yml,yaml,md}": ["prettier --write"] 4 | } 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Tests 2 | e2e 3 | examples 4 | 5 | # sources are inlined 6 | src 7 | 8 | # Github Pages 9 | website 10 | 11 | # Developement scripts 12 | scripts 13 | 14 | # .config file 15 | *.config.js 16 | *.config.cjs 17 | *.config.mjs 18 | *.config.ts 19 | *.config.cts 20 | *.config.mts 21 | *.properties 22 | 23 | # CI 24 | .github 25 | 26 | # Eslint 27 | .eslintignore 28 | .eslintrc.js 29 | .prettierignore 30 | .prettierrc 31 | 32 | # Tsconfig 33 | tsconfig.build.json 34 | tsconfig.eslint.json 35 | tsconfig.json 36 | 37 | # Logs 38 | logs 39 | *.log 40 | npm-debug.log* 41 | 42 | # Coverage directory used by tools like istanbul 43 | coverage 44 | 45 | # Dependency directories 46 | node_modules 47 | 48 | # Optional npm cache directory 49 | .npm 50 | 51 | # others 52 | *.tgz 53 | .editorconfig 54 | .npmignore 55 | .npmrc 56 | .vscode 57 | .cache 58 | .gitattributes 59 | .gitignore 60 | icon.png 61 | .idea 62 | .husky 63 | renovate.json 64 | 65 | # ensure we do not omit the digest 66 | !.ts-jest-digest 67 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | tag-version-prefix="v" 2 | message="chore(release): %s" 3 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | node_modules/ 3 | src/**/__snapshots__/ 4 | e2e/__tests__/__snapshots__/ 5 | CHANGELOG.md 6 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | semi: false 2 | printWidth: 120 3 | singleQuote: true 4 | tabWidth: 2 5 | useTabs: false 6 | trailingComma: all 7 | overrides: 8 | - files: "**/*.js" 9 | options: 10 | trailingComma: es5 11 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016-2025 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /TROUBLESHOOTING.md: -------------------------------------------------------------------------------- 1 | # Troubleshooting 2 | 3 | Troubleshooting guide have been moved to https://kulshekhar.github.io/ts-jest/docs/guides/troubleshooting 4 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('./dist/cli').processArgv() 4 | -------------------------------------------------------------------------------- /commitlint.config.ts: -------------------------------------------------------------------------------- 1 | import type { UserConfig } from '@commitlint/types' 2 | 3 | export default { 4 | extends: ['@commitlint/config-angular'], 5 | rules: { 6 | 'subject-max-length': [2, 'always', 120], 7 | 'scope-enum': [2, 'always', []], 8 | 'scope-empty': [2, 'always'], 9 | 'type-enum': [ 10 | 2, 11 | 'always', 12 | ['build', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'release', 'revert', 'style', 'test'], 13 | ], 14 | }, 15 | } satisfies UserConfig 16 | -------------------------------------------------------------------------------- /e2e/const-enum/__tests__/const-enum.spec.ts: -------------------------------------------------------------------------------- 1 | import { BarConstEnum } from '../src/bar-constant' 2 | import { FooConstEnum } from '../src/foo-constant' 3 | 4 | const getOne = (): string => BarConstEnum.one 5 | const getTwo = (): string => FooConstEnum.two 6 | 7 | describe('const-enum', () => { 8 | it('should pass', () => { 9 | expect(getOne()).toBe('ONE') 10 | expect(getTwo()).toBe('TWO') 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /e2e/const-enum/jest-compiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'const-enum-compiler-cjs', 5 | transform: { 6 | [TS_JS_TRANSFORM_PATTERN]: [ 7 | 'ts-jest', 8 | { 9 | tsconfig: '/tsconfig-cjs.spec.json', 10 | }, 11 | ], 12 | }, 13 | } satisfies JestConfigWithTsJest 14 | -------------------------------------------------------------------------------- /e2e/const-enum/jest-compiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'const-enum-compiler-esm', 5 | extensionsToTreatAsEsm: ['.ts'], 6 | transform: { 7 | [TS_JS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/tsconfig-esm.spec.json', 11 | useESM: true, 12 | }, 13 | ], 14 | }, 15 | } satisfies JestConfigWithTsJest 16 | -------------------------------------------------------------------------------- /e2e/const-enum/jest-transpiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'const-enum-transpiler-cjs', 5 | transform: { 6 | [TS_JS_TRANSFORM_PATTERN]: [ 7 | 'ts-jest', 8 | { 9 | tsconfig: '/tsconfig-cjs-transpiler.spec.json', 10 | }, 11 | ], 12 | }, 13 | } satisfies JestConfigWithTsJest 14 | -------------------------------------------------------------------------------- /e2e/const-enum/jest-transpiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'const-enum-transpiler-esm', 5 | extensionsToTreatAsEsm: ['.ts'], 6 | transform: { 7 | [TS_JS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/tsconfig-esm-transpiler.spec.json', 11 | useESM: true, 12 | }, 13 | ], 14 | }, 15 | } satisfies JestConfigWithTsJest 16 | -------------------------------------------------------------------------------- /e2e/const-enum/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "const-enum", 3 | "private": true 4 | } 5 | -------------------------------------------------------------------------------- /e2e/const-enum/src/bar-constant.ts: -------------------------------------------------------------------------------- 1 | export const enum BarConstEnum { 2 | one = 'ONE', 3 | } 4 | -------------------------------------------------------------------------------- /e2e/const-enum/src/foo-constant.d.ts: -------------------------------------------------------------------------------- 1 | export declare const enum FooConstEnum { 2 | two = 'TWO', 3 | } 4 | -------------------------------------------------------------------------------- /e2e/const-enum/src/foo-constant.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | var FooConstEnum 3 | ;(function (FooConstEnum) { 4 | FooConstEnum[(FooConstEnum['two'] = 'TWO')] = 'two' 5 | 6 | })((FooConstEnum = exports.FooConstEnum || (exports.FooConstEnum = {}))) 7 | -------------------------------------------------------------------------------- /e2e/const-enum/tsconfig-cjs-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-cjs.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true, 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/const-enum/tsconfig-cjs.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "../tsconfig-js.json", 4 | "../tsconfig-cjs.spec.json" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /e2e/const-enum/tsconfig-esm-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-esm.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true, 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/const-enum/tsconfig-esm.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "../tsconfig-js.json", 4 | "../tsconfig-esm.spec.json" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /e2e/enum/__tests__/enum.spec.ts: -------------------------------------------------------------------------------- 1 | import { BarEnum } from '../src/bar-constant' 2 | 3 | const getOne = (): string => BarEnum.one 4 | 5 | describe('enum', () => { 6 | it('should pass', () => { 7 | expect(getOne()).toBe('ONE') 8 | }) 9 | }) 10 | -------------------------------------------------------------------------------- /e2e/enum/jest-compiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, ESM_TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'enum-compiler-cjs', 5 | transform: { 6 | [ESM_TS_JS_TRANSFORM_PATTERN]: [ 7 | 'ts-jest', 8 | { 9 | tsconfig: '/tsconfig-cjs.spec.json', 10 | }, 11 | ], 12 | }, 13 | } satisfies JestConfigWithTsJest 14 | -------------------------------------------------------------------------------- /e2e/enum/jest-compiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'enum-compiler-esm', 5 | extensionsToTreatAsEsm: ['.ts'], 6 | transform: { 7 | [TS_JS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/tsconfig-esm.spec.json', 11 | useESM: true, 12 | }, 13 | ], 14 | }, 15 | } satisfies JestConfigWithTsJest 16 | -------------------------------------------------------------------------------- /e2e/enum/jest-transpiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, ESM_TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'enum-transpiler-cjs', 5 | transform: { 6 | [ESM_TS_JS_TRANSFORM_PATTERN]: [ 7 | 'ts-jest', 8 | { 9 | tsconfig: '/tsconfig-cjs-transpiler.spec.json', 10 | }, 11 | ], 12 | }, 13 | } satisfies JestConfigWithTsJest 14 | -------------------------------------------------------------------------------- /e2e/enum/jest-transpiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'enum-transpiler-esm', 5 | extensionsToTreatAsEsm: ['.ts'], 6 | transform: { 7 | [TS_JS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/tsconfig-esm-transpiler.spec.json', 11 | useESM: true, 12 | }, 13 | ], 14 | }, 15 | } satisfies JestConfigWithTsJest 16 | -------------------------------------------------------------------------------- /e2e/enum/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "enum", 3 | "private": true 4 | } 5 | -------------------------------------------------------------------------------- /e2e/enum/src/bar-constant.ts: -------------------------------------------------------------------------------- 1 | export enum BarEnum { 2 | one = 'ONE', 3 | } 4 | -------------------------------------------------------------------------------- /e2e/enum/tsconfig-cjs-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-cjs.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/enum/tsconfig-cjs.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "../tsconfig-js.json", 4 | "../tsconfig-cjs.spec.json" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /e2e/enum/tsconfig-esm-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-esm.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/enum/tsconfig-esm.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "../tsconfig-js.json", 4 | "../tsconfig-esm.spec.json" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /e2e/esm-features/__tests__/esm-features.spec.ts: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line prettier/prettier 2 | import jsonImportAssertion from '../src/foo.json' with { type: 'json' } 3 | 4 | const topLevelAwait = await import('../src/foo.json') 5 | 6 | const itWithRunNode18Above = (...args: Parameters) => { 7 | const [major] = process.versions.node.split('.').map(Number) 8 | if (major > 16) { 9 | // eslint-disable-next-line jest/valid-title,jest/expect-expect,jest/no-disabled-tests 10 | return it(...args) 11 | } 12 | 13 | // eslint-disable-next-line jest/valid-title,jest/expect-expect,jest/no-disabled-tests 14 | return it.skip(...args) 15 | } 16 | 17 | describe('esm-features', () => { 18 | it('should work with import.meta', () => { 19 | expect(import.meta.jest).toBeDefined() 20 | }) 21 | 22 | it('should work with import assertion', () => { 23 | expect(jsonImportAssertion.name).toBe('hello') 24 | }) 25 | 26 | itWithRunNode18Above('should work with import attributes', async () => { 27 | const jsonImportAttrs = await import('../src/foo.json', { with: { type: 'json' } }) 28 | // eslint-disable-next-line jest/no-standalone-expect 29 | expect(jsonImportAttrs.default.name).toBe('hello') 30 | }) 31 | 32 | it('should work with top-level await', () => { 33 | expect(topLevelAwait.default.name).toBe('hello') 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /e2e/esm-features/jest-compiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'esm-features-compiler-esm', 5 | extensionsToTreatAsEsm: ['.ts'], 6 | transform: { 7 | [TS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/tsconfig-esm-transpiler.spec.json', 11 | useESM: true, 12 | }, 13 | ], 14 | }, 15 | } satisfies JestConfigWithTsJest 16 | -------------------------------------------------------------------------------- /e2e/esm-features/jest-transpiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'esm-features-transpiler-esm', 5 | extensionsToTreatAsEsm: ['.ts'], 6 | transform: { 7 | [TS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/tsconfig-esm-transpiler.spec.json', 11 | useESM: true, 12 | }, 13 | ], 14 | }, 15 | } satisfies JestConfigWithTsJest 16 | -------------------------------------------------------------------------------- /e2e/esm-features/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "esm-features", 3 | "private": true 4 | } 5 | -------------------------------------------------------------------------------- /e2e/esm-features/src/foo.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hello" 3 | } 4 | -------------------------------------------------------------------------------- /e2e/esm-features/tsconfig-esm-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-esm.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/esm-features/tsconfig-esm.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json" 3 | } 4 | -------------------------------------------------------------------------------- /e2e/esm-features/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig-esm.spec.json" 3 | } 4 | -------------------------------------------------------------------------------- /e2e/extend-ts-jest/__tests__/extend-ts-jest.spec.ts: -------------------------------------------------------------------------------- 1 | describe('extend-ts-jest', () => { 2 | it('should pass', () => { 3 | expect(true).toBe(true) 4 | }) 5 | }) 6 | -------------------------------------------------------------------------------- /e2e/extend-ts-jest/jest-compiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'extend-ts-jest-compiler-cjs', 5 | transform: { 6 | [TS_JS_TRANSFORM_PATTERN]: [ 7 | 'ts-jest', 8 | { 9 | tsconfig: '/tsconfig-cjs.spec.json', 10 | }, 11 | ], 12 | }, 13 | } satisfies JestConfigWithTsJest 14 | -------------------------------------------------------------------------------- /e2e/extend-ts-jest/jest-compiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'extend-ts-jest-compiler-esm', 5 | extensionsToTreatAsEsm: ['.ts'], 6 | transform: { 7 | [TS_JS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/tsconfig-esm.spec.json', 11 | useESM: true, 12 | }, 13 | ], 14 | }, 15 | } satisfies JestConfigWithTsJest 16 | -------------------------------------------------------------------------------- /e2e/extend-ts-jest/jest-transpiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'extend-ts-jest-transpiler-cjs', 5 | transform: { 6 | [TS_JS_TRANSFORM_PATTERN]: [ 7 | 'ts-jest', 8 | { 9 | tsconfig: '/tsconfig-cjs-transpiler.spec.json', 10 | }, 11 | ], 12 | }, 13 | } satisfies JestConfigWithTsJest 14 | -------------------------------------------------------------------------------- /e2e/extend-ts-jest/jest-transpiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'extend-ts-jest-transpiler-esm', 5 | extensionsToTreatAsEsm: ['.ts'], 6 | transform: { 7 | [TS_JS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/tsconfig-esm-transpiler.spec.json', 11 | useESM: true, 12 | }, 13 | ], 14 | }, 15 | } satisfies JestConfigWithTsJest 16 | -------------------------------------------------------------------------------- /e2e/extend-ts-jest/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "extend-ts-jest", 3 | "private": true 4 | } 5 | -------------------------------------------------------------------------------- /e2e/extend-ts-jest/src/foo-transformer.js: -------------------------------------------------------------------------------- 1 | const tsJestTransformer = require('ts-jest') 2 | 3 | class FooTransformer extends tsJestTransformer.TsJestTransformer { 4 | async processAsync(sourceText, sourcePath, transformOptions) { 5 | return Promise.resolve(this.process(sourceText, sourcePath, transformOptions)) 6 | } 7 | } 8 | 9 | module.exports = { 10 | createTransformer: () => new FooTransformer(), 11 | } 12 | -------------------------------------------------------------------------------- /e2e/extend-ts-jest/tsconfig-cjs-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-cjs.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/extend-ts-jest/tsconfig-cjs.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "../tsconfig-js.json", 4 | "../tsconfig-cjs.spec.json" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /e2e/extend-ts-jest/tsconfig-esm-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-esm.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/extend-ts-jest/tsconfig-esm.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "../tsconfig-js.json", 4 | "../tsconfig-esm.spec.json" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /e2e/hoist-jest/__tests__/hoist-import-jest.spec.ts: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line import/no-duplicates 2 | import { jest } from '@jest/globals' 3 | // eslint-disable-next-line import/no-duplicates 4 | import { jest as aliasedJest } from '@jest/globals' 5 | import * as JestGlobals from '@jest/globals' 6 | 7 | import a from '../src/a' 8 | import b from '../src/b' 9 | import c from '../src/c' 10 | 11 | jest.unmock('../src/a') 12 | aliasedJest.unmock('../src/b') 13 | JestGlobals.jest.unmock('../src/c') 14 | 15 | describe('hoist-import-jest', () => { 16 | it('should work with named import', () => { 17 | // @ts-expect-error `_isMockFunction` is a hidden property 18 | expect(a._isMockFunction).toBeUndefined() 19 | expect(a()).toBe('unmocked') 20 | }) 21 | 22 | it('should work with aliased named import', () => { 23 | // @ts-expect-error `_isMockFunction` is a hidden property 24 | expect(b._isMockFunction).toBeUndefined() 25 | expect(b()).toBe('unmocked') 26 | }) 27 | 28 | it('should work with namespace import', () => { 29 | // @ts-expect-error `_isMockFunction` is a hidden property 30 | expect(c._isMockFunction).toBeUndefined() 31 | expect(c()).toBe('unmocked') 32 | }) 33 | }) 34 | -------------------------------------------------------------------------------- /e2e/hoist-jest/jest-compiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'hoist-jest-compiler-cjs', 5 | transform: { 6 | [TS_JS_TRANSFORM_PATTERN]: [ 7 | 'ts-jest', 8 | { 9 | tsconfig: '/tsconfig-cjs.spec.json', 10 | }, 11 | ], 12 | }, 13 | } satisfies JestConfigWithTsJest 14 | -------------------------------------------------------------------------------- /e2e/hoist-jest/jest-transpiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'hoist-jest-transpiler-cjs', 5 | transform: { 6 | [TS_JS_TRANSFORM_PATTERN]: [ 7 | 'ts-jest', 8 | { 9 | tsconfig: '/tsconfig-cjs-transpiler.spec.json', 10 | }, 11 | ], 12 | }, 13 | } satisfies JestConfigWithTsJest 14 | -------------------------------------------------------------------------------- /e2e/hoist-jest/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hoist-jest", 3 | "private": true 4 | } 5 | -------------------------------------------------------------------------------- /e2e/hoist-jest/src/a.js: -------------------------------------------------------------------------------- 1 | export default () => 'unmocked' 2 | -------------------------------------------------------------------------------- /e2e/hoist-jest/src/b.js: -------------------------------------------------------------------------------- 1 | export default () => 'unmocked' 2 | -------------------------------------------------------------------------------- /e2e/hoist-jest/src/c.js: -------------------------------------------------------------------------------- 1 | export default () => 'unmocked' 2 | -------------------------------------------------------------------------------- /e2e/hoist-jest/tsconfig-cjs-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-cjs.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/hoist-jest/tsconfig-cjs.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "./tsconfig.json", 4 | "../tsconfig-cjs.spec.json" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /e2e/hoist-jest/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig-js.json" 3 | } 4 | -------------------------------------------------------------------------------- /e2e/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "e2e", 3 | "private": true, 4 | "devDependencies": { 5 | "@formatjs/ts-transformer": "^3.13.34", 6 | "@types/react": "^18.3.3", 7 | "esbuild": "~0.25.5", 8 | "jest-environment-jsdom": "^29.7.0", 9 | "react": "^18.3.1", 10 | "react-intl": "^6.8.9", 11 | "ts-jest": "^29.3.4" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /e2e/presets/jest-compiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'presets-compiler-cjs', 5 | transform: { 6 | [TS_JS_TRANSFORM_PATTERN]: [ 7 | 'ts-jest', 8 | { 9 | tsconfig: '/tsconfig-cjs.spec.json', 10 | }, 11 | ], 12 | }, 13 | } satisfies JestConfigWithTsJest 14 | -------------------------------------------------------------------------------- /e2e/presets/jest-compiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'presets-compiler-esm', 5 | extensionsToTreatAsEsm: ['.ts'], 6 | transform: { 7 | [TS_JS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/tsconfig-esm.spec.json', 11 | useESM: true, 12 | }, 13 | ], 14 | }, 15 | } satisfies JestConfigWithTsJest 16 | -------------------------------------------------------------------------------- /e2e/presets/jest-transpiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'presets-transpiler-cjs', 5 | transform: { 6 | [TS_JS_TRANSFORM_PATTERN]: [ 7 | 'ts-jest', 8 | { 9 | tsconfig: '/tsconfig-cjs-transpiler.spec.json', 10 | }, 11 | ], 12 | }, 13 | } satisfies JestConfigWithTsJest 14 | -------------------------------------------------------------------------------- /e2e/presets/jest-transpiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'presets-transpiler-esm', 5 | extensionsToTreatAsEsm: ['.ts'], 6 | transform: { 7 | [TS_JS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/tsconfig-esm-transpiler.spec.json', 11 | useESM: true, 12 | }, 13 | ], 14 | }, 15 | } satisfies JestConfigWithTsJest 16 | -------------------------------------------------------------------------------- /e2e/presets/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "presets", 3 | "private": true 4 | } 5 | -------------------------------------------------------------------------------- /e2e/presets/tsconfig-cjs-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-cjs.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/presets/tsconfig-cjs.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "../tsconfig-js.json", 4 | "../tsconfig-cjs.spec.json" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /e2e/presets/tsconfig-esm-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-esm.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/presets/tsconfig-esm.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "../tsconfig-js.json", 4 | "../tsconfig-esm.spec.json" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /e2e/source-map/__tests__/__snapshots__/source-map.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`source-map should display failed test with stacktrace 1`] = ` 4 | " ● should fail 5 | 6 | expect(received).toBe(expected) // Object.is equality 7 | 8 | Expected: false 9 | Received: true 10 | 11 | 1 | it('should fail', () => { 12 | > 2 | expect(true).toBe(false) 13 | | ^ 14 | 3 | }) 15 | 4 | 16 | 17 | at Object.toBe (error.test-error.js:2:16) 18 | " 19 | `; 20 | -------------------------------------------------------------------------------- /e2e/source-map/__tests__/source-map.spec.ts: -------------------------------------------------------------------------------- 1 | import { sync as spawnSync } from 'execa' 2 | import stripAnsi from 'strip-ansi' 3 | 4 | describe('source-map', () => { 5 | it('should display failed test with stacktrace', () => { 6 | // Use `--json` flag to ignore differences between OS when creating snapshots 7 | const { stdout } = spawnSync('jest', ['-c=e2e/source-map/src/jest-fake.config.js', '--json'], { 8 | cwd: process.cwd(), 9 | reject: false, 10 | }) 11 | 12 | const message = JSON.parse(stdout || '').testResults[0].message 13 | 14 | expect(stripAnsi(message)).toMatchSnapshot() 15 | }) 16 | }) 17 | -------------------------------------------------------------------------------- /e2e/source-map/jest-compiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'source-map-compiler-cjs', 5 | transform: { 6 | [TS_TRANSFORM_PATTERN]: [ 7 | 'ts-jest', 8 | { 9 | tsconfig: '/../tsconfig-cjs.spec.json', 10 | }, 11 | ], 12 | }, 13 | } satisfies JestConfigWithTsJest 14 | -------------------------------------------------------------------------------- /e2e/source-map/jest-compiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'source-map-compiler-esm', 5 | extensionsToTreatAsEsm: ['.ts'], 6 | transform: { 7 | [TS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/../tsconfig-esm.spec.json', 11 | useESM: true, 12 | }, 13 | ], 14 | }, 15 | } satisfies JestConfigWithTsJest 16 | -------------------------------------------------------------------------------- /e2e/source-map/jest-transpiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'source-map-transpiler-cjs', 5 | transform: { 6 | [TS_TRANSFORM_PATTERN]: [ 7 | 'ts-jest', 8 | { 9 | tsconfig: '/tsconfig-cjs-transpiler.spec.json', 10 | }, 11 | ], 12 | }, 13 | } satisfies JestConfigWithTsJest 14 | -------------------------------------------------------------------------------- /e2e/source-map/jest-transpiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'source-map-transpiler-esm', 5 | extensionsToTreatAsEsm: ['.ts'], 6 | transform: { 7 | [TS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/tsconfig-esm-transpiler.spec.json', 11 | useESM: true, 12 | }, 13 | ], 14 | }, 15 | } satisfies JestConfigWithTsJest 16 | -------------------------------------------------------------------------------- /e2e/source-map/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "source-map", 3 | "private": true 4 | } 5 | -------------------------------------------------------------------------------- /e2e/source-map/src/error.test-error.js: -------------------------------------------------------------------------------- 1 | it('should fail', () => { 2 | expect(true).toBe(false) 3 | }) 4 | -------------------------------------------------------------------------------- /e2e/source-map/src/jest-fake.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testMatch: ['**/*/error.test-error.js'], 3 | } 4 | -------------------------------------------------------------------------------- /e2e/source-map/tsconfig-cjs-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig-cjs.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/source-map/tsconfig-esm-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig-esm.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/test-utils/__tests__/test-utils.spec.ts: -------------------------------------------------------------------------------- 1 | import { pathsToModuleNameMapper } from 'ts-jest' 2 | 3 | describe('test-utils', () => { 4 | it('should expose pathsToModuleNameMapper', () => { 5 | expect(typeof pathsToModuleNameMapper).toBe('function') 6 | }) 7 | }) 8 | -------------------------------------------------------------------------------- /e2e/test-utils/jest-compiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'test-utils-compiler-cjs', 5 | transform: { 6 | [TS_TRANSFORM_PATTERN]: [ 7 | 'ts-jest', 8 | { 9 | tsconfig: '/../tsconfig-cjs.spec.json', 10 | }, 11 | ], 12 | }, 13 | } satisfies JestConfigWithTsJest 14 | -------------------------------------------------------------------------------- /e2e/test-utils/jest-compiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'test-utils-compiler-esm', 5 | extensionsToTreatAsEsm: ['.ts'], 6 | transform: { 7 | [TS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/../tsconfig-esm.spec.json', 11 | useESM: true, 12 | }, 13 | ], 14 | }, 15 | } satisfies JestConfigWithTsJest 16 | -------------------------------------------------------------------------------- /e2e/test-utils/jest-transpiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'test-utils-transpiler-cjs', 5 | transform: { 6 | [TS_TRANSFORM_PATTERN]: [ 7 | 'ts-jest', 8 | { 9 | tsconfig: '/tsconfig-cjs-transpiler.spec.json', 10 | }, 11 | ], 12 | }, 13 | } satisfies JestConfigWithTsJest 14 | -------------------------------------------------------------------------------- /e2e/test-utils/jest-transpiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'test-utils-transpiler-esm', 5 | extensionsToTreatAsEsm: ['.ts'], 6 | transform: { 7 | [TS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/tsconfig-esm-transpiler.spec.json', 11 | useESM: true, 12 | }, 13 | ], 14 | }, 15 | } satisfies JestConfigWithTsJest 16 | -------------------------------------------------------------------------------- /e2e/test-utils/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-utils", 3 | "private": true 4 | } 5 | -------------------------------------------------------------------------------- /e2e/test-utils/tsconfig-cjs-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig-cjs.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/test-utils/tsconfig-esm-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig-esm.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/transform-js/__tests__/transform-js.spec.ts: -------------------------------------------------------------------------------- 1 | import { inc } from '../src/stateful' 2 | 3 | describe('transform js', () => { 4 | it('should process js file', () => { 5 | expect(inc()).toBe(1) 6 | }) 7 | }) 8 | -------------------------------------------------------------------------------- /e2e/transform-js/jest-compiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'transform-js-compiler-cjs', 5 | transform: { 6 | [TS_JS_TRANSFORM_PATTERN]: [ 7 | 'ts-jest', 8 | { 9 | tsconfig: '/tsconfig-cjs.spec.json', 10 | }, 11 | ], 12 | }, 13 | } satisfies JestConfigWithTsJest 14 | -------------------------------------------------------------------------------- /e2e/transform-js/jest-compiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'transform-js-compiler-esm', 5 | extensionsToTreatAsEsm: ['.ts'], 6 | transform: { 7 | [TS_JS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/tsconfig-esm.spec.json', 11 | useESM: true, 12 | }, 13 | ], 14 | }, 15 | } satisfies JestConfigWithTsJest 16 | -------------------------------------------------------------------------------- /e2e/transform-js/jest-transpiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'transform-js-transpiler-cjs', 5 | transform: { 6 | [TS_JS_TRANSFORM_PATTERN]: [ 7 | 'ts-jest', 8 | { 9 | tsconfig: '/tsconfig-cjs-transpiler.spec.json', 10 | }, 11 | ], 12 | }, 13 | } satisfies JestConfigWithTsJest 14 | -------------------------------------------------------------------------------- /e2e/transform-js/jest-transpiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'transform-js-transpiler-esm', 5 | extensionsToTreatAsEsm: ['.ts'], 6 | transform: { 7 | [TS_JS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/tsconfig-esm-transpiler.spec.json', 11 | useESM: true, 12 | }, 13 | ], 14 | }, 15 | } satisfies JestConfigWithTsJest 16 | -------------------------------------------------------------------------------- /e2e/transform-js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "transform-js", 3 | "private": true 4 | } 5 | -------------------------------------------------------------------------------- /e2e/transform-js/src/stateful.js: -------------------------------------------------------------------------------- 1 | let num = 0 2 | 3 | export function inc() { 4 | num++ 5 | 6 | return num 7 | } 8 | -------------------------------------------------------------------------------- /e2e/transform-js/tsconfig-cjs-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-cjs.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/transform-js/tsconfig-cjs.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "./tsconfig.json", 4 | "../tsconfig-cjs.spec.json" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /e2e/transform-js/tsconfig-esm-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-esm.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/transform-js/tsconfig-esm.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "./tsconfig.json", 4 | "../tsconfig-esm.spec.json" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /e2e/transform-js/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig-js.json" 3 | } 4 | -------------------------------------------------------------------------------- /e2e/transformer-in-ts/__tests__/transformer-in-ts.spec.ts: -------------------------------------------------------------------------------- 1 | describe('transformer-in-ts', () => { 2 | it('should use custom AST transformer written in ts', () => { 3 | expect(true).toBe(true) 4 | }) 5 | }) 6 | -------------------------------------------------------------------------------- /e2e/transformer-in-ts/jest-compiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'transformer-in-ts-compiler-cjs', 5 | transform: { 6 | [TS_TRANSFORM_PATTERN]: [ 7 | 'ts-jest', 8 | { 9 | tsconfig: '/../tsconfig-cjs.spec.json', 10 | astTransformers: { 11 | before: [ 12 | { 13 | path: '/../../src/transformers/hoist-jest.ts', 14 | }, 15 | ], 16 | }, 17 | }, 18 | ], 19 | }, 20 | } satisfies JestConfigWithTsJest 21 | -------------------------------------------------------------------------------- /e2e/transformer-in-ts/jest-compiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'transformer-in-ts-compiler-esm', 5 | extensionsToTreatAsEsm: ['.ts'], 6 | transform: { 7 | [TS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/../tsconfig-esm.spec.json', 11 | astTransformers: { 12 | before: [ 13 | { 14 | path: '/../../src/transformers/hoist-jest.ts', 15 | }, 16 | ], 17 | }, 18 | useESM: true, 19 | }, 20 | ], 21 | }, 22 | } satisfies JestConfigWithTsJest 23 | -------------------------------------------------------------------------------- /e2e/transformer-in-ts/jest-transpiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'transformer-in-ts-transpiler-cjs', 5 | transform: { 6 | [TS_TRANSFORM_PATTERN]: [ 7 | 'ts-jest', 8 | { 9 | tsconfig: '/tsconfig-cjs-transpiler.spec.json', 10 | astTransformers: { 11 | before: [ 12 | { 13 | path: '/../../src/transformers/hoist-jest.ts', 14 | }, 15 | ], 16 | }, 17 | }, 18 | ], 19 | }, 20 | } satisfies JestConfigWithTsJest 21 | -------------------------------------------------------------------------------- /e2e/transformer-in-ts/jest-transpiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'transformer-in-ts-transpiler-esm', 5 | extensionsToTreatAsEsm: ['.ts'], 6 | transform: { 7 | [TS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/tsconfig-esm-transpiler.spec.json', 11 | astTransformers: { 12 | before: [ 13 | { 14 | path: '/../../src/transformers/hoist-jest.ts', 15 | }, 16 | ], 17 | }, 18 | useESM: true, 19 | }, 20 | ], 21 | }, 22 | } satisfies JestConfigWithTsJest 23 | -------------------------------------------------------------------------------- /e2e/transformer-in-ts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "transformer-in-ts", 3 | "private": true 4 | } 5 | -------------------------------------------------------------------------------- /e2e/transformer-in-ts/tsconfig-cjs-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig-cjs.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/transformer-in-ts/tsconfig-esm-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig-esm.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/transformer-options/__tests__/transformer-options.spec.tsx: -------------------------------------------------------------------------------- 1 | import App from '../src/App' 2 | 3 | describe('transformer-options', () => { 4 | it('should pass', () => { 5 | expect(App.prototype.render().props.defaultMessage).toBeUndefined() 6 | }) 7 | }) 8 | -------------------------------------------------------------------------------- /e2e/transformer-options/jest-compiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'transformer-options-compiler-cjs', 5 | testEnvironment: 'jsdom', 6 | transform: { 7 | [TS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/tsconfig-cjs.spec.json', 11 | astTransformers: { 12 | before: [ 13 | { 14 | path: '/../node_modules/@formatjs/ts-transformer/ts-jest-integration', 15 | options: { 16 | removeDefaultMessage: true, 17 | }, 18 | }, 19 | ], 20 | }, 21 | }, 22 | ], 23 | }, 24 | } satisfies JestConfigWithTsJest 25 | -------------------------------------------------------------------------------- /e2e/transformer-options/jest-compiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'transformer-options-compiler-esm', 5 | testEnvironment: 'jsdom', 6 | extensionsToTreatAsEsm: ['.ts', '.tsx'], 7 | transform: { 8 | [TS_TRANSFORM_PATTERN]: [ 9 | 'ts-jest', 10 | { 11 | tsconfig: '/tsconfig-esm.spec.json', 12 | astTransformers: { 13 | before: [ 14 | { 15 | path: '/../node_modules/@formatjs/ts-transformer/ts-jest-integration', 16 | options: { 17 | removeDefaultMessage: true, 18 | }, 19 | }, 20 | ], 21 | }, 22 | useESM: true, 23 | }, 24 | ], 25 | }, 26 | } satisfies JestConfigWithTsJest 27 | -------------------------------------------------------------------------------- /e2e/transformer-options/jest-transpiler-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'transformer-options-transpiler-cjs', 5 | testEnvironment: 'jsdom', 6 | transform: { 7 | [TS_TRANSFORM_PATTERN]: [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/tsconfig-cjs-transpiler.spec.json', 11 | astTransformers: { 12 | before: [ 13 | { 14 | path: '@formatjs/ts-transformer/ts-jest-integration', 15 | options: { 16 | removeDefaultMessage: true, 17 | }, 18 | }, 19 | ], 20 | }, 21 | }, 22 | ], 23 | }, 24 | } satisfies JestConfigWithTsJest 25 | -------------------------------------------------------------------------------- /e2e/transformer-options/jest-transpiler-esm.config.ts: -------------------------------------------------------------------------------- 1 | import { type JestConfigWithTsJest, TS_TRANSFORM_PATTERN } from 'ts-jest' 2 | 3 | export default { 4 | displayName: 'transformer-options-transpiler-esm', 5 | testEnvironment: 'jsdom', 6 | extensionsToTreatAsEsm: ['.ts', '.tsx'], 7 | transform: { 8 | [TS_TRANSFORM_PATTERN]: [ 9 | 'ts-jest', 10 | { 11 | tsconfig: '/tsconfig-esm-transpiler.spec.json', 12 | astTransformers: { 13 | before: [ 14 | { 15 | path: '/../node_modules/@formatjs/ts-transformer/ts-jest-integration', 16 | options: { 17 | removeDefaultMessage: true, 18 | }, 19 | }, 20 | ], 21 | }, 22 | useESM: true, 23 | }, 24 | ], 25 | }, 26 | } satisfies JestConfigWithTsJest 27 | -------------------------------------------------------------------------------- /e2e/transformer-options/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "transformer-options", 3 | "private": true 4 | } 5 | -------------------------------------------------------------------------------- /e2e/transformer-options/src/App.tsx: -------------------------------------------------------------------------------- 1 | import { Component } from 'react' 2 | import { FormattedMessage } from 'react-intl' 3 | 4 | export default class App extends Component { 5 | render() { 6 | return ( 7 | 15 | ) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /e2e/transformer-options/tsconfig-cjs-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-cjs.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/transformer-options/tsconfig-cjs.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "./tsconfig.json", 4 | "../tsconfig-cjs.spec.json" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /e2e/transformer-options/tsconfig-esm-transpiler.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-esm.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/transformer-options/tsconfig-esm.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "./tsconfig.json", 4 | "../tsconfig-esm.spec.json" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /e2e/transformer-options/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "jsx": "react-jsx", 5 | "lib": ["ES2020", "DOM", "DOM.Iterable"] 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /e2e/tsconfig-cjs.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.base.json", 3 | "compilerOptions": { 4 | "module": "CommonJS" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/tsconfig-esm.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.base.json", 3 | "compilerOptions": { 4 | "module": "ESNext" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /e2e/tsconfig-js.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.base.json", 3 | "compilerOptions": { 4 | "esModuleInterop": true, 5 | "allowJs": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/js-with-babel/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['@babel/preset-env'], 3 | } 4 | -------------------------------------------------------------------------------- /examples/js-with-babel/jest-esm-isolated.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createJsWithBabelEsmPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'js-with-babel', 6 | ...createJsWithBabelEsmPreset({ 7 | babelConfig: true, 8 | tsconfig: 'tsconfig-esm-isolated.json', 9 | }), 10 | } satisfies Config 11 | -------------------------------------------------------------------------------- /examples/js-with-babel/jest-esm.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createJsWithBabelEsmPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'js-with-babel', 6 | ...createJsWithBabelEsmPreset({ 7 | babelConfig: true, 8 | tsconfig: 'tsconfig-esm.json', 9 | }), 10 | } satisfies Config 11 | -------------------------------------------------------------------------------- /examples/js-with-babel/jest-isolated.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createJsWithBabelPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'js-with-babel', 6 | ...createJsWithBabelPreset({ 7 | babelConfig: true, 8 | tsconfig: 'tsconfig-isolated.json', 9 | }), 10 | } satisfies Config 11 | -------------------------------------------------------------------------------- /examples/js-with-babel/jest.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createJsWithBabelPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'js-with-babel', 6 | ...createJsWithBabelPreset({ 7 | babelConfig: true, 8 | }), 9 | } satisfies Config 10 | -------------------------------------------------------------------------------- /examples/js-with-babel/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "js-with-babel", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "test": "jest -c=jest.config.ts --no-cache", 7 | "test-isolated": "jest -c=jest-isolated.config.ts --no-cache", 8 | "test-esm": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm.config.ts --no-cache", 9 | "test-esm-isolated": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm-isolated.config.ts --no-cache" 10 | }, 11 | "devDependencies": { 12 | "@babel/core": "^7.27.4", 13 | "@babel/preset-env": "^7.27.2", 14 | "@types/jest": "^29.5.14", 15 | "babel-jest": "^29.7.0", 16 | "cross-env": "^7.0.3", 17 | "jest": "^29.7.0", 18 | "ts-jest": "^29.3.4", 19 | "typescript": "~5.8.3" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/js-with-babel/src/welcome-message.spec.ts: -------------------------------------------------------------------------------- 1 | import { getWelcomeMessage } from './welcome-message' 2 | import welcomePerson from './welcome-person' 3 | 4 | test('should show welcome message', () => { 5 | expect(getWelcomeMessage()).toMatchInlineSnapshot(`"Welcome to ts-jest!!!"`) 6 | }) 7 | 8 | test('should show welcome person message', () => { 9 | // @ts-expect-error in ESM mode, `default` is kept after compilation 10 | expect(welcomePerson.default ? welcomePerson.default : welcomePerson).toMatchInlineSnapshot(`"Welcome to ts-jest!!!"`) 11 | }) 12 | -------------------------------------------------------------------------------- /examples/js-with-babel/src/welcome-message.ts: -------------------------------------------------------------------------------- 1 | export const getWelcomeMessage = (): string => 'Welcome to ts-jest!!!' 2 | -------------------------------------------------------------------------------- /examples/js-with-babel/src/welcome-person.js: -------------------------------------------------------------------------------- 1 | const welcomePerson = 'Welcome to ts-jest!!!' 2 | 3 | export default welcomePerson 4 | -------------------------------------------------------------------------------- /examples/js-with-babel/tsconfig-esm-isolated.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-esm.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/js-with-babel/tsconfig-esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "ESNext", 5 | "esModuleInterop": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/js-with-babel/tsconfig-isolated.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/js-with-babel/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig-base.spec.json", 3 | "compilerOptions": { 4 | "module": "CommonJS", 5 | "allowJs": true, 6 | "isolatedModules": false 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/js-with-ts/jest-esm-isolated.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createJsWithTsEsmPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'js-with-ts', 6 | ...createJsWithTsEsmPreset({ 7 | tsconfig: 'tsconfig-esm-isolated.json', 8 | }), 9 | } satisfies Config 10 | -------------------------------------------------------------------------------- /examples/js-with-ts/jest-esm.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createJsWithTsEsmPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'js-with-ts', 6 | ...createJsWithTsEsmPreset({ 7 | tsconfig: 'tsconfig-esm.json', 8 | }), 9 | } satisfies Config 10 | -------------------------------------------------------------------------------- /examples/js-with-ts/jest-isolated.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createJsWithTsPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'js-with-ts', 6 | ...createJsWithTsPreset({ 7 | tsconfig: 'tsconfig-isolated.json', 8 | }), 9 | transformIgnorePatterns: ['!node_modules/(?!lodash-es)'], 10 | } satisfies Config 11 | -------------------------------------------------------------------------------- /examples/js-with-ts/jest.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createJsWithTsPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'js-with-ts', 6 | ...createJsWithTsPreset(), 7 | transformIgnorePatterns: ['!node_modules/(?!lodash-es)'], 8 | } satisfies Config 9 | -------------------------------------------------------------------------------- /examples/js-with-ts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "js-with-ts", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "test": "jest -c=jest.config.ts --no-cache", 7 | "test-isolated": "jest -c=jest-isolated.config.ts --no-cache", 8 | "test-esm": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm.config.ts --no-cache", 9 | "test-esm-isolated": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm-isolated.config.ts --no-cache" 10 | }, 11 | "devDependencies": { 12 | "@types/lodash-es": "^4.17.12", 13 | "@types/jest": "^29.5.14", 14 | "cross-env": "^7.0.3", 15 | "lodash-es": "^4.17.21", 16 | "jest": "^29.7.0", 17 | "ts-jest": "^29.3.4", 18 | "typescript": "~5.8.3" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/js-with-ts/src/welcome-message.spec.ts: -------------------------------------------------------------------------------- 1 | import camelCase from 'lodash-es/camelCase' 2 | 3 | import { getWelcomeMessage } from './welcome-message' 4 | 5 | test('should show welcome message', () => { 6 | expect(camelCase(getWelcomeMessage())).toBe('welcomeToTsJest') 7 | }) 8 | -------------------------------------------------------------------------------- /examples/js-with-ts/src/welcome-message.ts: -------------------------------------------------------------------------------- 1 | export const getWelcomeMessage = (): string => 'Welcome to ts-jest!!!' 2 | -------------------------------------------------------------------------------- /examples/js-with-ts/tsconfig-esm-isolated.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-esm.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/js-with-ts/tsconfig-esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "ESNext", 5 | "esModuleInterop": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/js-with-ts/tsconfig-isolated.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/js-with-ts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig-base.spec.json", 3 | "compilerOptions": { 4 | "module": "CommonJS", 5 | "allowJs": true, 6 | "isolatedModules": false 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/monorepo-app/jest-esm-isolated.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | 3 | export default { 4 | projects: [ 5 | '/type-commonjs/jest-esm-isolated.config.ts', 6 | '/type-module/jest-esm-isolated.config.ts', 7 | ], 8 | } satisfies Config 9 | -------------------------------------------------------------------------------- /examples/monorepo-app/jest-esm.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | 3 | export default { 4 | projects: ['/type-commonjs/jest-esm.config.ts', '/type-module/jest-esm.config.ts'], 5 | } satisfies Config 6 | -------------------------------------------------------------------------------- /examples/monorepo-app/jest-isolated.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | 3 | export default { 4 | projects: ['/type-commonjs/jest-isolated.config.ts', '/type-module/jest-isolated.config.ts'], 5 | } satisfies Config 6 | -------------------------------------------------------------------------------- /examples/monorepo-app/jest.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | 3 | export default { 4 | projects: ['/type-commonjs/jest.config.ts', '/type-module/jest.config.ts'], 5 | } satisfies Config 6 | -------------------------------------------------------------------------------- /examples/monorepo-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "monorepo-app", 3 | "version": "0.0.0", 4 | "workspaces": [ 5 | "type-commonjs", 6 | "type-module", 7 | "shared" 8 | ], 9 | "scripts": { 10 | "build": "tsc -b", 11 | "test": "jest -c=jest.config.ts --no-cache", 12 | "test-isolated": "jest -c=jest-isolated.config.ts --no-cache", 13 | "test-esm": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm.config.ts --no-cache", 14 | "test-esm-isolated": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm-isolated.config.ts --no-cache" 15 | }, 16 | "devDependencies": { 17 | "@types/jest": "^29.5.14", 18 | "cross-env": "^7.0.3", 19 | "jest": "^29.7.0", 20 | "ts-jest": "^29.3.4", 21 | "typescript": "~5.8.3" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/monorepo-app/shared/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "shared" 3 | } 4 | -------------------------------------------------------------------------------- /examples/monorepo-app/shared/src/async-welcome-message.ts: -------------------------------------------------------------------------------- 1 | export const getAsyncWelcomeMessage = () => Promise.resolve('Welcome to ts-jest!!!') 2 | -------------------------------------------------------------------------------- /examples/monorepo-app/shared/src/default-welcome-message.ts: -------------------------------------------------------------------------------- 1 | const getWelcomeMessage = (): string => 'Welcome to ts-jest!!!' 2 | 3 | export default getWelcomeMessage 4 | -------------------------------------------------------------------------------- /examples/monorepo-app/shared/src/welcome-message.ts: -------------------------------------------------------------------------------- 1 | export const getWelcomeMessage = (): string => 'Welcome to ts-jest!!!' 2 | -------------------------------------------------------------------------------- /examples/monorepo-app/shared/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.base.json" 3 | } 4 | -------------------------------------------------------------------------------- /examples/monorepo-app/tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig-base.spec.json", 3 | "compilerOptions": { 4 | "target": "ESNext" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/monorepo-app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": [], 3 | "include": [], 4 | "references": [ 5 | { 6 | "path": "./type-module/tsconfig.json" 7 | }, 8 | { 9 | "path": "./type-commonjs/tsconfig.json" 10 | }, 11 | { 12 | "path": "./shared/tsconfig.json" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-commonjs/jest-esm-isolated.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createDefaultEsmPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'type-commonjs', 6 | ...createDefaultEsmPreset({ 7 | tsconfig: '/tsconfig-esm-isolated.json', 8 | }), 9 | } satisfies Config 10 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-commonjs/jest-esm.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createDefaultEsmPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'type-commonjs', 6 | ...createDefaultEsmPreset({ 7 | tsconfig: '/tsconfig-esm.json', 8 | }), 9 | } satisfies Config 10 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-commonjs/jest-isolated.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createDefaultPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'type-commonjs', 6 | ...createDefaultPreset({ 7 | tsconfig: '/tsconfig-isolated.json', 8 | }), 9 | } satisfies Config 10 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-commonjs/jest.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createDefaultPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'type-commonjs', 6 | ...createDefaultPreset(), 7 | } satisfies Config 8 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-commonjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "type-commonjs", 3 | "type": "commonjs" 4 | } 5 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-commonjs/test/welcome-message.spec.ts: -------------------------------------------------------------------------------- 1 | import { getWelcomeMessage } from '../../shared/src/welcome-message' 2 | 3 | it('should show welcome message', async () => { 4 | const { getAsyncWelcomeMessage } = await import('../../shared/src/async-welcome-message') 5 | const defaultWelcomeMessage = await import('../../shared/src/default-welcome-message') 6 | 7 | expect(getWelcomeMessage()).toBe('Welcome to ts-jest!!!') 8 | await expect(getAsyncWelcomeMessage()).resolves.toBe('Welcome to ts-jest!!!') 9 | expect(defaultWelcomeMessage.default()).toBe('Welcome to ts-jest!!!') 10 | }) 11 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-commonjs/tsconfig-esm-isolated.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-esm.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-commonjs/tsconfig-esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.base.json", 3 | "compilerOptions": { 4 | "module": "ESNext", 5 | "esModuleInterop": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-commonjs/tsconfig-isolated.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-commonjs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.base.json", 3 | "compilerOptions": { 4 | "module": "CommonJS" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-module/jest-esm-isolated.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createDefaultEsmPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'type-module', 6 | ...createDefaultEsmPreset({ 7 | tsconfig: '/tsconfig-esm-isolated.json', 8 | }), 9 | } satisfies Config 10 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-module/jest-esm.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createDefaultEsmPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'type-module', 6 | ...createDefaultEsmPreset({ 7 | tsconfig: '/tsconfig-esm.json', 8 | }), 9 | } satisfies Config 10 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-module/jest-isolated.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createDefaultPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'type-module', 6 | ...createDefaultPreset({ 7 | tsconfig: '/tsconfig-isolated.json', 8 | }), 9 | } satisfies Config 10 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-module/jest.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createDefaultEsmPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'type-module', 6 | ...createDefaultEsmPreset(), 7 | } satisfies Config 8 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-module/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "type-module", 3 | "type": "module" 4 | } 5 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-module/test/welcome-message.spec.ts: -------------------------------------------------------------------------------- 1 | import { getWelcomeMessage } from '../../shared/src/welcome-message' 2 | 3 | it('should show welcome message', async () => { 4 | const { getAsyncWelcomeMessage } = await import('../../shared/src/async-welcome-message') 5 | const defaultWelcomeMessage = await import('../../shared/src/default-welcome-message') 6 | 7 | expect(getWelcomeMessage()).toBe('Welcome to ts-jest!!!') 8 | await expect(getAsyncWelcomeMessage()).resolves.toBe('Welcome to ts-jest!!!') 9 | expect(defaultWelcomeMessage.default()).toBe('Welcome to ts-jest!!!') 10 | }) 11 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-module/tsconfig-esm-isolated.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-esm.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-module/tsconfig-esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.base.json", 3 | "compilerOptions": { 4 | "module": "ESNext", 5 | "esModuleInterop": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-module/tsconfig-isolated.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/monorepo-app/type-module/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.base.json", 3 | "compilerOptions": { 4 | "module": "CommonJS" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examples", 3 | "version": "0.0.0", 4 | "private": true, 5 | "workspaces": [ 6 | "js-with-babel", 7 | "js-with-ts", 8 | "monorepo-app", 9 | "react-app", 10 | "ts-only", 11 | "type-module" 12 | ], 13 | "scripts": { 14 | "test": "npm run test --workspaces", 15 | "test-isolated": "npm run test-isolated --workspaces", 16 | "test-esm": "npm run test-esm --workspaces", 17 | "test-esm-isolated": "npm run test-esm-isolated --workspaces", 18 | "test-all": "npm-run-all test test-isolated test-esm test-esm-isolated" 19 | }, 20 | "devDependencies": { 21 | "npm-run-all": "^4.1.5" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/react-app/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /examples/react-app/README.md: -------------------------------------------------------------------------------- 1 | # React + TypeScript + Vite 2 | 3 | This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. 4 | 5 | Currently, two official plugins are available: 6 | 7 | - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh 8 | - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh 9 | 10 | ## Expanding the ESLint configuration 11 | 12 | If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: 13 | 14 | - Configure the top-level `parserOptions` property like this: 15 | 16 | ```js 17 | export default { 18 | // other rules... 19 | parserOptions: { 20 | ecmaVersion: 'latest', 21 | sourceType: 'module', 22 | project: ['./tsconfig.json', './tsconfig.node.json'], 23 | tsconfigRootDir: __dirname, 24 | }, 25 | } 26 | ``` 27 | 28 | - Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` 29 | - Optionally add `plugin:@typescript-eslint/stylistic-type-checked` 30 | - Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list 31 | -------------------------------------------------------------------------------- /examples/react-app/config/jest/cssTransform.js: -------------------------------------------------------------------------------- 1 | // This is a custom Jest transformer turning style imports into empty objects. 2 | // http://facebook.github.io/jest/docs/en/webpack.html 3 | 4 | module.exports = { 5 | process() { 6 | return { 7 | code: 'module.exports = {};', 8 | } 9 | }, 10 | getCacheKey() { 11 | // The output is always the same. 12 | return 'cssTransform' 13 | }, 14 | } 15 | -------------------------------------------------------------------------------- /examples/react-app/config/jest/fileTransform.js: -------------------------------------------------------------------------------- 1 | const path = require('node:path') 2 | 3 | const camelcase = require('camelcase') 4 | 5 | // This is a custom Jest transformer turning file imports into filenames. 6 | // http://facebook.github.io/jest/docs/en/webpack.html 7 | 8 | module.exports = { 9 | process(src, filename) { 10 | const assetFilename = JSON.stringify(path.basename(filename)) 11 | 12 | if (filename.match(/\.svg$/)) { 13 | // Based on how SVGR generates a component name: 14 | // https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6 15 | const pascalCaseFilename = camelcase(path.parse(filename).name, { 16 | pascalCase: true, 17 | }) 18 | const componentName = `Svg${pascalCaseFilename}` 19 | 20 | return { 21 | code: `const React = require('react'); 22 | module.exports = { 23 | __esModule: true, 24 | default: ${assetFilename}, 25 | ReactComponent: React.forwardRef(function ${componentName}(props, ref) { 26 | return { 27 | $$typeof: Symbol.for('react.element'), 28 | type: 'svg', 29 | ref: ref, 30 | key: null, 31 | props: Object.assign({}, props, { 32 | children: ${assetFilename} 33 | }) 34 | }; 35 | }), 36 | };`, 37 | } 38 | } 39 | 40 | return { 41 | code: `module.exports = ${assetFilename};`, 42 | } 43 | }, 44 | } 45 | -------------------------------------------------------------------------------- /examples/react-app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite + React + TS 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /examples/react-app/jest-esm-isolated.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createDefaultEsmPreset } from 'ts-jest' 3 | 4 | const defaultPreset = createDefaultEsmPreset({ 5 | tsconfig: 'tsconfig-esm-isolated.spec.json', 6 | }) 7 | 8 | export default { 9 | ...defaultPreset, 10 | displayName: 'react-app', 11 | setupFilesAfterEnv: ['/src/setupTests.ts'], 12 | testEnvironment: 'jsdom', 13 | transform: { 14 | ...defaultPreset.transform, 15 | '^.+\\.css$': '/config/jest/cssTransform.js', 16 | '^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)': '/config/jest/fileTransform.js', 17 | }, 18 | } satisfies Config 19 | -------------------------------------------------------------------------------- /examples/react-app/jest-esm.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createDefaultEsmPreset } from 'ts-jest' 3 | 4 | const defaultPreset = createDefaultEsmPreset({ 5 | tsconfig: 'tsconfig-esm.spec.json', 6 | }) 7 | 8 | export default { 9 | ...defaultPreset, 10 | displayName: 'react-app', 11 | setupFilesAfterEnv: ['/src/setupTests.ts'], 12 | testEnvironment: 'jsdom', 13 | transform: { 14 | ...defaultPreset.transform, 15 | '^.+\\.css$': '/config/jest/cssTransform.js', 16 | '^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)': '/config/jest/fileTransform.js', 17 | }, 18 | } satisfies Config 19 | -------------------------------------------------------------------------------- /examples/react-app/jest-isolated.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createDefaultPreset } from 'ts-jest' 3 | 4 | const defaultPreset = createDefaultPreset({ 5 | tsconfig: 'tsconfig-isolated.spec.json', 6 | }) 7 | 8 | export default { 9 | displayName: 'react-app', 10 | setupFilesAfterEnv: ['/src/setupTests.ts'], 11 | testEnvironment: 'jsdom', 12 | transform: { 13 | ...defaultPreset.transform, 14 | '^.+\\.css$': '/config/jest/cssTransform.js', 15 | '^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)': '/config/jest/fileTransform.js', 16 | }, 17 | } satisfies Config 18 | -------------------------------------------------------------------------------- /examples/react-app/jest.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createDefaultPreset } from 'ts-jest' 3 | 4 | const defaultPreset = createDefaultPreset({ 5 | tsconfig: 'tsconfig.spec.json', 6 | }) 7 | 8 | export default { 9 | displayName: 'react-app', 10 | setupFilesAfterEnv: ['/src/setupTests.ts'], 11 | testEnvironment: 'jsdom', 12 | transform: { 13 | ...defaultPreset.transform, 14 | '^.+\\.css$': '/config/jest/cssTransform.js', 15 | '^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)': '/config/jest/fileTransform.js', 16 | }, 17 | } satisfies Config 18 | -------------------------------------------------------------------------------- /examples/react-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-app", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "vite", 7 | "build": "tsc -b && vite build", 8 | "test": "jest -c=jest.config.ts --no-cache", 9 | "test-isolated": "jest -c=jest-isolated.config.ts --no-cache", 10 | "test-esm": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm.config.ts --no-cache", 11 | "test-esm-isolated": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm-isolated.config.ts --no-cache", 12 | "preview": "vite preview" 13 | }, 14 | "dependencies": { 15 | "react": "^18.3.1", 16 | "react-dom": "^18.3.1" 17 | }, 18 | "devDependencies": { 19 | "@testing-library/dom": "^10.4.0", 20 | "@testing-library/jest-dom": "^6.6.3", 21 | "@testing-library/react": "^16.3.0", 22 | "@types/jest": "^29.5.14", 23 | "@types/react": "^18.3.3", 24 | "@types/react-dom": "^18.3.7", 25 | "@vitejs/plugin-react-swc": "^3.10.0", 26 | "camelcase": "^6.3.0", 27 | "cross-env": "^7.0.3", 28 | "eslint-plugin-prettier": "^5.4.1", 29 | "jest": "^29.7.0", 30 | "jest-environment-jsdom": "^29.7.0", 31 | "ts-jest": "^29.3.4", 32 | "typescript": "~5.8.3", 33 | "vite": "^6.3.5" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /examples/react-app/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/react-app/src/App.css: -------------------------------------------------------------------------------- 1 | #root { 2 | max-width: 1280px; 3 | margin: 0 auto; 4 | padding: 2rem; 5 | text-align: center; 6 | } 7 | 8 | .logo { 9 | height: 6em; 10 | padding: 1.5em; 11 | will-change: filter; 12 | transition: filter 300ms; 13 | } 14 | .logo:hover { 15 | filter: drop-shadow(0 0 2em #646cffaa); 16 | } 17 | .logo.react:hover { 18 | filter: drop-shadow(0 0 2em #61dafbaa); 19 | } 20 | 21 | @keyframes logo-spin { 22 | from { 23 | transform: rotate(0deg); 24 | } 25 | to { 26 | transform: rotate(360deg); 27 | } 28 | } 29 | 30 | @media (prefers-reduced-motion: no-preference) { 31 | a:nth-of-type(2) .logo { 32 | animation: logo-spin infinite 20s linear; 33 | } 34 | } 35 | 36 | .card { 37 | padding: 2em; 38 | } 39 | 40 | .read-the-docs { 41 | color: #888; 42 | } 43 | -------------------------------------------------------------------------------- /examples/react-app/src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import { render } from '@testing-library/react' 2 | 3 | import App from './App' 4 | 5 | test('renders learn react link', () => { 6 | const wrapper = render() 7 | const linkElement = wrapper.getByText('Vite + React') 8 | expect(linkElement).toBeInTheDocument() 9 | }) 10 | -------------------------------------------------------------------------------- /examples/react-app/src/App.tsx: -------------------------------------------------------------------------------- 1 | import { useState } from 'react' 2 | 3 | import viteLogo from '../public/vite.svg' 4 | 5 | import reactLogo from './assets/react.svg' 6 | 7 | import './App.css' 8 | 9 | function App() { 10 | const [count, setCount] = useState(0) 11 | 12 | return ( 13 | <> 14 | 22 |

Vite + React

23 |
24 | 25 |

26 | Edit src/App.tsx and save to test HMR 27 |

28 |
29 |

Click on the Vite and React logos to learn more

30 | 31 | ) 32 | } 33 | 34 | export default App 35 | -------------------------------------------------------------------------------- /examples/react-app/src/index.css: -------------------------------------------------------------------------------- 1 | :root { 2 | font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; 3 | line-height: 1.5; 4 | font-weight: 400; 5 | 6 | color-scheme: light dark; 7 | color: rgba(255, 255, 255, 0.87); 8 | background-color: #242424; 9 | 10 | font-synthesis: none; 11 | text-rendering: optimizeLegibility; 12 | -webkit-font-smoothing: antialiased; 13 | -moz-osx-font-smoothing: grayscale; 14 | } 15 | 16 | a { 17 | font-weight: 500; 18 | color: #646cff; 19 | text-decoration: inherit; 20 | } 21 | a:hover { 22 | color: #535bf2; 23 | } 24 | 25 | body { 26 | margin: 0; 27 | display: flex; 28 | place-items: center; 29 | min-width: 320px; 30 | min-height: 100vh; 31 | } 32 | 33 | h1 { 34 | font-size: 3.2em; 35 | line-height: 1.1; 36 | } 37 | 38 | button { 39 | border-radius: 8px; 40 | border: 1px solid transparent; 41 | padding: 0.6em 1.2em; 42 | font-size: 1em; 43 | font-weight: 500; 44 | font-family: inherit; 45 | background-color: #1a1a1a; 46 | cursor: pointer; 47 | transition: border-color 0.25s; 48 | } 49 | button:hover { 50 | border-color: #646cff; 51 | } 52 | button:focus, 53 | button:focus-visible { 54 | outline: 4px auto -webkit-focus-ring-color; 55 | } 56 | 57 | @media (prefers-color-scheme: light) { 58 | :root { 59 | color: #213547; 60 | background-color: #ffffff; 61 | } 62 | a:hover { 63 | color: #747bff; 64 | } 65 | button { 66 | background-color: #f9f9f9; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /examples/react-app/src/main.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom/client' 3 | 4 | import App from './App.tsx' 5 | import './index.css' 6 | 7 | // eslint-disable-next-line @typescript-eslint/no-non-null-assertion 8 | ReactDOM.createRoot(document.getElementById('root')!).render( 9 | 10 | 11 | , 12 | ) 13 | -------------------------------------------------------------------------------- /examples/react-app/src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom' 6 | -------------------------------------------------------------------------------- /examples/react-app/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /examples/react-app/tsconfig-esm-isolated.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-esm.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/react-app/tsconfig-esm.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.spec.json", 3 | "compilerOptions": { 4 | "module": "ESNext", 5 | "esModuleInterop": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/react-app/tsconfig-isolated.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.spec.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/react-app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "strict": true, 4 | "composite": true, 5 | "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo", 6 | "target": "ES2020", 7 | "useDefineForClassFields": true, 8 | "lib": ["ES2020", "DOM", "DOM.Iterable"], 9 | "module": "ESNext", 10 | /* Bundler mode */ 11 | "moduleResolution": "bundler", 12 | "allowImportingTsExtensions": true, 13 | "resolveJsonModule": true, 14 | "moduleDetection": "force", 15 | "noEmit": true, 16 | "jsx": "react-jsx", 17 | }, 18 | "include": [ 19 | "src" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /examples/react-app/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", 5 | "skipLibCheck": true, 6 | "module": "ESNext", 7 | "moduleResolution": "bundler", 8 | "allowSyntheticDefaultImports": true, 9 | "strict": true, 10 | "noEmit": true 11 | }, 12 | "include": ["vite.config.ts"] 13 | } 14 | -------------------------------------------------------------------------------- /examples/react-app/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "CommonJS", 5 | "moduleResolution": "Node10", 6 | "isolatedModules": false 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/react-app/vite.config.ts: -------------------------------------------------------------------------------- 1 | import react from '@vitejs/plugin-react-swc' 2 | import { defineConfig } from 'vite' 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [react()], 7 | }) 8 | -------------------------------------------------------------------------------- /examples/ts-only/jest-esm-isolated.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createDefaultEsmPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'ts-only', 6 | ...createDefaultEsmPreset({ 7 | tsconfig: 'tsconfig-esm-isolated.json', 8 | }), 9 | } satisfies Config 10 | -------------------------------------------------------------------------------- /examples/ts-only/jest-esm.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createDefaultEsmPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'ts-only', 6 | ...createDefaultEsmPreset({ 7 | tsconfig: 'tsconfig-esm.json', 8 | }), 9 | } satisfies Config 10 | -------------------------------------------------------------------------------- /examples/ts-only/jest-isolated.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createDefaultPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'ts-only', 6 | ...createDefaultPreset({ 7 | tsconfig: 'tsconfig-isolated.json', 8 | }), 9 | } satisfies Config 10 | -------------------------------------------------------------------------------- /examples/ts-only/jest.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | import { createDefaultPreset } from 'ts-jest' 3 | 4 | export default { 5 | displayName: 'ts-only', 6 | ...createDefaultPreset(), 7 | } satisfies Config 8 | -------------------------------------------------------------------------------- /examples/ts-only/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ts-only", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "test": "jest -c=jest.config.ts --no-cache", 7 | "test-isolated": "jest -c=jest-isolated.config.ts --no-cache", 8 | "test-esm": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm.config.ts --no-cache", 9 | "test-esm-isolated": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm-isolated.config.ts --no-cache" 10 | }, 11 | "devDependencies": { 12 | "@types/jest": "^29.5.14", 13 | "cross-env": "^7.0.3", 14 | "jest": "^29.7.0", 15 | "ts-jest": "^29.3.4", 16 | "typescript": "~5.8.3" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/ts-only/src/welcome-message.spec.ts: -------------------------------------------------------------------------------- 1 | import { getWelcomeMessage } from './welcome-message' 2 | 3 | test('should show welcome message', () => { 4 | expect(getWelcomeMessage()).toMatchInlineSnapshot(`"Welcome to ts-jest!!!"`) 5 | }) 6 | -------------------------------------------------------------------------------- /examples/ts-only/src/welcome-message.ts: -------------------------------------------------------------------------------- 1 | export const getWelcomeMessage = (): string => 'Welcome to ts-jest!!!' 2 | -------------------------------------------------------------------------------- /examples/ts-only/tsconfig-esm-isolated.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-esm.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/ts-only/tsconfig-esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "ESNext", 5 | "esModuleInterop": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/ts-only/tsconfig-isolated.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "isolatedModules": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/ts-only/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig-base.spec.json", 3 | "compilerOptions": { 4 | "module": "CommonJS", 5 | "isolatedModules": false 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/tsconfig-base.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "lib": ["ESNext"], 5 | "strict": true, 6 | "skipLibCheck": true, 7 | "types": ["jest"] 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kulshekhar/ts-jest/e5bd0a1a911c7f9ef5af0c96dc967989934120d4/icon.png -------------------------------------------------------------------------------- /jest-e2e-cjs.config.ts: -------------------------------------------------------------------------------- 1 | import path from 'node:path' 2 | 3 | import { sync as spawnSync } from 'execa' 4 | import type { Config } from 'jest' 5 | 6 | // @ts-expect-error not a ts file 7 | import { createBundle } from './scripts/lib/bundle' 8 | 9 | console.log('Install dependencies for all e2e test suites') 10 | 11 | const e2eFolderPath = path.join(process.cwd(), 'e2e') 12 | const bundle = createBundle() 13 | 14 | spawnSync('npm', ['ci'], { 15 | cwd: e2eFolderPath, 16 | }) 17 | 18 | spawnSync('npm', ['install', '--no-package-lock', '--no-shrinkwrap', '--no-save', bundle], { 19 | cwd: e2eFolderPath, 20 | }) 21 | 22 | export default { 23 | projects: ['e2e/**/jest-transpiler-cjs.config.ts', 'e2e/**/jest-compiler-cjs.config.ts'], 24 | } satisfies Config 25 | -------------------------------------------------------------------------------- /jest-e2e-esm.config.ts: -------------------------------------------------------------------------------- 1 | import path from 'node:path' 2 | 3 | import { sync as spawnSync } from 'execa' 4 | import type { Config } from 'jest' 5 | 6 | // @ts-expect-error not a ts file 7 | import { createBundle } from './scripts/lib/bundle' 8 | 9 | console.log('Install dependencies for all e2e test suites') 10 | 11 | const e2eFolderPath = path.join(process.cwd(), 'e2e') 12 | const bundle = createBundle() 13 | 14 | spawnSync('npm', ['ci'], { 15 | cwd: e2eFolderPath, 16 | }) 17 | 18 | spawnSync('npm', ['install', '--no-package-lock', '--no-shrinkwrap', '--no-save', bundle], { 19 | cwd: e2eFolderPath, 20 | }) 21 | 22 | export default { 23 | projects: ['e2e/**/jest-transpiler-esm.config.ts', 'e2e/**/jest-compiler-esm.config.ts'], 24 | } satisfies Config 25 | -------------------------------------------------------------------------------- /jest-preset.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./presets').defaults 2 | -------------------------------------------------------------------------------- /jest.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'jest' 2 | 3 | import { TS_TRANSFORM_PATTERN } from './src' 4 | 5 | import './scripts/create-bundle.js' 6 | 7 | export default { 8 | collectCoverageFrom: ['src/**/*.ts'], 9 | setupFilesAfterEnv: ['/src/__helpers__/setup-jest.ts'], 10 | testMatch: ['/src/**/*.spec.ts'], 11 | transform: { 12 | [TS_TRANSFORM_PATTERN]: [ 13 | '/dist/index.js', 14 | { 15 | tsconfig: { 16 | target: 'ES2015', 17 | isolatedModules: true, 18 | module: 'NodeNext', 19 | moduleResolution: 'NodeNext', 20 | }, 21 | }, 22 | ], 23 | }, 24 | coverageProvider: 'v8', 25 | } satisfies Config 26 | -------------------------------------------------------------------------------- /legacy.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./dist/legacy') 2 | -------------------------------------------------------------------------------- /preprocessor.js: -------------------------------------------------------------------------------- 1 | console.warn( 2 | 'ts-jest[main] (WARN) Replace any occurrences of "ts-jest/dist/preprocessor.js" or ' + 3 | ' "/node_modules/ts-jest/preprocessor.js"' + 4 | ' in the \'transform\' section of your Jest config with just "ts-jest".' 5 | ) 6 | 7 | module.exports = require('./dist') 8 | -------------------------------------------------------------------------------- /presets/default-esm-legacy/jest-preset.js: -------------------------------------------------------------------------------- 1 | module.exports = require('..').defaultsESMLegacy 2 | -------------------------------------------------------------------------------- /presets/default-esm/jest-preset.js: -------------------------------------------------------------------------------- 1 | module.exports = require('..').defaultsESM 2 | -------------------------------------------------------------------------------- /presets/default-legacy/jest-preset.js: -------------------------------------------------------------------------------- 1 | module.exports = require('..').defaultsLegacy 2 | -------------------------------------------------------------------------------- /presets/default/jest-preset.js: -------------------------------------------------------------------------------- 1 | module.exports = require('..').defaults 2 | -------------------------------------------------------------------------------- /presets/index.d.ts: -------------------------------------------------------------------------------- 1 | import allPresets from '../dist/presets/all-presets' 2 | 3 | export = allPresets 4 | -------------------------------------------------------------------------------- /presets/index.js: -------------------------------------------------------------------------------- 1 | const allPresets = require('../dist/presets/all-presets') 2 | 3 | module.exports = allPresets.default 4 | -------------------------------------------------------------------------------- /presets/js-with-babel-esm-legacy/jest-preset.js: -------------------------------------------------------------------------------- 1 | module.exports = require('..').jsWithBabelESMLegacy 2 | -------------------------------------------------------------------------------- /presets/js-with-babel-esm/jest-preset.js: -------------------------------------------------------------------------------- 1 | module.exports = require('..').jsWithBabelESM 2 | -------------------------------------------------------------------------------- /presets/js-with-babel-legacy/jest-preset.js: -------------------------------------------------------------------------------- 1 | module.exports = require('..').jsWithBabelLegacy 2 | -------------------------------------------------------------------------------- /presets/js-with-babel/jest-preset.js: -------------------------------------------------------------------------------- 1 | module.exports = require('..').jsWithBabel 2 | -------------------------------------------------------------------------------- /presets/js-with-ts-esm-legacy/jest-preset.js: -------------------------------------------------------------------------------- 1 | module.exports = require('..').jsWithTsESMLegacy 2 | -------------------------------------------------------------------------------- /presets/js-with-ts-esm/jest-preset.js: -------------------------------------------------------------------------------- 1 | module.exports = require('..').jsWithTsESM 2 | -------------------------------------------------------------------------------- /presets/js-with-ts-legacy/jest-preset.js: -------------------------------------------------------------------------------- 1 | module.exports = require('..').jsWithTsLegacy 2 | -------------------------------------------------------------------------------- /presets/js-with-ts/jest-preset.js: -------------------------------------------------------------------------------- 1 | module.exports = require('..').jsWithTs 2 | -------------------------------------------------------------------------------- /scripts/create-bundle.js: -------------------------------------------------------------------------------- 1 | const { createBundle } = require('./lib/bundle') 2 | 3 | createBundle() 4 | -------------------------------------------------------------------------------- /scripts/lib/logger.js: -------------------------------------------------------------------------------- 1 | module.exports = console 2 | -------------------------------------------------------------------------------- /scripts/lib/paths.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | 3 | const rootDir = path.resolve(__dirname, '..', '..') 4 | const pkgDigestFile = path.join(rootDir, '.ts-jest-digest') 5 | const rawCompilerOptionsFileName = path.join('src', 'raw-compiler-options.ts') 6 | const generatedPath = path.join(process.cwd(), rawCompilerOptionsFileName) 7 | 8 | module.exports = { 9 | pkgDigestFile, 10 | rootDir, 11 | generatedPath, 12 | rawCompilerOptionsFileName, 13 | } 14 | -------------------------------------------------------------------------------- /scripts/post-build.js: -------------------------------------------------------------------------------- 1 | const { computePackageDigest } = require('./lib/bundle') 2 | 3 | computePackageDigest() 4 | -------------------------------------------------------------------------------- /scripts/test-examples.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | 3 | const execa = require('execa') 4 | 5 | const { createBundle } = require('./lib/bundle') 6 | const logger = require('./lib/logger') 7 | 8 | const bundle = createBundle() 9 | 10 | const executeTest = () => { 11 | const projectPath = path.join(process.cwd(), 'examples') 12 | process.chdir(projectPath) 13 | 14 | logger.log('ensuring all dependencies of target project are installed') 15 | logger.log() 16 | 17 | execa.sync('npm', ['ci'], { cwd: projectPath }) 18 | logger.log() 19 | 20 | logger.log('installing bundled version of ts-jest') 21 | logger.log() 22 | 23 | execa.sync('npm', ['install', '--legacy-peer-deps', '--no-package-lock', '--no-shrinkwrap', '--no-save', bundle], { 24 | cwd: projectPath, 25 | }) 26 | logger.log() 27 | 28 | const cmdLine = ['npm', 'run', 'test-all'] 29 | 30 | execa.sync(cmdLine.shift(), cmdLine, { 31 | cwd: projectPath, 32 | stdio: 'inherit', 33 | env: process.env, 34 | }) 35 | logger.log() 36 | } 37 | 38 | executeTest() 39 | -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.organization=kulshekhar-ts-jest 2 | sonar.projectKey=kulshekhar_ts-jest 3 | sonar.sources=src 4 | sonar.language=ts 5 | sonar.sourceEncoding=UTF-8 6 | sonar.javascript.lcov.reportPaths=coverage/lcov.info 7 | sonar.typescript.tsconfigPath=tsconfig.json 8 | sonar.exclusions=\ 9 | **/*.md, \ 10 | **/jest.config.ts, \ 11 | **/jest-*.config.ts, \ 12 | **/*.spec.ts, \ 13 | **/**.spec.ts, \ 14 | src/__helpers__/**, \ 15 | src/__mocks__/**, \ 16 | website/** 17 | -------------------------------------------------------------------------------- /src/__helpers__/dedent-string.ts: -------------------------------------------------------------------------------- 1 | export const omitLeadingWhitespace = (text: string): string => { 2 | return text.replace(/^\s+/gm, '') 3 | } 4 | 5 | export const dedent = (strings: TemplateStringsArray, ...values: unknown[]) => { 6 | let joinedString = '' 7 | for (let i = 0; i < values.length; i++) { 8 | joinedString += `${strings[i]}${values[i]}` 9 | } 10 | joinedString += strings[strings.length - 1] 11 | 12 | return omitLeadingWhitespace(joinedString) 13 | } 14 | -------------------------------------------------------------------------------- /src/__helpers__/setup-jest.ts: -------------------------------------------------------------------------------- 1 | jest.mock('../utils/logger') 2 | -------------------------------------------------------------------------------- /src/__helpers__/workspace-root.ts: -------------------------------------------------------------------------------- 1 | import fs from 'node:fs' 2 | import path from 'node:path' 3 | 4 | function workspaceRootInner(dir: string, candidateRoot: string) { 5 | if (path.dirname(dir) === dir) return candidateRoot 6 | 7 | const matchablePaths = [path.join(dir, '.ts-jest-digest'), path.join(dir, '.github'), path.join(dir, 'renovate.json')] 8 | if (matchablePaths.some((x) => fs.existsSync(x))) { 9 | return dir 10 | } 11 | 12 | return workspaceRootInner(path.dirname(dir), candidateRoot) 13 | } 14 | 15 | export const workspaceRoot = workspaceRootInner(process.cwd(), process.cwd()) 16 | -------------------------------------------------------------------------------- /src/__mocks__/.babelrc-foo: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env", 4 | "@babel/preset-typescript", 5 | "@babel/preset-react" 6 | ], 7 | } 8 | -------------------------------------------------------------------------------- /src/__mocks__/babel-foo.config.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['@babel/preset-env', '@babel/preset-typescript', '@babel/preset-react'], 3 | } 4 | -------------------------------------------------------------------------------- /src/__mocks__/babel-foo.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['@babel/preset-env', '@babel/preset-typescript', '@babel/preset-react'], 3 | } 4 | -------------------------------------------------------------------------------- /src/__mocks__/dummy-transformer.js: -------------------------------------------------------------------------------- 1 | const version = 1 2 | const name = 'dummy-transformer' 3 | function factory() { 4 | return () => { 5 | return (sf) => { 6 | return sf 7 | } 8 | } 9 | } 10 | 11 | module.exports = { 12 | factory, 13 | version, 14 | name, 15 | } 16 | -------------------------------------------------------------------------------- /src/__mocks__/empty.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kulshekhar/ts-jest/e5bd0a1a911c7f9ef5af0c96dc967989934120d4/src/__mocks__/empty.ts -------------------------------------------------------------------------------- /src/__mocks__/funny-transformer.ts: -------------------------------------------------------------------------------- 1 | import type { SourceFile, TransformerFactory } from 'typescript' 2 | 3 | export const version = 1 4 | export const name = 'funny-transformer' 5 | export function factory(): TransformerFactory { 6 | return () => { 7 | return (sf: SourceFile) => { 8 | return sf 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/__mocks__/hummy-transformer.js: -------------------------------------------------------------------------------- 1 | function factory() { 2 | return () => { 3 | return (sf) => { 4 | return sf 5 | } 6 | } 7 | } 8 | 9 | module.exports = { 10 | factory, 11 | } 12 | -------------------------------------------------------------------------------- /src/__mocks__/index.ts: -------------------------------------------------------------------------------- 1 | export const version = '1.2.3-test.0' 2 | export const digest = 'a0d51ca854194df8191d0e65c0ca4730f510f332' 3 | export const createTransformer = jest.fn() 4 | export const jestPreset = { jestPreset: true } 5 | export const createJestPreset = jest.fn() 6 | export const pathsToModuleNameMapper = jest.fn() 7 | -------------------------------------------------------------------------------- /src/__mocks__/package-foo.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "foo" 3 | } 4 | -------------------------------------------------------------------------------- /src/__mocks__/thing.ts: -------------------------------------------------------------------------------- 1 | // @ts-expect-error testing purpose 2 | import babelFooCfg from './babel-foo.config' 3 | import { getFoo, getFooBar } from './thing1' 4 | import { getBar } from './thing2' 5 | 6 | getFoo('foo') 7 | getBar('bar') 8 | getFooBar('foobar') 9 | getFoo(JSON.stringify(babelFooCfg.presets)) 10 | -------------------------------------------------------------------------------- /src/__mocks__/thing1.ts: -------------------------------------------------------------------------------- 1 | import { camelCase, getBar } from './thing2' 2 | 3 | export function getFoo(msg: string): string { 4 | return camelCase(msg) + getBar(msg) 5 | } 6 | 7 | export function getFooBar(msg: string): string { 8 | return getBar(msg) + 'foo' 9 | } 10 | -------------------------------------------------------------------------------- /src/__mocks__/thing2.ts: -------------------------------------------------------------------------------- 1 | export function getBar(msg: string): string { 2 | return camelCase(msg) + 'foo' 3 | } 4 | 5 | export function camelCase(str: string): string { 6 | return str.replace(/[-_\s]+(.)?/g, (_, chr) => (chr ? chr.toUpperCase() : '')) 7 | } 8 | -------------------------------------------------------------------------------- /src/__mocks__/tsconfig-mocks.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "declaration": true, 5 | "types": [] 6 | }, 7 | "include": [ 8 | "bar/**/*" 9 | ], 10 | "exclude": [ 11 | "foo/**/*" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /src/cli/help.ts: -------------------------------------------------------------------------------- 1 | import type { Arguments } from 'yargs' 2 | 3 | /** 4 | * @internal 5 | */ 6 | export const run = async (_: Arguments): Promise => { 7 | process.stdout.write(` 8 | Usage: 9 | ts-jest command [options] [...args] 10 | 11 | Commands: 12 | config:init Creates initial Jest configuration 13 | config:migrate Migrates a given Jest configuration 14 | help [command] Show this help, or help about a command 15 | 16 | Example: 17 | ts-jest help config:migrate 18 | `) 19 | } 20 | 21 | /** 22 | * @internal 23 | */ 24 | export const help = run 25 | -------------------------------------------------------------------------------- /src/config/__snapshots__/paths-to-module-name-mapper.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`pathsToModuleNameMapper should convert tsconfig mapping with given prefix: / 1`] = ` 4 | { 5 | "^@foo\\-bar/common$": "/../common/dist/library", 6 | "^@pkg/(.*)$": "/packages/$1", 7 | "^api/(.*)$": "/src/api/$1", 8 | "^client$": [ 9 | "/src/client", 10 | "/src/client/index", 11 | ], 12 | "^log$": "/src/utils/log", 13 | "^mocks/(.*)$": "/test/mocks/$1", 14 | "^server$": "/src/server", 15 | "^test/(.*)$": "/test/$1", 16 | "^test/(.*)/mock$": [ 17 | "/test/mocks/$1", 18 | "/test/__mocks__/$1", 19 | ], 20 | "^util/(.*)$": "/src/utils/$1", 21 | } 22 | `; 23 | 24 | exports[`pathsToModuleNameMapper should convert tsconfig mapping with given prefix: foo 1`] = ` 25 | { 26 | "^@foo\\-bar/common$": "foo/../common/dist/library", 27 | "^@pkg/(.*)$": "foo/packages/$1", 28 | "^api/(.*)$": "foo/src/api/$1", 29 | "^client$": [ 30 | "foo/src/client", 31 | "foo/src/client/index", 32 | ], 33 | "^log$": "foo/src/utils/log", 34 | "^mocks/(.*)$": "foo/test/mocks/$1", 35 | "^server$": "foo/src/server", 36 | "^test/(.*)$": "foo/test/$1", 37 | "^test/(.*)/mock$": [ 38 | "foo/test/mocks/$1", 39 | "foo/test/__mocks__/$1", 40 | ], 41 | "^util/(.*)$": "foo/src/utils/$1", 42 | } 43 | `; 44 | -------------------------------------------------------------------------------- /src/config/index.ts: -------------------------------------------------------------------------------- 1 | export * from './paths-to-module-name-mapper' 2 | export * from './types' 3 | -------------------------------------------------------------------------------- /src/config/types.ts: -------------------------------------------------------------------------------- 1 | import type { TsConfigJson } from 'type-fest' 2 | 3 | export type TsConfigCompilerOptionsJson = TsConfigJson.CompilerOptions 4 | -------------------------------------------------------------------------------- /src/constants.ts: -------------------------------------------------------------------------------- 1 | export const LINE_FEED = '\n' 2 | export const DECLARATION_TYPE_EXT = '.d.ts' 3 | export const JS_JSX_EXTENSIONS = ['.js', '.jsx'] 4 | export const TS_TSX_REGEX = /\.[cm]?tsx?$/ 5 | export const JS_JSX_REGEX = /\.[cm]?jsx?$/ 6 | export const TS_TRANSFORM_PATTERN = '^.+\\.tsx?$' 7 | export const ESM_TS_TRANSFORM_PATTERN = '^.+\\.m?tsx?$' 8 | export const TS_JS_TRANSFORM_PATTERN = '^.+\\.[tj]sx?$' 9 | export const ESM_TS_JS_TRANSFORM_PATTERN = '^.+\\.m?[tj]sx?$' 10 | export const JS_TRANSFORM_PATTERN = '^.+\\.jsx?$' 11 | export const ESM_JS_TRANSFORM_PATTERN = '^.+\\.m?jsx?$' 12 | // `extensionsToTreatAsEsm` will throw error with `.mjs` 13 | export const TS_EXT_TO_TREAT_AS_ESM = ['.ts', '.tsx', '.mts'] 14 | export const JS_EXT_TO_TREAT_AS_ESM = ['.jsx'] 15 | /** 16 | * @internal 17 | * See https://jestjs.io/docs/en/configuration#testmatch-arraystring 18 | */ 19 | export const DEFAULT_JEST_TEST_MATCH = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'] 20 | -------------------------------------------------------------------------------- /src/index.spec.ts: -------------------------------------------------------------------------------- 1 | import { TsJestTransformer } from './legacy/ts-jest-transformer' 2 | 3 | import tsJest from '.' 4 | 5 | test('should create an instance of TsJestTransformer', () => { 6 | expect(tsJest.createTransformer()).toBeInstanceOf(TsJestTransformer) 7 | }) 8 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { TsJestTransformer } from './legacy/ts-jest-transformer' 2 | import type { TsJestTransformerOptions } from './types' 3 | 4 | export * from './config' 5 | export * from './constants' 6 | export * from './legacy/compiler' 7 | export * from './legacy/ts-jest-transformer' 8 | export * from './legacy/config/config-set' 9 | export * from './presets/create-jest-preset' 10 | export * from './raw-compiler-options' 11 | export * from './utils' 12 | export * from './types' 13 | 14 | export default { 15 | createTransformer(tsJestConfig?: TsJestTransformerOptions) { 16 | return new TsJestTransformer(tsJestConfig) 17 | }, 18 | } 19 | -------------------------------------------------------------------------------- /src/legacy/__snapshots__/ts-jest-transformer.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`TsJestTransformer process should process file with babel-jest 1`] = ` 4 | "foo; 5 | //# " 6 | `; 7 | 8 | exports[`TsJestTransformer process should process file with babel-jest 2`] = ` 9 | "[level:40] Got a unknown file type to compile (file: foo.bar). To fix this, in your Jest config change the \`transform\` key which value is \`ts-jest\` so that it does not match this kind of files anymore. If you still want Babel to process it, add another entry to the \`transform\` option with value \`babel-jest\` which key matches this type of files. 10 | " 11 | `; 12 | 13 | exports[`TsJestTransformer process should process file with babel-jest 3`] = ` 14 | "foo; 15 | //# " 16 | `; 17 | -------------------------------------------------------------------------------- /src/legacy/compiler/__snapshots__/ts-compiler.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`TsCompiler getCompiledOutput isolatedModules true should transpile code with config {"babelConfig": false, "module": "CommonJS", "supportsStaticESM": false, "useESM": true} 1`] = ` 4 | { 5 | "allowSyntheticDefaultImports": undefined, 6 | "customConditions": undefined, 7 | "esModuleInterop": true, 8 | "module": 1, 9 | } 10 | `; 11 | 12 | exports[`TsCompiler getCompiledOutput isolatedModules true should transpile code with config {"babelConfig": false, "module": "CommonJS", "supportsStaticESM": true, "useESM": false} 1`] = ` 13 | { 14 | "allowSyntheticDefaultImports": undefined, 15 | "customConditions": undefined, 16 | "esModuleInterop": true, 17 | "module": 1, 18 | } 19 | `; 20 | 21 | exports[`TsCompiler getCompiledOutput isolatedModules true should transpile code with config {"babelConfig": false, "module": "ESNext", "supportsStaticESM": true, "useESM": true} 1`] = ` 22 | { 23 | "allowSyntheticDefaultImports": undefined, 24 | "customConditions": undefined, 25 | "esModuleInterop": true, 26 | "module": 99, 27 | } 28 | `; 29 | 30 | exports[`TsCompiler getCompiledOutput isolatedModules true should transpile code with config {"babelConfig": true, "module": "CommonJS", "supportsStaticESM": false, "useESM": true} 1`] = ` 31 | { 32 | "allowSyntheticDefaultImports": undefined, 33 | "customConditions": undefined, 34 | "esModuleInterop": true, 35 | "module": 1, 36 | } 37 | `; 38 | -------------------------------------------------------------------------------- /src/legacy/compiler/compiler-utils.ts: -------------------------------------------------------------------------------- 1 | import { stringify } from '../../utils' 2 | 3 | /** 4 | * Rely on TypeScript compiled output generation which contains this prefix to point to sourcemap location. 5 | */ 6 | export const SOURCE_MAPPING_PREFIX = 'sourceMappingURL=' 7 | 8 | /** 9 | * Update the output remapping the source map. 10 | */ 11 | export function updateOutput(outputText: string, normalizedFileName: string, sourceMap?: string): string { 12 | if (sourceMap) { 13 | const base64Map = Buffer.from(updateSourceMap(sourceMap, normalizedFileName), 'utf8').toString('base64') 14 | const sourceMapContent = `data:application/json;charset=utf-8;base64,${base64Map}` 15 | 16 | // sourceMappingURL= prefix is always at the end of compiledOutput, using lastIndexOf should be the safest way to substring 17 | return ( 18 | outputText.slice(0, outputText.lastIndexOf(SOURCE_MAPPING_PREFIX) + SOURCE_MAPPING_PREFIX.length) + 19 | sourceMapContent 20 | ) 21 | } 22 | 23 | return outputText 24 | } 25 | 26 | /** 27 | * Update the source map contents for improved output. 28 | */ 29 | const updateSourceMap = (sourceMapText: string, normalizedFileName: string): string => { 30 | const sourceMap = JSON.parse(sourceMapText) 31 | sourceMap.file = normalizedFileName 32 | sourceMap.sources = [normalizedFileName] 33 | delete sourceMap.sourceRoot 34 | 35 | return stringify(sourceMap) 36 | } 37 | -------------------------------------------------------------------------------- /src/legacy/compiler/index.ts: -------------------------------------------------------------------------------- 1 | export * from './ts-compiler' 2 | export * from './ts-jest-compiler' 3 | -------------------------------------------------------------------------------- /src/legacy/compiler/ts-jest-compiler.spec.ts: -------------------------------------------------------------------------------- 1 | import { createConfigSet } from '../../__helpers__/fakers' 2 | 3 | import { TsCompiler } from './ts-compiler' 4 | import { TsJestCompiler } from './ts-jest-compiler' 5 | 6 | describe('TsJestCompiler', () => { 7 | jest.spyOn(TsCompiler.prototype, 'getResolvedModules').mockImplementation(() => []) 8 | jest.spyOn(TsCompiler.prototype, 'getCompiledOutput').mockImplementation(() => ({ 9 | code: '', 10 | })) 11 | const runtimeCacheFS = new Map() 12 | const fileContent = 'const foo = 1' 13 | const fileName = 'foo.ts' 14 | const compiler = new TsJestCompiler(createConfigSet(), runtimeCacheFS) 15 | 16 | describe('getResolvedModules', () => { 17 | test('should call getResolvedModules from compiler instance', () => { 18 | compiler.getResolvedModules(fileContent, fileName, runtimeCacheFS) 19 | 20 | expect(TsCompiler.prototype.getResolvedModules).toHaveBeenCalledWith(fileContent, fileName, runtimeCacheFS) 21 | }) 22 | }) 23 | 24 | describe('getCompiledOutput', () => { 25 | test('should call getCompiledOutput from compiler instance', () => { 26 | compiler.getCompiledOutput(fileContent, fileName, { 27 | depGraphs: new Map(), 28 | supportsStaticESM: false, 29 | watchMode: false, 30 | }) 31 | 32 | expect(TsCompiler.prototype.getCompiledOutput).toHaveBeenCalledWith(fileContent, fileName, { 33 | depGraphs: new Map(), 34 | supportsStaticESM: false, 35 | watchMode: false, 36 | }) 37 | }) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /src/legacy/compiler/ts-jest-compiler.ts: -------------------------------------------------------------------------------- 1 | import type { CompilerInstance, CompiledOutput, StringMap, TsJestCompileOptions } from '../../types' 2 | import type { ConfigSet } from '../config/config-set' 3 | 4 | import { TsCompiler } from './ts-compiler' 5 | 6 | export class TsJestCompiler implements CompilerInstance { 7 | private readonly _compilerInstance: CompilerInstance 8 | 9 | constructor(configSet: ConfigSet, runtimeCacheFS: StringMap) { 10 | // Later we can add swc/esbuild or other typescript compiler instance here 11 | this._compilerInstance = new TsCompiler(configSet, runtimeCacheFS) 12 | } 13 | 14 | getResolvedModules(fileContent: string, fileName: string, runtimeCacheFS: StringMap): string[] { 15 | return this._compilerInstance.getResolvedModules(fileContent, fileName, runtimeCacheFS) 16 | } 17 | 18 | getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): CompiledOutput { 19 | return this._compilerInstance.getCompiledOutput(fileContent, fileName, options) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/legacy/index.ts: -------------------------------------------------------------------------------- 1 | import type { TsJestTransformerOptions } from '../types' 2 | 3 | import { TsJestTransformer } from './ts-jest-transformer' 4 | 5 | export default { 6 | createTransformer: (tsJestConfig?: TsJestTransformerOptions): TsJestTransformer => 7 | new TsJestTransformer(tsJestConfig), 8 | } 9 | -------------------------------------------------------------------------------- /src/presets/all-presets.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createDefaultEsmLegacyPreset, 3 | createDefaultEsmPreset, 4 | createDefaultLegacyPreset, 5 | createDefaultPreset, 6 | createJsWithBabelEsmLegacyPreset, 7 | createJsWithBabelEsmPreset, 8 | createJsWithBabelLegacyPreset, 9 | createJsWithBabelPreset, 10 | createJsWithTsEsmLegacyPreset, 11 | createJsWithTsEsmPreset, 12 | createJsWithTsLegacyPreset, 13 | createJsWithTsPreset, 14 | } from './create-jest-preset' 15 | 16 | const allPresets = { 17 | get defaults() { 18 | return createDefaultPreset() 19 | }, 20 | get defaultsLegacy() { 21 | return createDefaultLegacyPreset() 22 | }, 23 | get defaultsESM() { 24 | return createDefaultEsmPreset() 25 | }, 26 | get defaultsESMLegacy() { 27 | return createDefaultEsmLegacyPreset() 28 | }, 29 | get jsWithTs() { 30 | return createJsWithTsPreset() 31 | }, 32 | get jsWithTsLegacy() { 33 | return createJsWithTsLegacyPreset() 34 | }, 35 | get jsWithTsESM() { 36 | return createJsWithTsEsmPreset() 37 | }, 38 | get jsWithTsESMLegacy() { 39 | return createJsWithTsEsmLegacyPreset() 40 | }, 41 | get jsWithBabel() { 42 | return createJsWithBabelPreset() 43 | }, 44 | get jsWithBabelLegacy() { 45 | return createJsWithBabelLegacyPreset() 46 | }, 47 | get jsWithBabelESM() { 48 | return createJsWithBabelEsmPreset() 49 | }, 50 | get jsWithBabelESMLegacy() { 51 | return createJsWithBabelEsmLegacyPreset() 52 | }, 53 | } 54 | 55 | export default allPresets 56 | -------------------------------------------------------------------------------- /src/transformers/README.md: -------------------------------------------------------------------------------- 1 | # Transformer 2 | 3 | See https://dev.doctorevidence.com/how-to-write-a-typescript-transform-plugin-fc5308fdd943 4 | 5 | ## Boilerplate 6 | 7 | ```ts 8 | import { SourceFile, TransformationContext, Transformer, Visitor } from 'typescript' 9 | 10 | import type { TsCompilerInstance } from 'ts-jest/dist/types' 11 | 12 | /** 13 | * Remember to increase the version whenever transformer's content is changed. This is to inform Jest to not reuse 14 | * the previous cache which contains old transformer's content 15 | */ 16 | export const version = 1 17 | // Used for constructing cache key 18 | export const name = 'hoist-jest' 19 | 20 | export function factory(compilerInstance: TsCompilerInstance) { 21 | const ts = compilerInstance.configSet.compilerModule 22 | function createVisitor(ctx: TransformationContext, sf: SourceFile) { 23 | const visitor: Visitor = (node) => { 24 | // here we can check each node and potentially return 25 | // new nodes if we want to leave the node as is, and 26 | // continue searching through child nodes: 27 | return ts.visitEachChild(node, visitor, ctx) 28 | } 29 | return visitor 30 | } 31 | // we return the factory expected in CustomTransformers 32 | return (ctx: TransformationContext): Transformer => { 33 | return (sf: SourceFile) => ts.visitNode(sf, createVisitor(ctx, sf)) 34 | } 35 | } 36 | ``` 37 | -------------------------------------------------------------------------------- /src/utils/__mocks__/logger.ts: -------------------------------------------------------------------------------- 1 | import { testing } from 'bs-logger' 2 | 3 | export const rootLogger = testing.createLoggerMock() 4 | -------------------------------------------------------------------------------- /src/utils/get-package-version.spec.ts: -------------------------------------------------------------------------------- 1 | import { valid } from 'semver' 2 | 3 | import { getPackageVersion } from './get-package-version' 4 | 5 | it('should get the version of a package', () => { 6 | const version = require('../../node_modules/jest/package.json').version 7 | // ensure the above call doesn't actually fail 8 | expect(valid(version)).not.toBeNull() 9 | // real test 10 | expect(getPackageVersion('jest')).toBe(version) 11 | }) 12 | 13 | it('should not fail when the package is not installeed', () => { 14 | expect(getPackageVersion('__foo-bar__')).toBeUndefined() 15 | }) 16 | -------------------------------------------------------------------------------- /src/utils/get-package-version.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @internal 3 | */ 4 | export function getPackageVersion(moduleName: string): string | undefined { 5 | try { 6 | return require(`${moduleName}/package.json`).version as string 7 | } catch { 8 | return undefined 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from './json' 2 | export * from './jsonable-value' 3 | export * from './logger' 4 | -------------------------------------------------------------------------------- /src/utils/json.spec.ts: -------------------------------------------------------------------------------- 1 | import { parse, stringify } from './json' 2 | 3 | describe('stringify/parse', () => { 4 | it('should (de)serialize undefined', () => { 5 | const val = undefined 6 | const serialized = stringify(val) 7 | 8 | expect(typeof serialized).toBe('string') 9 | expect(parse(serialized)).toBeUndefined() 10 | }) 11 | 12 | it('should keep the same order of keys', () => { 13 | const str1 = stringify({ one: 1, two: 2 }) 14 | const str2 = stringify({ two: 2, one: 1 }) 15 | 16 | expect(str1).toBe(str2) 17 | }) 18 | }) 19 | -------------------------------------------------------------------------------- /src/utils/json.ts: -------------------------------------------------------------------------------- 1 | import stableStringify from 'fast-json-stable-stringify' 2 | 3 | const UNDEFINED = 'undefined' 4 | 5 | export function stringify(input: unknown): string { 6 | return input === undefined ? UNDEFINED : stableStringify(input) 7 | } 8 | 9 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 10 | export function parse(input: string): any { 11 | return input === UNDEFINED ? undefined : JSON.parse(input) 12 | } 13 | -------------------------------------------------------------------------------- /src/utils/jsonable-value.spec.ts: -------------------------------------------------------------------------------- 1 | import * as _json from './json' 2 | import { JsonableValue } from './jsonable-value' 3 | 4 | jest.mock('./json') 5 | 6 | const { stringify } = jest.mocked(_json) 7 | 8 | stringify.mockImplementation((v) => JSON.stringify(v)) 9 | 10 | beforeEach(() => { 11 | jest.clearAllMocks() 12 | }) 13 | 14 | it('should cache the serialized value', () => { 15 | const jv = new JsonableValue({ foo: 'bar' }) 16 | expect(jv.serialized).toBe('{"foo":"bar"}') 17 | expect(stringify).toHaveBeenCalledTimes(1) 18 | expect(jv.serialized).toBe('{"foo":"bar"}') 19 | expect(stringify).toHaveBeenCalledTimes(1) 20 | }) 21 | 22 | it('should update the serialized value when updating the value', () => { 23 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 24 | const jv = new JsonableValue({ foo: 'bar' } as any) 25 | expect(jv.serialized).toBe('{"foo":"bar"}') 26 | stringify.mockClear() 27 | jv.value = { bar: 'foo' } 28 | expect(jv.serialized).toBe('{"bar":"foo"}') 29 | expect(jv.serialized).toBe('{"bar":"foo"}') 30 | expect(stringify).toHaveBeenCalledTimes(1) 31 | }) 32 | -------------------------------------------------------------------------------- /src/utils/jsonable-value.ts: -------------------------------------------------------------------------------- 1 | import { stringify } from './json' 2 | 3 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 4 | export class JsonableValue> { 5 | private _serialized!: string 6 | private _value!: V 7 | 8 | constructor(value: V) { 9 | this.value = value 10 | } 11 | 12 | set value(value: V) { 13 | this._value = value 14 | this._serialized = stringify(value) 15 | } 16 | 17 | get value(): V { 18 | return this._value 19 | } 20 | 21 | get serialized(): string { 22 | return this._serialized 23 | } 24 | 25 | valueOf(): V { 26 | return this._value 27 | } 28 | 29 | toString(): string { 30 | return this._serialized 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/utils/logger.spec.ts: -------------------------------------------------------------------------------- 1 | import { rootLogger } from './logger' 2 | 3 | jest.unmock('./logger') 4 | 5 | // ths is just a simple test to ensure we do have a logger 6 | describe('rootLogger', () => { 7 | it('should be a logger', () => { 8 | expect(typeof rootLogger).toBe('function') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /src/utils/logger.ts: -------------------------------------------------------------------------------- 1 | import { LogContexts, LogLevels, createLogger } from 'bs-logger' 2 | 3 | import { backportTsJestDebugEnvVar } from './backports' 4 | 5 | const original = process.env.TS_JEST_LOG 6 | 7 | const buildOptions = () => ({ 8 | context: { 9 | [LogContexts.package]: 'ts-jest', 10 | [LogContexts.logLevel]: LogLevels.trace, 11 | version: require('../../package.json').version, 12 | }, 13 | targets: process.env.TS_JEST_LOG ?? undefined, 14 | }) 15 | 16 | export let rootLogger = createLogger(buildOptions()) 17 | 18 | backportTsJestDebugEnvVar(rootLogger) 19 | 20 | // re-create the logger if the env var has been backported 21 | if (original !== process.env.TS_JEST_LOG) { 22 | rootLogger = createLogger(buildOptions()) 23 | } 24 | -------------------------------------------------------------------------------- /src/utils/messages.spec.ts: -------------------------------------------------------------------------------- 1 | import { interpolate } from './messages' 2 | 3 | const MESSAGE_WITH_PARAMS = 'param1: {{param1}}, param2: {{param2}}, again param1: {{param1}}' 4 | 5 | describe('interpolate', () => { 6 | it('should return string as-is when no var given', () => { 7 | expect(interpolate(MESSAGE_WITH_PARAMS)).toBe(MESSAGE_WITH_PARAMS) 8 | }) 9 | it('should return string with replaced vars', () => { 10 | expect(interpolate(MESSAGE_WITH_PARAMS, { param1: 1, param2: '2' })).toBe('param1: 1, param2: 2, again param1: 1') 11 | expect(interpolate(MESSAGE_WITH_PARAMS, { param1: 'p1' })).toBe('param1: p1, param2: {{param2}}, again param1: p1') 12 | }) 13 | }) 14 | -------------------------------------------------------------------------------- /src/utils/normalize-slashes.spec.ts: -------------------------------------------------------------------------------- 1 | import { normalizeSlashes } from './normalize-slashes' 2 | 3 | it('should replace windows slashes', () => { 4 | expect(normalizeSlashes('path/to\\something/here\\and\\there.js')).toBe('path/to/something/here/and/there.js') 5 | }) 6 | -------------------------------------------------------------------------------- /src/utils/normalize-slashes.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @internal 3 | */ 4 | export function normalizeSlashes(value: string): string { 5 | return value.replace(/\\/g, '/') 6 | } 7 | -------------------------------------------------------------------------------- /src/utils/sha1.spec.ts: -------------------------------------------------------------------------------- 1 | import { sha1 } from './sha1' 2 | 3 | const ONE = 'fe05bcdcdc4928012781a5f1a2a77cbb5398e106' 4 | const ONE_TWO = '30ae97492ce1da88d0e7117ace0a60a6f9e1e0bc' 5 | const ONE_TWO_THREE = '3e949019500deb1369f13d9644d420d3a920aa5e' 6 | 7 | it('should encrypt one or more string', () => { 8 | expect(sha1('one')).toBe(ONE) 9 | expect(sha1('one', 'two')).toBe(ONE_TWO) 10 | expect(sha1('one', 'two', 'three')).toBe(ONE_TWO_THREE) 11 | }) 12 | 13 | it('should encrypt one or more buffers', () => { 14 | expect(sha1(Buffer.from('one'))).toBe(ONE) 15 | expect(sha1(Buffer.from('one'), Buffer.from('two'))).toBe(ONE_TWO) 16 | expect(sha1(Buffer.from('one'), Buffer.from('two'), Buffer.from('three'))).toBe(ONE_TWO_THREE) 17 | }) 18 | 19 | it('should encrypt mixed items', () => { 20 | expect(sha1('one', Buffer.from('two'), 'three')).toBe(ONE_TWO_THREE) 21 | expect(sha1(Buffer.from('one'), 'two', Buffer.from('three'))).toBe(ONE_TWO_THREE) 22 | }) 23 | -------------------------------------------------------------------------------- /src/utils/sha1.ts: -------------------------------------------------------------------------------- 1 | import { createHash } from 'crypto' 2 | 3 | /** 4 | * @internal 5 | */ 6 | // stores hashes made out of only one argument being a string 7 | export const cache: { [key: string]: string } = Object.create(null) 8 | 9 | type DataItem = string | Buffer 10 | 11 | /** 12 | * @internal 13 | */ 14 | export function sha1(...data: DataItem[]): string { 15 | const canCache = data.length === 1 && typeof data[0] === 'string' 16 | // caching 17 | let cacheKey!: string 18 | if (canCache) { 19 | cacheKey = data[0] as string 20 | if (cacheKey in cache) { 21 | return cache[cacheKey] 22 | } 23 | } 24 | 25 | // we use SHA1 because it's the fastest provided by node 26 | // and we are not concerned about security here 27 | const hash = createHash('sha1') 28 | data.forEach((item) => { 29 | if (typeof item === 'string') hash.update(item, 'utf8') 30 | else hash.update(item) 31 | }) 32 | const res = hash.digest('hex').toString() 33 | 34 | if (canCache) { 35 | cache[cacheKey] = res 36 | } 37 | 38 | return res 39 | } 40 | -------------------------------------------------------------------------------- /src/utils/ts-error.ts: -------------------------------------------------------------------------------- 1 | import { inspect } from 'util' 2 | 3 | import { BaseError } from 'make-error' 4 | 5 | import { rootLogger } from './logger' 6 | import { Errors, interpolate } from './messages' 7 | 8 | const logger = rootLogger.child({ namespace: 'TSError' }) 9 | 10 | /** 11 | * @internal 12 | */ 13 | export const INSPECT_CUSTOM = inspect.custom || 'inspect' 14 | 15 | /** 16 | * TypeScript diagnostics error. 17 | * 18 | * @internal 19 | */ 20 | export class TSError extends BaseError { 21 | name = 'TSError' 22 | 23 | constructor(public diagnosticText: string, public diagnosticCodes: number[]) { 24 | super( 25 | interpolate(Errors.UnableToCompileTypeScript, { 26 | diagnostics: diagnosticText.trim(), 27 | }), 28 | ) 29 | logger.debug({ diagnosticCodes, diagnosticText }, 'created new TSError') 30 | // ensure we blacklist any of our code 31 | Object.defineProperty(this, 'stack', { value: '' }) 32 | } 33 | 34 | /* istanbul ignore next */ 35 | [INSPECT_CUSTOM](): string { 36 | return this.diagnosticText 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "strict": true, 4 | "downlevelIteration": true, 5 | "experimentalDecorators": true, 6 | "forceConsistentCasingInFileNames": true, 7 | "noFallthroughCasesInSwitch": true, 8 | "noUnusedLocals": true, 9 | "noUnusedParameters": true, 10 | "noImplicitReturns": true, 11 | "skipLibCheck": true, 12 | "esModuleInterop": true, 13 | "resolveJsonModule": true, 14 | "checkJs": false, 15 | "target": "ESNext", 16 | "module": "NodeNext", 17 | "moduleResolution": "NodeNext", 18 | "lib": ["ESNext"] 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "stripInternal": true, 6 | "outDir": "dist" 7 | }, 8 | "include": ["src"], 9 | "exclude": ["**/*.spec.ts", "**/__mocks__", "src/__helpers__"] 10 | } 11 | -------------------------------------------------------------------------------- /tsconfig.eslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "include": ["src", "examples", "website", "scripts", "presets", "utils", "e2e", "*.config.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "compilerOptions": { 4 | "moduleResolution": "Bundler" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /website/.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | /node_modules 3 | 4 | # Production 5 | /build 6 | 7 | # Generated files 8 | .docusaurus 9 | .cache-loader 10 | 11 | # Misc 12 | .DS_Store 13 | .env.local 14 | .env.development.local 15 | .env.test.local 16 | .env.production.local 17 | 18 | npm-debug.log* 19 | yarn-debug.log* 20 | yarn-error.log* 21 | -------------------------------------------------------------------------------- /website/README.md: -------------------------------------------------------------------------------- 1 | # Website 2 | 3 | This website is built using [Docusaurus 2](https://v2.docusaurus.io/), a modern static website generator. 4 | 5 | ## Installation 6 | 7 | ```console 8 | yarn install 9 | ``` 10 | 11 | ## Local Development 12 | 13 | ```console 14 | yarn start 15 | ``` 16 | 17 | This command starts a local development server and open up a browser window. Most changes are reflected live without having to restart the server. 18 | 19 | ## Build 20 | 21 | ```console 22 | yarn build 23 | ``` 24 | 25 | This command generates static content into the `build` directory and can be served using any static contents hosting service. 26 | 27 | ## Deployment 28 | 29 | ```console 30 | GIT_USER= USE_SSH=true yarn deploy 31 | ``` 32 | 33 | If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch. 34 | -------------------------------------------------------------------------------- /website/docs/debugging.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: debugging 3 | title: Debugging ts-jest 4 | --- 5 | 6 | You can activate the debug logger by setting the environment variable `TS_JEST_LOG` before running tests. 7 | The output of the logger will be in **ts-jest.log** in current working directory. 8 | 9 | The debug logger contains some useful information about how internal `ts-jest` works, including which files are processed, 10 | which Jest config or TypeScript config is used etc. 11 | 12 | **Linux/MacOS** 13 | 14 | ``` 15 | export TS_JEST_LOG=ts-jest.log 16 | ``` 17 | 18 | **Windows** 19 | 20 | ```Command Prompt tab 21 | set TS_JEST_LOG=ts-jest.log 22 | ``` 23 | 24 | ```PowerShell tab 25 | $env:TS_JEST_LOG = 'ts-jest.log' 26 | ``` 27 | -------------------------------------------------------------------------------- /website/docs/getting-started/options/compiler.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Compiler option 3 | --- 4 | 5 | The `compiler` option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler. 6 | 7 | The default value is `typescript`, which will load the original [TypeScript compiler module](https://www.npmjs.com/package/typescript). 8 | The loaded version will depend on the one installed in your project. 9 | 10 | If you use a custom compiler, such as `ttypescript`, make sure its API is the same as the original TypeScript, at least for what `ts-jest` is using. 11 | 12 | ### Example 13 | 14 | ```ts title="jest.config.ts" 15 | import type { Config } from 'jest' 16 | 17 | const jestConfig: Config = { 18 | // [...] 19 | transform: { 20 | // '^.+\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest` 21 | // '^.+\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest` 22 | '^.+\\.tsx?$': [ 23 | 'ts-jest', 24 | { 25 | compiler: 'ttypescript', 26 | }, 27 | ], 28 | }, 29 | } 30 | 31 | export default jestConfig 32 | ``` 33 | -------------------------------------------------------------------------------- /website/docs/getting-started/options/useESM.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: useESM option 3 | --- 4 | 5 | The `useESM` option allows `ts-jest` to transform codes to ESM syntax **if possible**. 6 | 7 | The default value is **false**, `ts-jest` will transform codes to `CommonJS` syntax. 8 | 9 | :::tip 10 | 11 | See more about ESM support in [dedicated guide](../../guides/esm-support.md) 12 | 13 | ::: 14 | 15 | ### Examples 16 | 17 | ```ts title="jest.config.ts" 18 | import type { Config } from 'jest' 19 | 20 | const jestConfig: Config = { 21 | // [...] 22 | transform: { 23 | // '^.+\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest` 24 | // '^.+\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest` 25 | '^.+\\.tsx?$': [ 26 | 'ts-jest', 27 | { 28 | useESM: true, 29 | }, 30 | ], 31 | }, 32 | } 33 | 34 | export default jestConfig 35 | ``` 36 | -------------------------------------------------------------------------------- /website/docs/getting-started/version-checking.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: version-checking 3 | title: Version checking 4 | --- 5 | 6 | :::warning DEPRECATED 7 | 8 | The version checking is **DEPRECATED** in favor of native `peerDependencies` checking mechanism in `package.json`. This page will be removed in the next major version. 9 | 10 | ::: 11 | 12 | By default, `ts-jest` supports a range of versions for `jest`/`typescript`. One uses incompatible versions will receive a warning 13 | message while running tests. This warning message can be opt-out by setting environment variable `TS_JEST_DISABLE_VER_CHECKER`: 14 | 15 | **Linux/MacOS** 16 | 17 | ``` 18 | export TS_JEST_DISABLE_VER_CHECKER=true 19 | ``` 20 | 21 | **Windows** 22 | 23 | ``` 24 | set TS_JEST_DISABLE_VER_CHECKER=true 25 | ``` 26 | 27 | ### Note 28 | 29 | As long as the environment variable `TS_JEST_DISABLE_VER_CHECKER` stays, the warning message will no longer show. 30 | This can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions. 31 | -------------------------------------------------------------------------------- /website/docs/guides/hybrid-node-module.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: hybrid-node-module 3 | title: Hybrid Node module 4 | --- 5 | 6 | When using hybrid node `module` values, `Node16`/`Node18`/`NodeNext`, one should read [TypeScript documentation](https://www.typescriptlang.org/docs/handbook/modules/reference.html#node16-node18-nodenext) 7 | to understand how the emitted code looks like. 8 | 9 | :::important 10 | 11 | At the moment, `ts-jest` uses TypeScript API to transpile code so the emitted `js` code depends on the `TypeScript` version used. 12 | 13 | ::: 14 | 15 | There will be a few differences from traditional `CommonJs`, e.g. `dynamic import` **WON'T** be transformed into `Promise` and `require`. 16 | -------------------------------------------------------------------------------- /website/docs/guides/mock-es6-class.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: mock-es6-class 3 | title: Mock ES6 class 4 | --- 5 | 6 | TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import. 7 | `const soundPlayer = require('./sound-player')`. Therefore creating an instance of the class that was exported as 8 | a default will look like this: `new soundPlayer.default()`. However if you are mocking the class as suggested by the documentation. 9 | 10 | ```ts title="my-mocks.ts" 11 | jest.mock('./sound-player', () => { 12 | return jest.fn().mockImplementation(() => { 13 | return { playSoundFile: mockPlaySoundFile } 14 | }) 15 | }) 16 | ``` 17 | 18 | You will get the error 19 | 20 | ``` 21 | TypeError: sound_player_1.default is not a constructor 22 | ``` 23 | 24 | because `soundPlayer.default` does not point to a function. Your mock has to return an object which has a property default 25 | that points to a function. 26 | 27 | ```ts title="my-mocks.ts" 28 | jest.mock('./sound-player', () => { 29 | return { 30 | default: jest.fn().mockImplementation(() => { 31 | return { 32 | playSoundFile: mockPlaySoundFile, 33 | } 34 | }), 35 | } 36 | }) 37 | ``` 38 | 39 | For named imports, like `import { OAuth2 } from './oauth'`, replace `default` with imported module name, `OAuth2` in this example: 40 | 41 | ```ts title="my-mocks.ts" 42 | jest.mock('./oauth', () => { 43 | return { 44 | OAuth2: ... // mock here 45 | } 46 | }) 47 | ``` 48 | -------------------------------------------------------------------------------- /website/docs/guides/using-with-monorepo.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: using-with-monorepo 3 | title: Using with monorepo 4 | --- 5 | 6 | To use `ts-jest` in a project with monorepo structure, you'll need to use [Jest projects configuration](https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig). 7 | 8 | When using Jest `projects` configuration, Jest will run `ts-jest` against each project which is defined in the configuration. 9 | -------------------------------------------------------------------------------- /website/docs/introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: introduction 3 | title: Introduction 4 | description: A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript. 5 | slug: / 6 | --- 7 | 8 | `ts-jest` is a Jest [transformer](https://jestjs.io/docs/next/code-transformation#writing-custom-transformers) with source map support that lets you use Jest to test projects written in TypeScript. 9 | 10 | It supports all features of TypeScript including type-checking. [Read more about Babel7 + `preset-typescript` **vs** TypeScript (and `ts-jest`)](babel7-or-ts). 11 | 12 | :::important 13 | 14 | We are not doing semantic versioning and `23.10` is a re-write, run `npm i -D ts-jest@"<23.10.0"` to go back to the previous version 15 | 16 | ::: 17 | -------------------------------------------------------------------------------- /website/docs/migration.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: migration 3 | title: Migration from <=23.10 4 | --- 5 | 6 | You can use the `config:migrate` tool of `ts-jest` CLI if you're coming from an older version to help you migrate your Jest configuration. 7 | 8 | _If you're using `jest.config.js`:_ 9 | 10 | ```npm tab 11 | npx ts-jest config:migrate jest.config.js 12 | ``` 13 | 14 | ```Yarn tab 15 | yarn ts-jest config:migrate jest.config.js 16 | ``` 17 | 18 | _If you're using `jest` config property of `package.json`:_ 19 | 20 | ```npm tab 21 | npx ts-jest config:migrate package.json 22 | ``` 23 | 24 | ```Yarn tab 25 | yarn ts-jest config:migrate package.json 26 | ``` 27 | -------------------------------------------------------------------------------- /website/sidebars.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | docs: [ 3 | { 4 | type: 'category', 5 | label: 'ts-jest', 6 | items: ['introduction', 'processing', 'contributing'], 7 | }, 8 | { 9 | type: 'category', 10 | label: 'Getting Started', 11 | collapsed: false, 12 | items: [ 13 | 'getting-started/installation', 14 | 'getting-started/presets', 15 | 'getting-started/options', 16 | 'getting-started/paths-mapping', 17 | 'getting-started/version-checking', 18 | ], 19 | }, 20 | { 21 | type: 'category', 22 | label: 'Guides', 23 | collapsed: false, 24 | items: [ 25 | 'guides/esm-support', 26 | 'guides/hybrid-node-module', 27 | 'guides/mock-es6-class', 28 | 'guides/react-native', 29 | 'guides/troubleshooting', 30 | 'guides/using-with-monorepo', 31 | ], 32 | }, 33 | { 34 | type: 'doc', 35 | id: 'babel7-or-ts', 36 | }, 37 | { 38 | type: 'doc', 39 | id: 'migration', 40 | }, 41 | { 42 | type: 'doc', 43 | id: 'debugging', 44 | }, 45 | ], 46 | } 47 | -------------------------------------------------------------------------------- /website/static/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kulshekhar/ts-jest/e5bd0a1a911c7f9ef5af0c96dc967989934120d4/website/static/.nojekyll -------------------------------------------------------------------------------- /website/static/img/discord.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /website/static/img/documentation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kulshekhar/ts-jest/e5bd0a1a911c7f9ef5af0c96dc967989934120d4/website/static/img/documentation.png -------------------------------------------------------------------------------- /website/static/img/github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kulshekhar/ts-jest/e5bd0a1a911c7f9ef5af0c96dc967989934120d4/website/static/img/github.png -------------------------------------------------------------------------------- /website/static/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kulshekhar/ts-jest/e5bd0a1a911c7f9ef5af0c96dc967989934120d4/website/static/img/logo.png -------------------------------------------------------------------------------- /website/static/img/pull-request.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kulshekhar/ts-jest/e5bd0a1a911c7f9ef5af0c96dc967989934120d4/website/static/img/pull-request.png -------------------------------------------------------------------------------- /website/static/img/troubleshooting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kulshekhar/ts-jest/e5bd0a1a911c7f9ef5af0c96dc967989934120d4/website/static/img/troubleshooting.png -------------------------------------------------------------------------------- /website/static/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ts-jest", 3 | "short_name": "ts-jest", 4 | "theme_color": "#2196f3", 5 | "background_color": "#424242", 6 | "display": "standalone", 7 | "scope": "./", 8 | "start_url": "./index.html", 9 | "icons": [ 10 | { 11 | "src": "img/icons/icon-72x72.png", 12 | "sizes": "72x72", 13 | "type": "image/png" 14 | }, 15 | { 16 | "src": "img/icons/icon-96x96.png", 17 | "sizes": "96x96", 18 | "type": "image/png" 19 | }, 20 | { 21 | "src": "img/icons/icon-128x128.png", 22 | "sizes": "128x128", 23 | "type": "image/png" 24 | }, 25 | { 26 | "src": "img/icons/icon-144x144.png", 27 | "sizes": "144x144", 28 | "type": "image/png" 29 | }, 30 | { 31 | "src": "img/icons/icon-152x152.png", 32 | "sizes": "152x152", 33 | "type": "image/png" 34 | }, 35 | { 36 | "src": "img/icons/icon-192x192.png", 37 | "sizes": "192x192", 38 | "type": "image/png" 39 | }, 40 | { 41 | "src": "img/icons/icon-384x384.png", 42 | "sizes": "384x384", 43 | "type": "image/png" 44 | }, 45 | { 46 | "src": "img/icons/icon-512x512.png", 47 | "sizes": "512x512", 48 | "type": "image/png" 49 | } 50 | ] 51 | } 52 | -------------------------------------------------------------------------------- /website/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@docusaurus/tsconfig", 3 | "compilerOptions": { 4 | "baseUrl": "." 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /website/versioned_docs/version-26.5/debugging.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: debugging 3 | title: Debugging ts-jest 4 | --- 5 | 6 | You can activate the debug logger by setting the environment variable `TS_JEST_LOG` before running tests. 7 | The output of the logger will be in **ts-jest.log** in current working directory. 8 | 9 | The debug logger contains some useful information about how internal `ts-jest` works, including which files are processed, 10 | which Jest config or TypeScript config is used etc. 11 | 12 | **Linux/MacOS** 13 | 14 | ``` 15 | export TS_JEST_LOG=ts-jest.log 16 | ``` 17 | 18 | **Windows** 19 | 20 | ``` 21 | set TS_JEST_LOG=ts-jest.log 22 | ``` 23 | -------------------------------------------------------------------------------- /website/versioned_docs/version-26.5/getting-started/options/compiler.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Compiler option 3 | --- 4 | 5 | The `compiler` option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler. 6 | 7 | The default value is `typescript`, which will load the original [TypeScript compiler module](https://www.npmjs.com/package/typescript). 8 | The loaded version will depend on the one installed in your project. 9 | 10 | If you use a custom compiler, such as `ttypescript`, make sure its API is the same as the original TypeScript, at least for what `ts-jest` is using. 11 | 12 | ### Example 13 | 14 | ```js 15 | // jest.config.js 16 | module.exports = { 17 | // [...] 18 | globals: { 19 | 'ts-jest': { 20 | compiler: 'ttypescript', 21 | }, 22 | }, 23 | } 24 | ``` 25 | 26 | ```json 27 | // package.json 28 | { 29 | // [...] 30 | "jest": { 31 | "globals": { 32 | "ts-jest": { 33 | "compiler": "ttypescript" 34 | } 35 | } 36 | } 37 | } 38 | ``` 39 | -------------------------------------------------------------------------------- /website/versioned_docs/version-26.5/getting-started/version-checking.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: version-checking 3 | title: Version checking 4 | --- 5 | 6 | By default, `ts-jest` supports a range of versions for `jest`/`typescript`. One uses incompatible versions will receive a warning 7 | message while running tests. This warning message can be opt-out by setting environment variable `TS_JEST_DISABLE_VER_CHECKER`: 8 | 9 | **Linux/MacOS** 10 | 11 | ``` 12 | export TS_JEST_DISABLE_VER_CHECKER=true 13 | ``` 14 | 15 | **Windows** 16 | 17 | ``` 18 | set TS_JEST_DISABLE_VER_CHECKER=true 19 | ``` 20 | 21 | ### Note 22 | 23 | As long as the environment variable `TS_JEST_DISABLE_VER_CHECKER` stays, the warning message will no longer show. 24 | This can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions. 25 | -------------------------------------------------------------------------------- /website/versioned_docs/version-26.5/guides/esm-support.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: esm-support 3 | title: ESM Support 4 | --- 5 | 6 | :::important 7 | 8 | ESM support is only available in **v27++** 9 | 10 | ::: 11 | -------------------------------------------------------------------------------- /website/versioned_docs/version-26.5/guides/mock-es6-class.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: mock-es6-class 3 | title: Mock ES6 class 4 | --- 5 | 6 | TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import. 7 | `const soundPlayer = require('./sound-player')`. Therefore creating an instance of the class that was exported as 8 | a default will look like this: `new soundPlayer.default()`. However if you are mocking the class as suggested by the documentation. 9 | 10 | ```js 11 | jest.mock('./sound-player', () => { 12 | return jest.fn().mockImplementation(() => { 13 | return { playSoundFile: mockPlaySoundFile } 14 | }) 15 | }) 16 | ``` 17 | 18 | You will get the error 19 | 20 | ``` 21 | TypeError: sound_player_1.default is not a constructor 22 | ``` 23 | 24 | because `soundPlayer.default` does not point to a function. Your mock has to return an object which has a property default 25 | that points to a function. 26 | 27 | ```js 28 | jest.mock('./sound-player', () => { 29 | return { 30 | default: jest.fn().mockImplementation(() => { 31 | return { 32 | playSoundFile: mockPlaySoundFile, 33 | } 34 | }), 35 | } 36 | }) 37 | ``` 38 | 39 | For named imports, like `import { OAuth2 } from './oauth'`, replace `default` with imported module name, `OAuth2` in this example: 40 | 41 | ```js 42 | jest.mock('./oauth', () => { 43 | return { 44 | OAuth2: ... // mock here 45 | } 46 | }) 47 | ``` 48 | -------------------------------------------------------------------------------- /website/versioned_docs/version-26.5/guides/react-native.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: react-native 3 | title: Using with React Native 4 | --- 5 | 6 | To use `ts-jest` with React Native + TypeScript and Babel 7, you'll first need to follow [this tutorial](https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native). 7 | 8 | After that, some little modifications will be required as follows: 9 | 10 | ### Babel config 11 | 12 | If you didn't yet, move any Babel config from `.babelrc` to `babel.config.js`. It should at least contain: 13 | 14 | ```js 15 | // babel.config.js 16 | module.exports = { 17 | presets: ['module:metro-react-native-babel-preset'], 18 | } 19 | ``` 20 | 21 | ### TypeScript Configuration 22 | 23 | Create a new `tsconfig.spec.json` at the root of your project with the following content 24 | 25 | ```json 26 | // tsconfig.spec.json 27 | { 28 | "extends": "./tsconfig.json", 29 | "compilerOptions": { 30 | "jsx": "react" 31 | } 32 | } 33 | ``` 34 | 35 | ### Jest config 36 | 37 | In the same way that you moved Babel config, move Jest config from `jest` key of `package.json` to `jest.config.js`. It should look like this: 38 | 39 | ```js 40 | // jest.config.js 41 | module.exports = { 42 | preset: 'react-native', 43 | globals: { 44 | 'ts-jest': { 45 | tsconfig: 'tsconfig.spec.json', 46 | }, 47 | }, 48 | transform: { 49 | '^.+\\.jsx$': 'babel-jest', 50 | '^.+\\.tsx?$': 'ts-jest', 51 | }, 52 | moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], 53 | } 54 | ``` 55 | -------------------------------------------------------------------------------- /website/versioned_docs/version-26.5/guides/using-with-monorepo.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: using-with-monorepo 3 | title: Using with monorepo 4 | --- 5 | 6 | To use `ts-jest` in a project with monorepo structure, you'll need to use [Jest projects configuration](https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig). 7 | 8 | When using Jest `projects` configuration, Jest will run `ts-jest` against each project which is defined in the configuration. 9 | 10 | One should not be confused between the term **monorepo** vs TypeScript **project references**. These are 2 different terms. 11 | -------------------------------------------------------------------------------- /website/versioned_docs/version-26.5/introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: introduction 3 | title: Introduction 4 | description: A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript. 5 | slug: / 6 | --- 7 | 8 | `ts-jest` is a Jest [transformer](https://jestjs.io/docs/next/code-transformation#writing-custom-transformers) with source map support that lets you use Jest to test projects written in TypeScript. 9 | 10 | It supports all features of TypeScript including type-checking. [Read more about Babel7 + `preset-typescript` **vs** TypeScript (and `ts-jest`)](babel7-or-ts). 11 | 12 | :::important 13 | 14 | We are not doing semantic versioning and `23.10` is a re-write, run `npm i -D ts-jest@"<23.10.0"` to go back to the previous version 15 | 16 | ::: 17 | -------------------------------------------------------------------------------- /website/versioned_docs/version-26.5/migration.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: migration 3 | title: Migration from <=23.10 4 | --- 5 | 6 | You can use the `config:migrate` tool of `ts-jest` CLI if you're coming from an older version to help you migrate your Jest configuration. 7 | 8 | _If you're using `jest.config.js`:_ 9 | 10 | ### NPM 11 | 12 | ```sh 13 | npx ts-jest config:migrate jest.config.js 14 | ``` 15 | 16 | ### Yarn 17 | 18 | ```sh 19 | yarn ts-jest config:migrate jest.config.js 20 | ``` 21 | 22 | _If you're using `jest` config property of `package.json`:_ 23 | 24 | ### NPM 25 | 26 | ```sh 27 | npx ts-jest config:migrate package.json 28 | ``` 29 | 30 | ### Yarn 31 | 32 | ```sh 33 | yarn ts-jest config:migrate package.json 34 | ``` 35 | -------------------------------------------------------------------------------- /website/versioned_docs/version-27.0/debugging.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: debugging 3 | title: Debugging ts-jest 4 | --- 5 | 6 | You can activate the debug logger by setting the environment variable `TS_JEST_LOG` before running tests. 7 | The output of the logger will be in **ts-jest.log** in current working directory. 8 | 9 | The debug logger contains some useful information about how internal `ts-jest` works, including which files are processed, 10 | which Jest config or TypeScript config is used etc. 11 | 12 | **Linux/MacOS** 13 | 14 | ``` 15 | export TS_JEST_LOG=ts-jest.log 16 | ``` 17 | 18 | **Windows** 19 | 20 | ``` 21 | set TS_JEST_LOG=ts-jest.log 22 | ``` 23 | -------------------------------------------------------------------------------- /website/versioned_docs/version-27.0/getting-started/options/compiler.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Compiler option 3 | --- 4 | 5 | The `compiler` option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler. 6 | 7 | The default value is `typescript`, which will load the original [TypeScript compiler module](https://www.npmjs.com/package/typescript). 8 | The loaded version will depend on the one installed in your project. 9 | 10 | If you use a custom compiler, such as `ttypescript`, make sure its API is the same as the original TypeScript, at least for what `ts-jest` is using. 11 | 12 | ### Example 13 | 14 | ```js 15 | // jest.config.js 16 | module.exports = { 17 | // [...] 18 | globals: { 19 | 'ts-jest': { 20 | compiler: 'ttypescript', 21 | }, 22 | }, 23 | } 24 | ``` 25 | 26 | ```json 27 | // package.json 28 | { 29 | // [...] 30 | "jest": { 31 | "globals": { 32 | "ts-jest": { 33 | "compiler": "ttypescript" 34 | } 35 | } 36 | } 37 | } 38 | ``` 39 | -------------------------------------------------------------------------------- /website/versioned_docs/version-27.0/getting-started/options/useESM.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: useESM option 3 | --- 4 | 5 | The `useESM` option allows `ts-jest` to transform codes to ESM syntax **if possible**. 6 | 7 | The default value is **false**, `ts-jest` will transform codes to `CommonJS` syntax. 8 | 9 | ### Examples 10 | 11 | ```js 12 | // jest.config.js 13 | module.exports = { 14 | // [...] 15 | globals: { 16 | 'ts-jest': { 17 | useESM: true, 18 | }, 19 | }, 20 | } 21 | ``` 22 | 23 | ```json 24 | // package.json 25 | { 26 | // [...] 27 | "jest": { 28 | "globals": { 29 | "ts-jest": { 30 | "useESM": true 31 | } 32 | } 33 | } 34 | } 35 | ``` 36 | -------------------------------------------------------------------------------- /website/versioned_docs/version-27.0/getting-started/version-checking.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: version-checking 3 | title: Version checking 4 | --- 5 | 6 | By default, `ts-jest` supports a range of versions for `jest`/`typescript`. One uses incompatible versions will receive a warning 7 | message while running tests. This warning message can be opt-out by setting environment variable `TS_JEST_DISABLE_VER_CHECKER`: 8 | 9 | **Linux/MacOS** 10 | 11 | ``` 12 | export TS_JEST_DISABLE_VER_CHECKER=true 13 | ``` 14 | 15 | **Windows** 16 | 17 | ``` 18 | set TS_JEST_DISABLE_VER_CHECKER=true 19 | ``` 20 | 21 | ### Note 22 | 23 | As long as the environment variable `TS_JEST_DISABLE_VER_CHECKER` stays, the warning message will no longer show. 24 | This can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions. 25 | -------------------------------------------------------------------------------- /website/versioned_docs/version-27.0/guides/mock-es6-class.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: mock-es6-class 3 | title: Mock ES6 class 4 | --- 5 | 6 | TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import. 7 | `const soundPlayer = require('./sound-player')`. Therefore creating an instance of the class that was exported as 8 | a default will look like this: `new soundPlayer.default()`. However if you are mocking the class as suggested by the documentation. 9 | 10 | ```js 11 | jest.mock('./sound-player', () => { 12 | return jest.fn().mockImplementation(() => { 13 | return { playSoundFile: mockPlaySoundFile } 14 | }) 15 | }) 16 | ``` 17 | 18 | You will get the error 19 | 20 | ``` 21 | TypeError: sound_player_1.default is not a constructor 22 | ``` 23 | 24 | because `soundPlayer.default` does not point to a function. Your mock has to return an object which has a property default 25 | that points to a function. 26 | 27 | ```js 28 | jest.mock('./sound-player', () => { 29 | return { 30 | default: jest.fn().mockImplementation(() => { 31 | return { 32 | playSoundFile: mockPlaySoundFile, 33 | } 34 | }), 35 | } 36 | }) 37 | ``` 38 | 39 | For named imports, like `import { OAuth2 } from './oauth'`, replace `default` with imported module name, `OAuth2` in this example: 40 | 41 | ```js 42 | jest.mock('./oauth', () => { 43 | return { 44 | OAuth2: ... // mock here 45 | } 46 | }) 47 | ``` 48 | -------------------------------------------------------------------------------- /website/versioned_docs/version-27.0/guides/react-native.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: react-native 3 | title: Using with React Native 4 | --- 5 | 6 | To use `ts-jest` with React Native + TypeScript and Babel 7, you'll first need to follow [this tutorial](https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native). 7 | 8 | After that, some little modifications will be required as follows: 9 | 10 | ### Babel config 11 | 12 | If you didn't yet, move any Babel config from `.babelrc` to `babel.config.js`. It should at least contain: 13 | 14 | ```js 15 | // babel.config.js 16 | module.exports = { 17 | presets: ['module:metro-react-native-babel-preset'], 18 | } 19 | ``` 20 | 21 | ### TypeScript Configuration 22 | 23 | Create a new `tsconfig.spec.json` at the root of your project with the following content 24 | 25 | ```json 26 | // tsconfig.spec.json 27 | { 28 | "extends": "./tsconfig.json", 29 | "compilerOptions": { 30 | "jsx": "react" 31 | } 32 | } 33 | ``` 34 | 35 | ### Jest config 36 | 37 | In the same way that you moved Babel config, move Jest config from `jest` key of `package.json` to `jest.config.js`. It should look like this: 38 | 39 | ```js 40 | // jest.config.js 41 | module.exports = { 42 | preset: 'react-native', 43 | globals: { 44 | 'ts-jest': { 45 | tsconfig: 'tsconfig.spec.json', 46 | }, 47 | }, 48 | transform: { 49 | '^.+\\.jsx$': 'babel-jest', 50 | '^.+\\.tsx?$': 'ts-jest', 51 | }, 52 | moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], 53 | } 54 | ``` 55 | -------------------------------------------------------------------------------- /website/versioned_docs/version-27.0/guides/using-with-monorepo.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: using-with-monorepo 3 | title: Using with monorepo 4 | --- 5 | 6 | To use `ts-jest` in a project with monorepo structure, you'll need to use [Jest projects configuration](https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig). 7 | 8 | When using Jest `projects` configuration, Jest will run `ts-jest` against each project which is defined in the configuration. 9 | -------------------------------------------------------------------------------- /website/versioned_docs/version-27.0/introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: introduction 3 | title: Introduction 4 | description: A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript. 5 | slug: / 6 | --- 7 | 8 | `ts-jest` is a Jest [transformer](https://jestjs.io/docs/next/code-transformation#writing-custom-transformers) with source map support that lets you use Jest to test projects written in TypeScript. 9 | 10 | It supports all features of TypeScript including type-checking. [Read more about Babel7 + `preset-typescript` **vs** TypeScript (and `ts-jest`)](babel7-or-ts). 11 | 12 | :::important 13 | 14 | We are not doing semantic versioning and `23.10` is a re-write, run `npm i -D ts-jest@"<23.10.0"` to go back to the previous version 15 | 16 | ::: 17 | -------------------------------------------------------------------------------- /website/versioned_docs/version-27.0/migration.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: migration 3 | title: Migration from <=23.10 4 | --- 5 | 6 | You can use the `config:migrate` tool of `ts-jest` CLI if you're coming from an older version to help you migrate your Jest configuration. 7 | 8 | _If you're using `jest.config.js`:_ 9 | 10 | ### NPM 11 | 12 | ```sh 13 | npx ts-jest config:migrate jest.config.js 14 | ``` 15 | 16 | ### Yarn 17 | 18 | ```sh 19 | yarn ts-jest config:migrate jest.config.js 20 | ``` 21 | 22 | _If you're using `jest` config property of `package.json`:_ 23 | 24 | ### NPM 25 | 26 | ```sh 27 | npx ts-jest config:migrate package.json 28 | ``` 29 | 30 | ### Yarn 31 | 32 | ```sh 33 | yarn ts-jest config:migrate package.json 34 | ``` 35 | -------------------------------------------------------------------------------- /website/versioned_docs/version-27.1/debugging.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: debugging 3 | title: Debugging ts-jest 4 | --- 5 | 6 | You can activate the debug logger by setting the environment variable `TS_JEST_LOG` before running tests. 7 | The output of the logger will be in **ts-jest.log** in current working directory. 8 | 9 | The debug logger contains some useful information about how internal `ts-jest` works, including which files are processed, 10 | which Jest config or TypeScript config is used etc. 11 | 12 | **Linux/MacOS** 13 | 14 | ``` 15 | export TS_JEST_LOG=ts-jest.log 16 | ``` 17 | 18 | **Windows** 19 | 20 | ``` 21 | set TS_JEST_LOG=ts-jest.log 22 | ``` 23 | -------------------------------------------------------------------------------- /website/versioned_docs/version-27.1/getting-started/options/compiler.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Compiler option 3 | --- 4 | 5 | The `compiler` option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler. 6 | 7 | The default value is `typescript`, which will load the original [TypeScript compiler module](https://www.npmjs.com/package/typescript). 8 | The loaded version will depend on the one installed in your project. 9 | 10 | If you use a custom compiler, such as `ttypescript`, make sure its API is the same as the original TypeScript, at least for what `ts-jest` is using. 11 | 12 | ### Example 13 | 14 | ```js 15 | // jest.config.js 16 | module.exports = { 17 | // [...] 18 | globals: { 19 | 'ts-jest': { 20 | compiler: 'ttypescript', 21 | }, 22 | }, 23 | } 24 | ``` 25 | 26 | ```json 27 | // package.json 28 | { 29 | // [...] 30 | "jest": { 31 | "globals": { 32 | "ts-jest": { 33 | "compiler": "ttypescript" 34 | } 35 | } 36 | } 37 | } 38 | ``` 39 | -------------------------------------------------------------------------------- /website/versioned_docs/version-27.1/getting-started/options/useESM.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: useESM option 3 | --- 4 | 5 | The `useESM` option allows `ts-jest` to transform codes to ESM syntax **if possible**. 6 | 7 | The default value is **false**, `ts-jest` will transform codes to `CommonJS` syntax. 8 | 9 | ### Examples 10 | 11 | ```js 12 | // jest.config.js 13 | module.exports = { 14 | // [...] 15 | globals: { 16 | 'ts-jest': { 17 | useESM: true, 18 | }, 19 | }, 20 | } 21 | ``` 22 | 23 | ```json 24 | // package.json 25 | { 26 | // [...] 27 | "jest": { 28 | "globals": { 29 | "ts-jest": { 30 | "useESM": true 31 | } 32 | } 33 | } 34 | } 35 | ``` 36 | -------------------------------------------------------------------------------- /website/versioned_docs/version-27.1/getting-started/version-checking.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: version-checking 3 | title: Version checking 4 | --- 5 | 6 | By default, `ts-jest` supports a range of versions for `jest`/`typescript`. One uses incompatible versions will receive a warning 7 | message while running tests. This warning message can be opt-out by setting environment variable `TS_JEST_DISABLE_VER_CHECKER`: 8 | 9 | **Linux/MacOS** 10 | 11 | ``` 12 | export TS_JEST_DISABLE_VER_CHECKER=true 13 | ``` 14 | 15 | **Windows** 16 | 17 | ``` 18 | set TS_JEST_DISABLE_VER_CHECKER=true 19 | ``` 20 | 21 | ### Note 22 | 23 | As long as the environment variable `TS_JEST_DISABLE_VER_CHECKER` stays, the warning message will no longer show. 24 | This can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions. 25 | -------------------------------------------------------------------------------- /website/versioned_docs/version-27.1/guides/mock-es6-class.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: mock-es6-class 3 | title: Mock ES6 class 4 | --- 5 | 6 | TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import. 7 | `const soundPlayer = require('./sound-player')`. Therefore creating an instance of the class that was exported as 8 | a default will look like this: `new soundPlayer.default()`. However if you are mocking the class as suggested by the documentation. 9 | 10 | ```js 11 | jest.mock('./sound-player', () => { 12 | return jest.fn().mockImplementation(() => { 13 | return { playSoundFile: mockPlaySoundFile } 14 | }) 15 | }) 16 | ``` 17 | 18 | You will get the error 19 | 20 | ``` 21 | TypeError: sound_player_1.default is not a constructor 22 | ``` 23 | 24 | because `soundPlayer.default` does not point to a function. Your mock has to return an object which has a property default 25 | that points to a function. 26 | 27 | ```js 28 | jest.mock('./sound-player', () => { 29 | return { 30 | default: jest.fn().mockImplementation(() => { 31 | return { 32 | playSoundFile: mockPlaySoundFile, 33 | } 34 | }), 35 | } 36 | }) 37 | ``` 38 | 39 | For named imports, like `import { OAuth2 } from './oauth'`, replace `default` with imported module name, `OAuth2` in this example: 40 | 41 | ```js 42 | jest.mock('./oauth', () => { 43 | return { 44 | OAuth2: ... // mock here 45 | } 46 | }) 47 | ``` 48 | -------------------------------------------------------------------------------- /website/versioned_docs/version-27.1/guides/using-with-monorepo.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: using-with-monorepo 3 | title: Using with monorepo 4 | --- 5 | 6 | To use `ts-jest` in a project with monorepo structure, you'll need to use [Jest projects configuration](https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig). 7 | 8 | When using Jest `projects` configuration, Jest will run `ts-jest` against each project which is defined in the configuration. 9 | -------------------------------------------------------------------------------- /website/versioned_docs/version-27.1/introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: introduction 3 | title: Introduction 4 | description: A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript. 5 | slug: / 6 | --- 7 | 8 | `ts-jest` is a Jest [transformer](https://jestjs.io/docs/next/code-transformation#writing-custom-transformers) with source map support that lets you use Jest to test projects written in TypeScript. 9 | 10 | It supports all features of TypeScript including type-checking. [Read more about Babel7 + `preset-typescript` **vs** TypeScript (and `ts-jest`)](babel7-or-ts). 11 | 12 | :::important 13 | 14 | We are not doing semantic versioning and `23.10` is a re-write, run `npm i -D ts-jest@"<23.10.0"` to go back to the previous version 15 | 16 | ::: 17 | -------------------------------------------------------------------------------- /website/versioned_docs/version-27.1/migration.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: migration 3 | title: Migration from <=23.10 4 | --- 5 | 6 | You can use the `config:migrate` tool of `ts-jest` CLI if you're coming from an older version to help you migrate your Jest configuration. 7 | 8 | _If you're using `jest.config.js`:_ 9 | 10 | ### NPM 11 | 12 | ```sh 13 | npx ts-jest config:migrate jest.config.js 14 | ``` 15 | 16 | ### Yarn 17 | 18 | ```sh 19 | yarn ts-jest config:migrate jest.config.js 20 | ``` 21 | 22 | _If you're using `jest` config property of `package.json`:_ 23 | 24 | ### NPM 25 | 26 | ```sh 27 | npx ts-jest config:migrate package.json 28 | ``` 29 | 30 | ### Yarn 31 | 32 | ```sh 33 | yarn ts-jest config:migrate package.json 34 | ``` 35 | -------------------------------------------------------------------------------- /website/versioned_docs/version-28.0/debugging.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: debugging 3 | title: Debugging ts-jest 4 | --- 5 | 6 | You can activate the debug logger by setting the environment variable `TS_JEST_LOG` before running tests. 7 | The output of the logger will be in **ts-jest.log** in current working directory. 8 | 9 | The debug logger contains some useful information about how internal `ts-jest` works, including which files are processed, 10 | which Jest config or TypeScript config is used etc. 11 | 12 | **Linux/MacOS** 13 | 14 | ``` 15 | export TS_JEST_LOG=ts-jest.log 16 | ``` 17 | 18 | **Windows** 19 | 20 | Command Prompt (cmd) 21 | 22 | ``` 23 | set TS_JEST_LOG=ts-jest.log 24 | ``` 25 | 26 | PowerShell 27 | 28 | ``` 29 | $env:TS_JEST_LOG = 'ts-jest.log' 30 | ``` 31 | -------------------------------------------------------------------------------- /website/versioned_docs/version-28.0/getting-started/options/compiler.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Compiler option 3 | --- 4 | 5 | The `compiler` option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler. 6 | 7 | The default value is `typescript`, which will load the original [TypeScript compiler module](https://www.npmjs.com/package/typescript). 8 | The loaded version will depend on the one installed in your project. 9 | 10 | If you use a custom compiler, such as `ttypescript`, make sure its API is the same as the original TypeScript, at least for what `ts-jest` is using. 11 | 12 | ### Example 13 | 14 | ```js 15 | // jest.config.js 16 | module.exports = { 17 | // [...] 18 | globals: { 19 | 'ts-jest': { 20 | compiler: 'ttypescript', 21 | }, 22 | }, 23 | } 24 | ``` 25 | 26 | ```json 27 | // package.json 28 | { 29 | // [...] 30 | "jest": { 31 | "globals": { 32 | "ts-jest": { 33 | "compiler": "ttypescript" 34 | } 35 | } 36 | } 37 | } 38 | ``` 39 | -------------------------------------------------------------------------------- /website/versioned_docs/version-28.0/getting-started/options/useESM.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: useESM option 3 | --- 4 | 5 | The `useESM` option allows `ts-jest` to transform codes to ESM syntax **if possible**. 6 | 7 | The default value is **false**, `ts-jest` will transform codes to `CommonJS` syntax. 8 | 9 | ### Examples 10 | 11 | ```js 12 | // jest.config.js 13 | module.exports = { 14 | // [...] 15 | globals: { 16 | 'ts-jest': { 17 | useESM: true, 18 | }, 19 | }, 20 | } 21 | ``` 22 | 23 | ```json 24 | // package.json 25 | { 26 | // [...] 27 | "jest": { 28 | "globals": { 29 | "ts-jest": { 30 | "useESM": true 31 | } 32 | } 33 | } 34 | } 35 | ``` 36 | -------------------------------------------------------------------------------- /website/versioned_docs/version-28.0/getting-started/version-checking.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: version-checking 3 | title: Version checking 4 | --- 5 | 6 | By default, `ts-jest` supports a range of versions for `jest`/`typescript`. One uses incompatible versions will receive a warning 7 | message while running tests. This warning message can be opt-out by setting environment variable `TS_JEST_DISABLE_VER_CHECKER`: 8 | 9 | **Linux/MacOS** 10 | 11 | ``` 12 | export TS_JEST_DISABLE_VER_CHECKER=true 13 | ``` 14 | 15 | **Windows** 16 | 17 | ``` 18 | set TS_JEST_DISABLE_VER_CHECKER=true 19 | ``` 20 | 21 | ### Note 22 | 23 | As long as the environment variable `TS_JEST_DISABLE_VER_CHECKER` stays, the warning message will no longer show. 24 | This can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions. 25 | -------------------------------------------------------------------------------- /website/versioned_docs/version-28.0/guides/mock-es6-class.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: mock-es6-class 3 | title: Mock ES6 class 4 | --- 5 | 6 | TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import. 7 | `const soundPlayer = require('./sound-player')`. Therefore creating an instance of the class that was exported as 8 | a default will look like this: `new soundPlayer.default()`. However if you are mocking the class as suggested by the documentation. 9 | 10 | ```js 11 | jest.mock('./sound-player', () => { 12 | return jest.fn().mockImplementation(() => { 13 | return { playSoundFile: mockPlaySoundFile } 14 | }) 15 | }) 16 | ``` 17 | 18 | You will get the error 19 | 20 | ``` 21 | TypeError: sound_player_1.default is not a constructor 22 | ``` 23 | 24 | because `soundPlayer.default` does not point to a function. Your mock has to return an object which has a property default 25 | that points to a function. 26 | 27 | ```js 28 | jest.mock('./sound-player', () => { 29 | return { 30 | default: jest.fn().mockImplementation(() => { 31 | return { 32 | playSoundFile: mockPlaySoundFile, 33 | } 34 | }), 35 | } 36 | }) 37 | ``` 38 | 39 | For named imports, like `import { OAuth2 } from './oauth'`, replace `default` with imported module name, `OAuth2` in this example: 40 | 41 | ```js 42 | jest.mock('./oauth', () => { 43 | return { 44 | OAuth2: ... // mock here 45 | } 46 | }) 47 | ``` 48 | -------------------------------------------------------------------------------- /website/versioned_docs/version-28.0/guides/using-with-monorepo.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: using-with-monorepo 3 | title: Using with monorepo 4 | --- 5 | 6 | To use `ts-jest` in a project with monorepo structure, you'll need to use [Jest projects configuration](https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig). 7 | 8 | When using Jest `projects` configuration, Jest will run `ts-jest` against each project which is defined in the configuration. 9 | -------------------------------------------------------------------------------- /website/versioned_docs/version-28.0/introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: introduction 3 | title: Introduction 4 | description: A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript. 5 | slug: / 6 | --- 7 | 8 | `ts-jest` is a Jest [transformer](https://jestjs.io/docs/next/code-transformation#writing-custom-transformers) with source map support that lets you use Jest to test projects written in TypeScript. 9 | 10 | It supports all features of TypeScript including type-checking. [Read more about Babel7 + `preset-typescript` **vs** TypeScript (and `ts-jest`)](babel7-or-ts). 11 | 12 | :::important 13 | 14 | We are not doing semantic versioning and `23.10` is a re-write, run `npm i -D ts-jest@"<23.10.0"` to go back to the previous version 15 | 16 | ::: 17 | -------------------------------------------------------------------------------- /website/versioned_docs/version-28.0/migration.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: migration 3 | title: Migration from <=23.10 4 | --- 5 | 6 | You can use the `config:migrate` tool of `ts-jest` CLI if you're coming from an older version to help you migrate your Jest configuration. 7 | 8 | _If you're using `jest.config.js`:_ 9 | 10 | ### NPM 11 | 12 | ```sh 13 | npx ts-jest config:migrate jest.config.js 14 | ``` 15 | 16 | ### Yarn 17 | 18 | ```sh 19 | yarn ts-jest config:migrate jest.config.js 20 | ``` 21 | 22 | _If you're using `jest` config property of `package.json`:_ 23 | 24 | ### NPM 25 | 26 | ```sh 27 | npx ts-jest config:migrate package.json 28 | ``` 29 | 30 | ### Yarn 31 | 32 | ```sh 33 | yarn ts-jest config:migrate package.json 34 | ``` 35 | -------------------------------------------------------------------------------- /website/versioned_docs/version-29.0/debugging.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: debugging 3 | title: Debugging ts-jest 4 | --- 5 | 6 | You can activate the debug logger by setting the environment variable `TS_JEST_LOG` before running tests. 7 | The output of the logger will be in **ts-jest.log** in current working directory. 8 | 9 | The debug logger contains some useful information about how internal `ts-jest` works, including which files are processed, 10 | which Jest config or TypeScript config is used etc. 11 | 12 | **Linux/MacOS** 13 | 14 | ``` 15 | export TS_JEST_LOG=ts-jest.log 16 | ``` 17 | 18 | **Windows** 19 | 20 | ```Command Prompt tab 21 | set TS_JEST_LOG=ts-jest.log 22 | ``` 23 | 24 | ```PowerShell tab 25 | $env:TS_JEST_LOG = 'ts-jest.log' 26 | ``` 27 | -------------------------------------------------------------------------------- /website/versioned_docs/version-29.0/getting-started/version-checking.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: version-checking 3 | title: Version checking 4 | --- 5 | 6 | By default, `ts-jest` supports a range of versions for `jest`/`typescript`. One uses incompatible versions will receive a warning 7 | message while running tests. This warning message can be opt-out by setting environment variable `TS_JEST_DISABLE_VER_CHECKER`: 8 | 9 | **Linux/MacOS** 10 | 11 | ``` 12 | export TS_JEST_DISABLE_VER_CHECKER=true 13 | ``` 14 | 15 | **Windows** 16 | 17 | ``` 18 | set TS_JEST_DISABLE_VER_CHECKER=true 19 | ``` 20 | 21 | ### Note 22 | 23 | As long as the environment variable `TS_JEST_DISABLE_VER_CHECKER` stays, the warning message will no longer show. 24 | This can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions. 25 | -------------------------------------------------------------------------------- /website/versioned_docs/version-29.0/guides/using-with-monorepo.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: using-with-monorepo 3 | title: Using with monorepo 4 | --- 5 | 6 | To use `ts-jest` in a project with monorepo structure, you'll need to use [Jest projects configuration](https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig). 7 | 8 | When using Jest `projects` configuration, Jest will run `ts-jest` against each project which is defined in the configuration. 9 | -------------------------------------------------------------------------------- /website/versioned_docs/version-29.0/introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: introduction 3 | title: Introduction 4 | description: A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript. 5 | slug: / 6 | --- 7 | 8 | `ts-jest` is a Jest [transformer](https://jestjs.io/docs/next/code-transformation#writing-custom-transformers) with source map support that lets you use Jest to test projects written in TypeScript. 9 | 10 | It supports all features of TypeScript including type-checking. [Read more about Babel7 + `preset-typescript` **vs** TypeScript (and `ts-jest`)](babel7-or-ts). 11 | 12 | :::important 13 | 14 | We are not doing semantic versioning and `23.10` is a re-write, run `npm i -D ts-jest@"<23.10.0"` to go back to the previous version 15 | 16 | ::: 17 | -------------------------------------------------------------------------------- /website/versioned_docs/version-29.0/migration.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: migration 3 | title: Migration from <=23.10 4 | --- 5 | 6 | You can use the `config:migrate` tool of `ts-jest` CLI if you're coming from an older version to help you migrate your Jest configuration. 7 | 8 | _If you're using `jest.config.js`:_ 9 | 10 | ```npm tab 11 | npx ts-jest config:migrate jest.config.js 12 | ``` 13 | 14 | ```Yarn tab 15 | yarn ts-jest config:migrate jest.config.js 16 | ``` 17 | 18 | _If you're using `jest` config property of `package.json`:_ 19 | 20 | ```npm tab 21 | npx ts-jest config:migrate package.json 22 | ``` 23 | 24 | ```Yarn tab 25 | yarn ts-jest config:migrate package.json 26 | ``` 27 | -------------------------------------------------------------------------------- /website/versioned_docs/version-29.2/debugging.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: debugging 3 | title: Debugging ts-jest 4 | --- 5 | 6 | You can activate the debug logger by setting the environment variable `TS_JEST_LOG` before running tests. 7 | The output of the logger will be in **ts-jest.log** in current working directory. 8 | 9 | The debug logger contains some useful information about how internal `ts-jest` works, including which files are processed, 10 | which Jest config or TypeScript config is used etc. 11 | 12 | **Linux/MacOS** 13 | 14 | ``` 15 | export TS_JEST_LOG=ts-jest.log 16 | ``` 17 | 18 | **Windows** 19 | 20 | ```Command Prompt tab 21 | set TS_JEST_LOG=ts-jest.log 22 | ``` 23 | 24 | ```PowerShell tab 25 | $env:TS_JEST_LOG = 'ts-jest.log' 26 | ``` 27 | -------------------------------------------------------------------------------- /website/versioned_docs/version-29.2/getting-started/version-checking.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: version-checking 3 | title: Version checking 4 | --- 5 | 6 | By default, `ts-jest` supports a range of versions for `jest`/`typescript`. One uses incompatible versions will receive a warning 7 | message while running tests. This warning message can be opt-out by setting environment variable `TS_JEST_DISABLE_VER_CHECKER`: 8 | 9 | **Linux/MacOS** 10 | 11 | ``` 12 | export TS_JEST_DISABLE_VER_CHECKER=true 13 | ``` 14 | 15 | **Windows** 16 | 17 | ``` 18 | set TS_JEST_DISABLE_VER_CHECKER=true 19 | ``` 20 | 21 | ### Note 22 | 23 | As long as the environment variable `TS_JEST_DISABLE_VER_CHECKER` stays, the warning message will no longer show. 24 | This can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions. 25 | -------------------------------------------------------------------------------- /website/versioned_docs/version-29.2/guides/using-with-monorepo.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: using-with-monorepo 3 | title: Using with monorepo 4 | --- 5 | 6 | To use `ts-jest` in a project with monorepo structure, you'll need to use [Jest projects configuration](https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig). 7 | 8 | When using Jest `projects` configuration, Jest will run `ts-jest` against each project which is defined in the configuration. 9 | -------------------------------------------------------------------------------- /website/versioned_docs/version-29.2/introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: introduction 3 | title: Introduction 4 | description: A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript. 5 | slug: / 6 | --- 7 | 8 | `ts-jest` is a Jest [transformer](https://jestjs.io/docs/next/code-transformation#writing-custom-transformers) with source map support that lets you use Jest to test projects written in TypeScript. 9 | 10 | It supports all features of TypeScript including type-checking. [Read more about Babel7 + `preset-typescript` **vs** TypeScript (and `ts-jest`)](babel7-or-ts). 11 | 12 | :::important 13 | 14 | We are not doing semantic versioning and `23.10` is a re-write, run `npm i -D ts-jest@"<23.10.0"` to go back to the previous version 15 | 16 | ::: 17 | -------------------------------------------------------------------------------- /website/versioned_docs/version-29.2/migration.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: migration 3 | title: Migration from <=23.10 4 | --- 5 | 6 | You can use the `config:migrate` tool of `ts-jest` CLI if you're coming from an older version to help you migrate your Jest configuration. 7 | 8 | _If you're using `jest.config.js`:_ 9 | 10 | ```npm tab 11 | npx ts-jest config:migrate jest.config.js 12 | ``` 13 | 14 | ```Yarn tab 15 | yarn ts-jest config:migrate jest.config.js 16 | ``` 17 | 18 | _If you're using `jest` config property of `package.json`:_ 19 | 20 | ```npm tab 21 | npx ts-jest config:migrate package.json 22 | ``` 23 | 24 | ```Yarn tab 25 | yarn ts-jest config:migrate package.json 26 | ``` 27 | -------------------------------------------------------------------------------- /website/versioned_docs/version-29.3/debugging.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: debugging 3 | title: Debugging ts-jest 4 | --- 5 | 6 | You can activate the debug logger by setting the environment variable `TS_JEST_LOG` before running tests. 7 | The output of the logger will be in **ts-jest.log** in current working directory. 8 | 9 | The debug logger contains some useful information about how internal `ts-jest` works, including which files are processed, 10 | which Jest config or TypeScript config is used etc. 11 | 12 | **Linux/MacOS** 13 | 14 | ``` 15 | export TS_JEST_LOG=ts-jest.log 16 | ``` 17 | 18 | **Windows** 19 | 20 | ```Command Prompt tab 21 | set TS_JEST_LOG=ts-jest.log 22 | ``` 23 | 24 | ```PowerShell tab 25 | $env:TS_JEST_LOG = 'ts-jest.log' 26 | ``` 27 | -------------------------------------------------------------------------------- /website/versioned_docs/version-29.3/getting-started/options/compiler.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Compiler option 3 | --- 4 | 5 | The `compiler` option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler. 6 | 7 | The default value is `typescript`, which will load the original [TypeScript compiler module](https://www.npmjs.com/package/typescript). 8 | The loaded version will depend on the one installed in your project. 9 | 10 | If you use a custom compiler, such as `ttypescript`, make sure its API is the same as the original TypeScript, at least for what `ts-jest` is using. 11 | 12 | ### Example 13 | 14 | ```ts title="jest.config.ts" 15 | import type { Config } from 'jest' 16 | 17 | const jestConfig: Config = { 18 | // [...] 19 | transform: { 20 | // '^.+\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest` 21 | // '^.+\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest` 22 | '^.+\\.tsx?$': [ 23 | 'ts-jest', 24 | { 25 | compiler: 'ttypescript', 26 | }, 27 | ], 28 | }, 29 | } 30 | 31 | export default jestConfig 32 | ``` 33 | -------------------------------------------------------------------------------- /website/versioned_docs/version-29.3/getting-started/options/useESM.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: useESM option 3 | --- 4 | 5 | The `useESM` option allows `ts-jest` to transform codes to ESM syntax **if possible**. 6 | 7 | The default value is **false**, `ts-jest` will transform codes to `CommonJS` syntax. 8 | 9 | :::tip 10 | 11 | See more about ESM support in [dedicated guide](../../guides/esm-support.md) 12 | 13 | ::: 14 | 15 | ### Examples 16 | 17 | ```ts title="jest.config.ts" 18 | import type { Config } from 'jest' 19 | 20 | const jestConfig: Config = { 21 | // [...] 22 | transform: { 23 | // '^.+\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest` 24 | // '^.+\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest` 25 | '^.+\\.tsx?$': [ 26 | 'ts-jest', 27 | { 28 | useESM: true, 29 | }, 30 | ], 31 | }, 32 | } 33 | 34 | export default jestConfig 35 | ``` 36 | -------------------------------------------------------------------------------- /website/versioned_docs/version-29.3/getting-started/version-checking.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: version-checking 3 | title: Version checking 4 | --- 5 | 6 | :::warning DEPRECATED 7 | 8 | The version checking is **DEPRECATED** in favor of native `peerDependencies` checking mechanism in `package.json`. This page will be removed in the next major version. 9 | 10 | ::: 11 | 12 | By default, `ts-jest` supports a range of versions for `jest`/`typescript`. One uses incompatible versions will receive a warning 13 | message while running tests. This warning message can be opt-out by setting environment variable `TS_JEST_DISABLE_VER_CHECKER`: 14 | 15 | **Linux/MacOS** 16 | 17 | ``` 18 | export TS_JEST_DISABLE_VER_CHECKER=true 19 | ``` 20 | 21 | **Windows** 22 | 23 | ``` 24 | set TS_JEST_DISABLE_VER_CHECKER=true 25 | ``` 26 | 27 | ### Note 28 | 29 | As long as the environment variable `TS_JEST_DISABLE_VER_CHECKER` stays, the warning message will no longer show. 30 | This can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions. 31 | -------------------------------------------------------------------------------- /website/versioned_docs/version-29.3/guides/hybrid-node-module.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: hybrid-node-module 3 | title: Hybrid Node module 4 | --- 5 | 6 | When using hybrid node `module` values, `Node16`/`Node18`/`NodeNext`, one should read [TypeScript documentation](https://www.typescriptlang.org/docs/handbook/modules/reference.html#node16-node18-nodenext) 7 | to understand how the emitted code looks like. 8 | 9 | :::important 10 | 11 | At the moment, `ts-jest` uses TypeScript API to transpile code so the emitted `js` code depends on the `TypeScript` version used. 12 | 13 | ::: 14 | 15 | There will be a few differences from traditional `CommonJs`, e.g. `dynamic import` **WON'T** be transformed into `Promise` and `require`. 16 | -------------------------------------------------------------------------------- /website/versioned_docs/version-29.3/guides/mock-es6-class.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: mock-es6-class 3 | title: Mock ES6 class 4 | --- 5 | 6 | TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import. 7 | `const soundPlayer = require('./sound-player')`. Therefore creating an instance of the class that was exported as 8 | a default will look like this: `new soundPlayer.default()`. However if you are mocking the class as suggested by the documentation. 9 | 10 | ```ts title="my-mocks.ts" 11 | jest.mock('./sound-player', () => { 12 | return jest.fn().mockImplementation(() => { 13 | return { playSoundFile: mockPlaySoundFile } 14 | }) 15 | }) 16 | ``` 17 | 18 | You will get the error 19 | 20 | ``` 21 | TypeError: sound_player_1.default is not a constructor 22 | ``` 23 | 24 | because `soundPlayer.default` does not point to a function. Your mock has to return an object which has a property default 25 | that points to a function. 26 | 27 | ```ts title="my-mocks.ts" 28 | jest.mock('./sound-player', () => { 29 | return { 30 | default: jest.fn().mockImplementation(() => { 31 | return { 32 | playSoundFile: mockPlaySoundFile, 33 | } 34 | }), 35 | } 36 | }) 37 | ``` 38 | 39 | For named imports, like `import { OAuth2 } from './oauth'`, replace `default` with imported module name, `OAuth2` in this example: 40 | 41 | ```ts title="my-mocks.ts" 42 | jest.mock('./oauth', () => { 43 | return { 44 | OAuth2: ... // mock here 45 | } 46 | }) 47 | ``` 48 | -------------------------------------------------------------------------------- /website/versioned_docs/version-29.3/guides/using-with-monorepo.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: using-with-monorepo 3 | title: Using with monorepo 4 | --- 5 | 6 | To use `ts-jest` in a project with monorepo structure, you'll need to use [Jest projects configuration](https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig). 7 | 8 | When using Jest `projects` configuration, Jest will run `ts-jest` against each project which is defined in the configuration. 9 | -------------------------------------------------------------------------------- /website/versioned_docs/version-29.3/introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: introduction 3 | title: Introduction 4 | description: A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript. 5 | slug: / 6 | --- 7 | 8 | `ts-jest` is a Jest [transformer](https://jestjs.io/docs/next/code-transformation#writing-custom-transformers) with source map support that lets you use Jest to test projects written in TypeScript. 9 | 10 | It supports all features of TypeScript including type-checking. [Read more about Babel7 + `preset-typescript` **vs** TypeScript (and `ts-jest`)](babel7-or-ts). 11 | 12 | :::important 13 | 14 | We are not doing semantic versioning and `23.10` is a re-write, run `npm i -D ts-jest@"<23.10.0"` to go back to the previous version 15 | 16 | ::: 17 | -------------------------------------------------------------------------------- /website/versioned_docs/version-29.3/migration.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: migration 3 | title: Migration from <=23.10 4 | --- 5 | 6 | You can use the `config:migrate` tool of `ts-jest` CLI if you're coming from an older version to help you migrate your Jest configuration. 7 | 8 | _If you're using `jest.config.js`:_ 9 | 10 | ```npm tab 11 | npx ts-jest config:migrate jest.config.js 12 | ``` 13 | 14 | ```Yarn tab 15 | yarn ts-jest config:migrate jest.config.js 16 | ``` 17 | 18 | _If you're using `jest` config property of `package.json`:_ 19 | 20 | ```npm tab 21 | npx ts-jest config:migrate package.json 22 | ``` 23 | 24 | ```Yarn tab 25 | yarn ts-jest config:migrate package.json 26 | ``` 27 | -------------------------------------------------------------------------------- /website/versioned_sidebars/version-29.3-sidebars.json: -------------------------------------------------------------------------------- 1 | { 2 | "docs": [ 3 | { 4 | "type": "category", 5 | "label": "ts-jest", 6 | "items": [ 7 | "introduction", 8 | "processing", 9 | "contributing" 10 | ] 11 | }, 12 | { 13 | "type": "category", 14 | "label": "Getting Started", 15 | "collapsed": false, 16 | "items": [ 17 | "getting-started/installation", 18 | "getting-started/presets", 19 | "getting-started/options", 20 | "getting-started/paths-mapping", 21 | "getting-started/version-checking" 22 | ] 23 | }, 24 | { 25 | "type": "category", 26 | "label": "Guides", 27 | "collapsed": false, 28 | "items": [ 29 | "guides/esm-support", 30 | "guides/hybrid-node-module", 31 | "guides/mock-es6-class", 32 | "guides/react-native", 33 | "guides/troubleshooting", 34 | "guides/using-with-monorepo" 35 | ] 36 | }, 37 | { 38 | "type": "doc", 39 | "id": "babel7-or-ts" 40 | }, 41 | { 42 | "type": "doc", 43 | "id": "migration" 44 | }, 45 | { 46 | "type": "doc", 47 | "id": "debugging" 48 | } 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /website/versions.json: -------------------------------------------------------------------------------- 1 | [ 2 | "29.3", 3 | "29.2", 4 | "29.0", 5 | "28.0", 6 | "27.1", 7 | "27.0", 8 | "26.5" 9 | ] 10 | --------------------------------------------------------------------------------