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

⏪ Revert Jest 27 utils re-export (will need to be a breaking change) #699

Merged
merged 4 commits into from
Feb 3, 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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
"@commitlint/cli": "^13.1.0",
"@commitlint/config-conventional": "^13.1.0",
"@commitlint/prompt": "^13.1.0",
"@jest/globals": "^27.4.6",
"@types/jest": "^27.4.0",
"@types/jest": "^27.0.2",
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.4.0",
"arrify": "^2.0.1",
Expand All @@ -75,7 +74,7 @@
"eslint-plugin-react-hooks": "^4.3.0",
"glob": "^7.2.0",
"is-ci": "^3.0.0",
"jest": "^27.4.7",
"jest": "^27.3.1",
"jest-github-actions-reporter": "^1.0.3",
"jest-watch-typeahead": "^1.0.0",
"lint-staged": "^11.1.2",
Expand Down Expand Up @@ -125,6 +124,7 @@
"@babel/core": "^7.16.0",
"@babel/preset-env": "^7.16.11",
"@types/cross-spawn": "^6.0.2",
"babel-jest": "^27.2.4",
"eslint-config-kentcdodds": "^20.0.1",
"husky": "^7.0.4",
"jest-in-case": "^1.0.2",
Expand Down
17 changes: 7 additions & 10 deletions src/api/__tests__/test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import * as utilsExports from 'ts-jest'
import * as utilsExports from 'ts-jest/utils'
import * as testExports from '../test' // eslint-disable-line import/namespace

const toForwardTsJest = ['pathsToModuleNameMapper', 'createJestPreset']

describe('re-exporting ts-jest utils', () => {
test.each(
Object.entries(utilsExports).filter(([key]) =>
toForwardTsJest.includes(key),
),
)('forwards `%s` export', (exportName, exportValue) => {
expect(testExports).toHaveProperty(exportName, exportValue)
})
test.each(Object.entries(utilsExports).filter(([key]) => key !== 'default'))(
'forwards `%s` export',
(exportName, exportValue) => {
expect(testExports).toHaveProperty(exportName, exportValue)
},
)
})
7 changes: 1 addition & 6 deletions src/api/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
import {jest} from '@jest/globals'
export {pathsToModuleNameMapper, createJestPreset} from 'ts-jest'

const {mocked} = jest

export {mocked}
export * from 'ts-jest/utils'
33 changes: 18 additions & 15 deletions src/config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const {jsWithTs: preset} = require('ts-jest/presets')

const {ifAnyDep, hasFile, fromRoot} = require('../utils')
const {ifAnyDep, hasAnyDep, hasFile, fromRoot} = require('../utils')

const {
testMatch,
Expand All @@ -29,14 +29,6 @@ const jestConfig = {
testMatch,
testPathIgnorePatterns: [...ignores, '<rootDir>/dist'],
testLocationInResults: true,
transform: Object.fromEntries(
// Ensure we can resolve the preset even when
// it's in a nested `node_modules` installation
Object.entries(preset.transform).map(([key, value]) => [
key,
require.resolve(value),
]),
),
coveragePathIgnorePatterns: [
...ignores,
'src/(umd|cjs|esm)-entry.js$',
Expand All @@ -59,13 +51,24 @@ const jestConfig = {
require.resolve('jest-watch-typeahead/filename'),
require.resolve('jest-watch-typeahead/testname'),
],
globals: {
'ts-jest': {
diagnostics: {
warnOnly: true,
},
globals: {},
}

if (hasAnyDep('ts-jest') || hasFile('tsconfig.json')) {
jestConfig.transform = Object.fromEntries(
// Ensure we can resolve the preset even when
// it's in a nested `node_modules` installation
Object.entries(preset.transform).map(([key, value]) => [
key,
require.resolve(value),
]),
)

jestConfig.globals['ts-jest'] = {
diagnostics: {
warnOnly: true,
},
},
}
}

if (hasFile('tests/setup-env.js')) {
Expand Down
5 changes: 2 additions & 3 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"declarationMap": true,
"outDir": "../dist",
"rootDir": ".",
"skipLibCheck": true
"rootDir": "."
}
}