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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃懡 Update api/test per ts-jest deprecations #693

Merged
merged 4 commits into from Feb 2, 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
Expand Up @@ -52,7 +52,8 @@
"@commitlint/cli": "^13.1.0",
"@commitlint/config-conventional": "^13.1.0",
"@commitlint/prompt": "^13.1.0",
"@types/jest": "^27.0.2",
"@jest/globals": "^27.4.6",
"@types/jest": "^27.4.0",
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.4.0",
"arrify": "^2.0.1",
Expand All @@ -74,7 +75,7 @@
"eslint-plugin-react-hooks": "^4.3.0",
"glob": "^7.2.0",
"is-ci": "^3.0.0",
"jest": "^27.3.1",
"jest": "^27.4.7",
"jest-github-actions-reporter": "^1.0.3",
"jest-watch-typeahead": "^1.0.0",
"lint-staged": "^11.1.2",
Expand Down Expand Up @@ -124,7 +125,6 @@
"@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: 10 additions & 7 deletions src/api/__tests__/test.js
@@ -1,11 +1,14 @@
import * as utilsExports from 'ts-jest/utils'
import * as utilsExports from 'ts-jest'
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]) => key !== 'default'))(
'forwards `%s` export',
(exportName, exportValue) => {
expect(testExports).toHaveProperty(exportName, exportValue)
},
)
test.each(
Object.entries(utilsExports).filter(([key]) =>
toForwardTsJest.includes(key),
),
)('forwards `%s` export', (exportName, exportValue) => {
expect(testExports).toHaveProperty(exportName, exportValue)
})
})
7 changes: 6 additions & 1 deletion src/api/test.js
@@ -1 +1,6 @@
export * from 'ts-jest/utils'
import {jest} from '@jest/globals'
export {pathsToModuleNameMapper, createJestPreset} from 'ts-jest'

const {mocked} = jest

export {mocked}
33 changes: 15 additions & 18 deletions src/config/jest.config.js
Expand Up @@ -2,7 +2,7 @@

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

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

const {
testMatch,
Expand All @@ -29,6 +29,14 @@ 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 @@ -51,24 +59,13 @@ const jestConfig = {
require.resolve('jest-watch-typeahead/filename'),
require.resolve('jest-watch-typeahead/testname'),
],
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,
globals: {
'ts-jest': {
diagnostics: {
warnOnly: true,
},
},
}
},
}

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