Skip to content

Commit

Permalink
fix: allow (but deprecate) use of old preprocessor.js
Browse files Browse the repository at this point in the history
  • Loading branch information
huafu committed Aug 3, 2018
1 parent b895cb4 commit a65079f
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 0 deletions.
7 changes: 7 additions & 0 deletions preprocessor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
console.warn(
`[ts-jest][DEPRECATED] - replace any occurrences to "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".`
);

module.exports = require('./dist');
7 changes: 7 additions & 0 deletions scripts/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ function createIntegrationMock() {
path.resolve(testCaseModuleFolder, 'package.json')
);

// TODO: remove this in next major version as well as the test, and the preprocessor.js file in root
// Copy preprocessor.js
fs.copySync(
path.resolve(rootDir, 'preprocessor.js'),
path.resolve(testCaseModuleFolder, 'preprocessor.js')
);

// Copy dist folder
fs.copySync(
path.resolve(rootDir, 'dist'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Deprecated Jest transform value should log the depration message 1`] = `"[ts-jest][DEPRECATED] - replace any occurrences to \\"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\\"."`;
14 changes: 14 additions & 0 deletions tests/__tests__/deprecated-transform.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import runJest from '../__helpers__/runJest';

describe('Deprecated Jest transform value', () => {
it('should log the depration message', () => {
const result = runJest('../deprecated-transform', ['--no-cache']);

const output = result.stderr;

// get only the line with deprecation message (we dont want the snapshot to contain any timing or test name)
const msg = output.split('\n').find(line => /deprecated/i.test(line));

expect(msg).toMatchSnapshot();
});
});
3 changes: 3 additions & 0 deletions tests/deprecated-transform/Hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class Hello {
constructor(readonly msg: string) {}
}
10 changes: 10 additions & 0 deletions tests/deprecated-transform/__tests__/Hello.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
declare var jest, describe, it, expect;

import { Hello } from '../Hello';

describe('Hello Class', () => {
it('should create a new Hello', () => {
const hello = new Hello('foo');
expect(hello.msg).toBe('foo');
});
});
9 changes: 9 additions & 0 deletions tests/deprecated-transform/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"jest": {
"transform": {
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": ["ts", "js"]
}
}
5 changes: 5 additions & 0 deletions tests/deprecated-transform/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"target": "es5",
}
}

0 comments on commit a65079f

Please sign in to comment.