Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate globals config to transformer config #3780

Merged
merged 1 commit into from Aug 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 2 additions & 22 deletions e2e/__tests__/__snapshots__/const-enum.test.ts.snap
@@ -1,27 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`partial successfully runs the tests inside const-enum with 'isolatedModules: true' 1`] = `
"FAIL __tests__/import-from-d-ts-no-js.spec.ts
● Test suite failed to run

Cannot find module '../hoo-constant' from '__tests__/import-from-d-ts-no-js.spec.ts'

However, Jest was able to find:
'../hoo-constant.d.ts'

You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'mjs', 'cjs', 'jsx', 'ts', 'tsx', 'json', 'node'].

See https://jestjs.io/docs/configuration#modulefileextensions-arraystring

> 1 | import { HooConstEnum } from '../hoo-constant'
| ^
2 |
3 | const getTwo = (): string => HooConstEnum.two
4 |

at Resolver._throwModNotFoundError (../../node_modules/jest-resolve/build/resolver.js:487:11)
at Object.<anonymous> (__tests__/import-from-d-ts-no-js.spec.ts:1:1)

PASS __tests__/import-from-d-ts-has-js.spec.ts
"PASS __tests__/import-from-d-ts-has-js.spec.ts
PASS __tests__/import-from-d-ts-no-js.spec.ts
PASS __tests__/import-from-ts.spec.ts"
`;
18 changes: 9 additions & 9 deletions e2e/ast-transformers/hoist-jest/jest-isolated.config.js
@@ -1,18 +1,18 @@
/** @type {import('../../../dist').InitialOptionsTsJest} */
module.exports = {
automock: true,
globals: {
'ts-jest': {
isolatedModules: true,
tsconfig: {
allowJs: true,
},
},
},
moduleNameMapper: {
react$: '<rootDir>/node_modules/react',
},
transform: {
'^.+.[tj]sx?$': '<rootDir>/../../../legacy.js',
'^.+.[tj]sx?$': [
'<rootDir>/../../../legacy.js',
{
isolatedModules: true,
tsconfig: {
allowJs: true,
},
},
],
},
}
13 changes: 5 additions & 8 deletions e2e/ast-transformers/hoist-jest/package.json
Expand Up @@ -4,18 +4,15 @@
},
"jest": {
"automock": true,
"globals": {
"ts-jest": {
"tsconfig": {
"allowJs": true
}
}
},
"moduleNameMapper": {
"react$": "<rootDir>/node_modules/react"
},
"transform": {
"^.+\\.[tj]sx?$": "<rootDir>/../../../legacy.js"
"^.+\\.[tj]sx?$": ["<rootDir>/../../../legacy.js", {
"tsconfig": {
"allowJs": true
}
}]
}
}
}
9 changes: 3 additions & 6 deletions e2e/ast-transformers/transformer-in-ts/package.json
Expand Up @@ -3,15 +3,12 @@
"esbuild": "~0.15.5"
},
"jest": {
"globals": {
"ts-jest": {
"transform": {
"^.+\\.[tj]sx?$": ["<rootDir>/../../../legacy.js", {
"astTransformers": {
"before": ["<rootDir>/../../../src/transformers/hoist-jest.ts"]
}
}
},
"transform": {
"^.+\\.[tj]sx?$": "<rootDir>/../../../legacy.js"
}]
}
}
}
30 changes: 15 additions & 15 deletions e2e/ast-transformers/transformer-options/jest-isolated.config.js
@@ -1,21 +1,21 @@
/** @type {import('../../../dist').InitialOptionsTsJest} */
module.exports = {
globals: {
'ts-jest': {
isolatedModules: true,
astTransformers: {
before: [
{
path: '<rootDir>/node_modules/@formatjs/ts-transformer/ts-jest-integration',
options: {
removeDefaultMessage: true,
transform: {
'^.+.[tj]sx?$': [
'<rootDir>/../../../legacy.js',
{
isolatedModules: true,
astTransformers: {
before: [
{
path: '<rootDir>/node_modules/@formatjs/ts-transformer/ts-jest-integration',
options: {
removeDefaultMessage: true,
},
},
},
],
],
},
},
},
},
transform: {
'^.+.[tj]sx?$': '<rootDir>/../../../legacy.js',
],
},
}
9 changes: 3 additions & 6 deletions e2e/ast-transformers/transformer-options/package.json
Expand Up @@ -5,8 +5,8 @@
"react-intl": "^6.1.0"
},
"jest": {
"globals": {
"ts-jest": {
"transform": {
"^.+\\.[tj]sx?$": ["<rootDir>/../../../legacy.js", {
"astTransformers": {
"before": [
{
Expand All @@ -17,10 +17,7 @@
}
]
}
}
},
"transform": {
"^.+\\.[tj]sx?$": "<rootDir>/../../../legacy.js"
}]
}
}
}
12 changes: 6 additions & 6 deletions e2e/config-typing/jest.config.ts
@@ -1,13 +1,13 @@
import type { InitialOptionsTsJest } from 'ts-jest'

const jestCfg: InitialOptionsTsJest = {
globals: {
'ts-jest': {
isolatedModules: true,
},
},
transform: {
'^.+.tsx?$': 'ts-jest',
'^.+.tsx?$': [
'ts-jest',
{
isolatedModules: true,
},
],
},
}

Expand Down
14 changes: 8 additions & 6 deletions e2e/const-enum/jest-isolated.config.js
@@ -1,11 +1,13 @@
/** @type {import('../../dist').InitialOptionsTsJest} */
module.exports = {
globals: {
'ts-jest': {
isolatedModules: true,
},
},
transform: {
'^.+.tsx?$': '<rootDir>/../../legacy.js',
'^.+.tsx?$': [
'<rootDir>/../../legacy.js',
{
'ts-jest': {
isolatedModules: true,
},
},
],
},
}
12 changes: 6 additions & 6 deletions e2e/coverage-report/jest-isolated.config.js
@@ -1,12 +1,12 @@
/** @type {import('../../dist').InitialOptionsTsJest} */
module.exports = {
collectCoverageFrom: ['**/*.js', '**/*.ts', '!**/node_modules/**', '!**/coverage/**'],
globals: {
'ts-jest': {
isolatedModules: true,
},
},
transform: {
'^.+.tsx?$': '<rootDir>/../../legacy.js',
'^.+.tsx?$': [
'<rootDir>/../../legacy.js',
{
isolatedModules: true,
},
],
},
}
9 changes: 3 additions & 6 deletions e2e/custom-compiler/ttypescript/package.json
Expand Up @@ -4,13 +4,10 @@
"ttypescript": "^1.5.13"
},
"jest": {
"globals": {
"ts-jest": {
"compiler": "ttypescript"
}
},
"transform": {
"^.+.tsx?$": "<rootDir>/../../../legacy.js"
"^.+.tsx?$": ["<rootDir>/../../../legacy.js", {
"compiler": "ttypescript"
}]
}
}
}
12 changes: 6 additions & 6 deletions e2e/diagnostics/jest-disabled.config.js
@@ -1,11 +1,11 @@
/** @type {import('../../dist').InitialOptionsTsJest} */
module.exports = {
globals: {
'ts-jest': {
diagnostics: false,
},
},
transform: {
'^.+.tsx?$': '<rootDir>/../../legacy.js',
'^.+.tsx?$': [
'<rootDir>/../../legacy.js',
{
diagnostics: false,
},
],
},
}
16 changes: 8 additions & 8 deletions e2e/diagnostics/jest-exclude.config.js
@@ -1,13 +1,13 @@
/** @type {import('../../dist').InitialOptionsTsJest} */
module.exports = {
globals: {
'ts-jest': {
diagnostics: {
exclude: ['**/__tests__/diagnostics.spec.ts'],
},
},
},
transform: {
'^.+.tsx?$': '<rootDir>/../../legacy.js',
'^.+.tsx?$': [
'<rootDir>/../../legacy.js',
{
diagnostics: {
exclude: ['**/__tests__/diagnostics.spec.ts'],
},
},
],
},
}
16 changes: 8 additions & 8 deletions e2e/diagnostics/jest-ignored-code.config.js
@@ -1,13 +1,13 @@
/** @type {import('../../dist').InitialOptionsTsJest} */
module.exports = {
globals: {
'ts-jest': {
diagnostics: {
ignoreCodes: 'TS2741',
},
},
},
transform: {
'^.+.tsx?$': '<rootDir>/../../legacy.js',
'^.+.tsx?$': [
'<rootDir>/../../legacy.js',
{
diagnostics: {
ignoreCodes: 'TS2741',
},
},
],
},
}
12 changes: 6 additions & 6 deletions e2e/diagnostics/jest-isolated.config.js
@@ -1,11 +1,11 @@
/** @type {import('../../dist').InitialOptionsTsJest} */
module.exports = {
globals: {
'ts-jest': {
isolatedModules: true,
},
},
transform: {
'^.+.tsx?$': '<rootDir>/../../legacy.js',
'^.+.tsx?$': [
'<rootDir>/../../legacy.js',
{
isolatedModules: true,
},
],
},
}
16 changes: 8 additions & 8 deletions e2e/diagnostics/jest-warn.config.js
@@ -1,13 +1,13 @@
/** @type {import('../../dist').InitialOptionsTsJest} */
module.exports = {
globals: {
'ts-jest': {
diagnostics: {
warnOnly: true,
},
},
},
transform: {
'^.+.tsx?$': '<rootDir>/../../legacy.js',
'^.+.tsx?$': [
'<rootDir>/../../legacy.js',
{
diagnostics: {
warnOnly: true,
},
},
],
},
}
12 changes: 6 additions & 6 deletions e2e/enum/jest-isolated.config.js
@@ -1,11 +1,11 @@
/** @type {import('../../dist').InitialOptionsTsJest} */
module.exports = {
globals: {
'ts-jest': {
isolatedModules: true,
},
},
transform: {
'^.+.tsx?$': '<rootDir>/../../legacy.js',
'^.+.tsx?$': [
'<rootDir>/../../legacy.js',
{
isolatedModules: true,
},
],
},
}
9 changes: 3 additions & 6 deletions e2e/extend-ts-jest/package.json
@@ -1,12 +1,9 @@
{
"jest": {
"globals": {
"ts-jest": {
"isolatedModules": true
}
},
"transform": {
"^.+\\.tsx?$": "./foo-transformer.js"
"^.+\\.tsx?$": ["./foo-transformer.js", {
"isolatedModules": true
}]
}
}
}
11 changes: 4 additions & 7 deletions e2e/native-esm-js/isolated/package.json
Expand Up @@ -2,18 +2,15 @@
"type": "module",
"jest": {
"extensionsToTreatAsEsm": [".ts"],
"globals": {
"ts-jest": {
"useESM": true,
"isolatedModules": true
}
},
"roots": ["<rootDir>", "<rootDir>/../__tests__"],
"moduleNameMapper": {
"@jest/globals": "<rootDir>/../../../node_modules/@jest/globals"
},
"transform": {
"^.+.tsx?$": "<rootDir>/../../../legacy.js"
"^.+.tsx?$": ["<rootDir>/../../../legacy.js", {
"useESM": true,
"isolatedModules": true
}]
}
}
}