Skip to content

Commit 1103071

Browse files
committed
feat: warn about unsupported versions
1 parent 015e8f7 commit 1103071

22 files changed

Lines changed: 327 additions & 58 deletions

jest.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
module.exports = {
22
rootDir: '.',
33
transform: {
4-
'\\.ts$': '<rootDir>/dist/index.js'
4+
'\\.ts$': '<rootDir>/dist/index.js',
55
},
66
testMatch: ['<rootDir>/src/**/?(*.)+(spec|test).ts?(x)'],
77
collectCoverageFrom: [
88
'<rootDir>/src/**/*.ts',
99
'!<rootDir>/src/**/*.d.ts',
1010
'!<rootDir>/src/**/*.spec.ts',
1111
'!<rootDir>/src/**/*.test.ts',
12-
'!<rootDir>/src/**/__*__/*'
12+
'!<rootDir>/src/**/__*__/*',
1313
],
1414
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
15-
testEnvironment: 'node'
15+
testEnvironment: 'node',
1616
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"fast-json-stable-stringify": "^2.0.0",
4343
"json5": "^1.0.1",
4444
"make-error": "^1.3.4",
45-
"mkdirp": "^0.5.1"
45+
"mkdirp": "^0.5.1",
46+
"semver": "^5.5.1"
4647
},
4748
"peerDependencies": {
4849
"babel-jest": "23.x",
@@ -74,7 +75,6 @@
7475
"prettier": "^1.14.2",
7576
"prettier-tslint": "^0.4.0",
7677
"reflect-metadata": "^0.1.12",
77-
"semver": "^5.5.1",
7878
"source-map": "^0.7.3",
7979
"tslint": "^5.11.0",
8080
"typescript": "^3.0.1"

preprocessor.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
console.warn(
2+
'ts-jest',
3+
'[deprecated]',
4+
`Replace any occurrences of "ts-jest/dist/preprocessor.js" or ` +
5+
` "<rootDir>/node_modules/ts-jest/preprocessor.js"` +
6+
` in the 'transform' section of your Jest config with just "ts-jest".`,
7+
)
8+
9+
module.exports = require('./dist')

src/__helpers__/fakers.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ describe('hello', () => {
5454

5555
export function tsJestConfig(options?: Partial<TsJestConfig>): TsJestConfig {
5656
return {
57-
version: '0.0.0-mock0',
5857
typeCheck: false,
5958
compiler: 'typescript',
6059
babelConfig: undefined,

src/index.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tslint:disable:max-line-length
2+
import { __setup } from './lib/debug'
13
import * as tsJest from '.'
24
import { TsJestTransformer } from './lib/ts-jest-transformer'
35

@@ -31,6 +33,28 @@ describe('ts-jest', () => {
3133
})
3234
})
3335

36+
describe('old entry point', () => {
37+
const MANIFEST = { tsJestIndex: true }
38+
const spy = jest.spyOn(console, 'warn')
39+
spy.mockImplementation(() => undefined)
40+
afterAll(() => {
41+
spy.mockRestore()
42+
})
43+
44+
it('should warn when using old path to ts-jest', () => {
45+
jest.mock('../dist/index', () => MANIFEST)
46+
expect(require('../preprocessor.js')).toBe(MANIFEST)
47+
expect(spy).toHaveBeenCalledTimes(1)
48+
expect(spy.mock.calls[0]).toMatchInlineSnapshot(`
49+
Array [
50+
"ts-jest",
51+
"[deprecated]",
52+
"Replace any occurrences of \\"ts-jest/dist/preprocessor.js\\" or \\"<rootDir>/node_modules/ts-jest/preprocessor.js\\" in the 'transform' section of your Jest config with just \\"ts-jest\\".",
53+
]
54+
`)
55+
})
56+
})
57+
3458
describe('createTransformer', () => {
3559
it('should create different instances', () => {
3660
const tr1 = tsJest.createTransformer()

src/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import { TsJestTransformer } from './lib/ts-jest-transformer'
22
import { createJestPreset } from './lib/create-jest-preset'
33
import { TsJestGlobalOptions } from './lib/types'
4+
import { VersionCheckers } from './lib/version-checkers'
5+
6+
// tslint:disable-next-line:no-var-requires
7+
const version: string = require('../package.json').version
48

59
let transformer!: TsJestTransformer
610
function defaultTransformer(): TsJestTransformer {
7-
return transformer || (transformer = new TsJestTransformer())
11+
return transformer || (transformer = createTransformer())
812
}
913

1014
function createTransformer(baseConfig?: TsJestGlobalOptions) {
15+
VersionCheckers.jest.warn()
1116
return new TsJestTransformer(baseConfig)
1217
}
1318
function tsProcess(...args: any[]): any {
@@ -26,14 +31,15 @@ const __singleton = () => transformer
2631
const __resetModule = () => (transformer = undefined as any)
2732

2833
export {
29-
// jest API
34+
version,
35+
// jest API ===============
3036
createTransformer,
3137
tsProcess as process,
3238
getCacheKey,
33-
// extra
39+
// extra ==================
3440
createJestPreset,
3541
jestPreset,
36-
// tests
42+
// tests ==================
3743
__singleton,
3844
__resetModule,
3945
}

src/lib/__snapshots__/backports.spec.ts.snap

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Object {
1616
}
1717
`;
1818

19-
exports[`backportJestConfig with "globals.__TRANSFORM_HTML__" set to false should wran the user 1`] = `"ts-jest \\"[jest-config].globals.__TRANSFORM_HTML__\\" is deprecated, use \\"[jest-config].globals.ts-jest.stringifyContentPathRegex\\" instead."`;
19+
exports[`backportJestConfig with "globals.__TRANSFORM_HTML__" set to false should wran the user 1`] = `"ts-jest: \\"[jest-config].globals.__TRANSFORM_HTML__\\" is deprecated, use \\"[jest-config].globals.ts-jest.stringifyContentPathRegex\\" instead."`;
2020

2121
exports[`backportJestConfig with "globals.__TRANSFORM_HTML__" set to true should have changed the config correctly: before 1`] = `
2222
Object {
@@ -36,7 +36,7 @@ Object {
3636
}
3737
`;
3838

39-
exports[`backportJestConfig with "globals.__TRANSFORM_HTML__" set to true should wran the user 1`] = `"ts-jest \\"[jest-config].globals.__TRANSFORM_HTML__\\" is deprecated, use \\"[jest-config].globals.ts-jest.stringifyContentPathRegex\\" instead."`;
39+
exports[`backportJestConfig with "globals.__TRANSFORM_HTML__" set to true should wran the user 1`] = `"ts-jest: \\"[jest-config].globals.__TRANSFORM_HTML__\\" is deprecated, use \\"[jest-config].globals.ts-jest.stringifyContentPathRegex\\" instead."`;
4040

4141
exports[`backportJestConfig with "globals.__TS_CONFIG__" set to { foo: 'bar' } should have changed the config correctly: before 1`] = `
4242
Object {
@@ -60,7 +60,7 @@ Object {
6060
}
6161
`;
6262

63-
exports[`backportJestConfig with "globals.__TS_CONFIG__" set to { foo: 'bar' } should wran the user 1`] = `"ts-jest \\"[jest-config].globals.__TS_CONFIG__\\" is deprecated, use \\"[jest-config].globals.ts-jest.tsConfig\\" instead."`;
63+
exports[`backportJestConfig with "globals.__TS_CONFIG__" set to { foo: 'bar' } should wran the user 1`] = `"ts-jest: \\"[jest-config].globals.__TS_CONFIG__\\" is deprecated, use \\"[jest-config].globals.ts-jest.tsConfig\\" instead."`;
6464

6565
exports[`backportJestConfig with "globals.ts-jest.enableTsDiagnostics" set to '\\\\.spec\\\\.ts$' should have changed the config correctly: before 1`] = `
6666
Object {
@@ -84,7 +84,7 @@ Object {
8484
}
8585
`;
8686

87-
exports[`backportJestConfig with "globals.ts-jest.enableTsDiagnostics" set to '\\\\.spec\\\\.ts$' should wran the user 1`] = `"ts-jest \\"[jest-config].globals.ts-jest.enableTsDiagnostics\\" is deprecated, use \\"[jest-config].globals.ts-jest.diagnostics\\" instead."`;
87+
exports[`backportJestConfig with "globals.ts-jest.enableTsDiagnostics" set to '\\\\.spec\\\\.ts$' should wran the user 1`] = `"ts-jest: \\"[jest-config].globals.ts-jest.enableTsDiagnostics\\" is deprecated, use \\"[jest-config].globals.ts-jest.diagnostics\\" instead."`;
8888

8989
exports[`backportJestConfig with "globals.ts-jest.enableTsDiagnostics" set to false should have changed the config correctly: before 1`] = `
9090
Object {
@@ -106,7 +106,7 @@ Object {
106106
}
107107
`;
108108

109-
exports[`backportJestConfig with "globals.ts-jest.enableTsDiagnostics" set to false should wran the user 1`] = `"ts-jest \\"[jest-config].globals.ts-jest.enableTsDiagnostics\\" is deprecated, use \\"[jest-config].globals.ts-jest.diagnostics\\" instead."`;
109+
exports[`backportJestConfig with "globals.ts-jest.enableTsDiagnostics" set to false should wran the user 1`] = `"ts-jest: \\"[jest-config].globals.ts-jest.enableTsDiagnostics\\" is deprecated, use \\"[jest-config].globals.ts-jest.diagnostics\\" instead."`;
110110

111111
exports[`backportJestConfig with "globals.ts-jest.enableTsDiagnostics" set to true should have changed the config correctly: before 1`] = `
112112
Object {
@@ -128,7 +128,7 @@ Object {
128128
}
129129
`;
130130

131-
exports[`backportJestConfig with "globals.ts-jest.enableTsDiagnostics" set to true should wran the user 1`] = `"ts-jest \\"[jest-config].globals.ts-jest.enableTsDiagnostics\\" is deprecated, use \\"[jest-config].globals.ts-jest.diagnostics\\" instead."`;
131+
exports[`backportJestConfig with "globals.ts-jest.enableTsDiagnostics" set to true should wran the user 1`] = `"ts-jest: \\"[jest-config].globals.ts-jest.enableTsDiagnostics\\" is deprecated, use \\"[jest-config].globals.ts-jest.diagnostics\\" instead."`;
132132

133133
exports[`backportJestConfig with "globals.ts-jest.skipBabel" set to false should have changed the config correctly: before 1`] = `
134134
Object {
@@ -150,7 +150,7 @@ Object {
150150
}
151151
`;
152152

153-
exports[`backportJestConfig with "globals.ts-jest.skipBabel" set to false should wran the user 1`] = `"ts-jest \\"[jest-config].globals.ts-jest.skipBabel\\" is deprecated, use \\"[jest-config].globals.ts-jest.babelConfig\\" instead."`;
153+
exports[`backportJestConfig with "globals.ts-jest.skipBabel" set to false should wran the user 1`] = `"ts-jest: \\"[jest-config].globals.ts-jest.skipBabel\\" is deprecated, use \\"[jest-config].globals.ts-jest.babelConfig\\" instead."`;
154154

155155
exports[`backportJestConfig with "globals.ts-jest.skipBabel" set to true should have changed the config correctly: before 1`] = `
156156
Object {
@@ -170,7 +170,7 @@ Object {
170170
}
171171
`;
172172

173-
exports[`backportJestConfig with "globals.ts-jest.skipBabel" set to true should wran the user 1`] = `"ts-jest \\"[jest-config].globals.ts-jest.skipBabel\\" is deprecated, use \\"[jest-config].globals.ts-jest.babelConfig\\" instead."`;
173+
exports[`backportJestConfig with "globals.ts-jest.skipBabel" set to true should wran the user 1`] = `"ts-jest: \\"[jest-config].globals.ts-jest.skipBabel\\" is deprecated, use \\"[jest-config].globals.ts-jest.babelConfig\\" instead."`;
174174

175175
exports[`backportJestConfig with "globals.ts-jest.tsConfigFile" set to 'tsconfig.build.json' should have changed the config correctly: before 1`] = `
176176
Object {
@@ -192,7 +192,7 @@ Object {
192192
}
193193
`;
194194

195-
exports[`backportJestConfig with "globals.ts-jest.tsConfigFile" set to 'tsconfig.build.json' should wran the user 1`] = `"ts-jest \\"[jest-config].globals.ts-jest.tsConfigFile\\" is deprecated, use \\"[jest-config].globals.ts-jest.tsConfig\\" instead."`;
195+
exports[`backportJestConfig with "globals.ts-jest.tsConfigFile" set to 'tsconfig.build.json' should wran the user 1`] = `"ts-jest: \\"[jest-config].globals.ts-jest.tsConfigFile\\" is deprecated, use \\"[jest-config].globals.ts-jest.tsConfig\\" instead."`;
196196

197197
exports[`backportJestConfig with "globals.ts-jest.useBabelrc" set to false should have changed the config correctly: before 1`] = `
198198
Object {
@@ -215,7 +215,7 @@ Object {
215215
`;
216216

217217
exports[`backportJestConfig with "globals.ts-jest.useBabelrc" set to false should wran the user 1`] = `
218-
"ts-jest \\"[jest-config].globals.ts-jest.useBabelrc\\" is deprecated, use \\"[jest-config].globals.ts-jest.babelConfig\\" instead.
218+
"ts-jest: \\"[jest-config].globals.ts-jest.useBabelrc\\" is deprecated, use \\"[jest-config].globals.ts-jest.babelConfig\\" instead.
219219
↳ See \`babel-jest\` related issue: https://github.com/facebook/jest/issues/3845"
220220
`;
221221

@@ -240,6 +240,6 @@ Object {
240240
`;
241241

242242
exports[`backportJestConfig with "globals.ts-jest.useBabelrc" set to true should wran the user 1`] = `
243-
"ts-jest \\"[jest-config].globals.ts-jest.useBabelrc\\" is deprecated, use \\"[jest-config].globals.ts-jest.babelConfig\\" instead.
243+
"ts-jest: \\"[jest-config].globals.ts-jest.useBabelrc\\" is deprecated, use \\"[jest-config].globals.ts-jest.babelConfig\\" instead.
244244
↳ See \`babel-jest\` related issue: https://github.com/facebook/jest/issues/3845"
245245
`;

src/lib/__snapshots__/config-set.spec.ts.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,5 @@ Object {
3636
"value": undefined,
3737
},
3838
"typeCheck": false,
39-
"version": "X.Y.Z",
4039
}
4140
`;

src/lib/compiler.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('cache', () => {
8686
expect(logger).toHaveBeenCalledTimes(1)
8787
expect(logger).toHaveBeenCalledWith(
8888
'log',
89-
'ts-jest',
89+
'ts-jest:',
9090
'readThrough:cache-miss',
9191
__filename,
9292
)
@@ -96,7 +96,7 @@ describe('cache', () => {
9696
expect(logger).toHaveBeenCalledTimes(1)
9797
expect(logger).toHaveBeenCalledWith(
9898
'log',
99-
'ts-jest',
99+
'ts-jest:',
100100
'readThrough:cache-hit',
101101
__filename,
102102
)

src/lib/config-set.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { resolve } from 'path'
88
import { normalizeSlashes } from './normalize-slashes'
99

1010
jest.mock('./backports')
11-
jest.mock('../../package.json', () => ({ version: 'X.Y.Z' }))
1211

1312
const backports = mocked(_backports)
1413

0 commit comments

Comments
 (0)