-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #652 from huafu/hotfix/babel-and-preprocess-bridges
[HOTFIX] babel and preprocess.js bridges
- Loading branch information
Showing
15 changed files
with
177 additions
and
8,115 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
console.warn( | ||
`[ts-jest][DEPRECATED] - 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".` | ||
); | ||
|
||
module.exports = require('./dist'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { | ||
TBabel, | ||
TBabelPresetEnv, | ||
TBabelPluginIstanbul, | ||
TBabelPresetJest, | ||
} from '../types'; | ||
|
||
export function importBabelCore(): TBabel { | ||
const mod = tryRequire('@babel/core') || tryRequire('babel-core'); | ||
if (!mod) { | ||
throw new Error( | ||
`[ts-jest] You must install the '@babel/core' or 'babel-core'` + | ||
` package (depending on the version you want to use).`, | ||
); | ||
} | ||
return mod; | ||
} | ||
|
||
export function importBabelPresetEnv(): TBabelPresetEnv { | ||
const mod = tryRequire('@babel/preset-env') || tryRequire('babel-preset-env'); | ||
if (!mod) { | ||
throw new Error( // babel-jest has the env preset as a dep | ||
`[ts-jest] You must install the 'babel-jest' package if you're using babel.`, | ||
); | ||
} | ||
return mod; | ||
} | ||
|
||
export function importBabelPresetJest(): TBabelPresetJest { | ||
const mod = tryRequire('babel-preset-jest'); | ||
if (!mod) { | ||
throw new Error( // babel-jest has the jest preset as a dep | ||
`[ts-jest] You must install the 'babel-jest' package if you're using babel.`, | ||
); | ||
} | ||
return mod; | ||
} | ||
|
||
export function importBabelPluginIstanbul(): TBabelPluginIstanbul { | ||
const mod = tryRequire('babel-plugin-istanbul'); | ||
if (!mod) { | ||
throw new Error( // babel-jest has the istanbul plugin as a dep | ||
`[ts-jest] You must install the 'babel-jest' package if you're using babel.`, | ||
); | ||
} | ||
return mod.default; | ||
} | ||
|
||
function tryRequire<T = any>(packageName: string): T | void { | ||
let mod: T; | ||
try { | ||
mod = require(packageName); | ||
} catch (err) { | ||
if (err.code !== 'ENOENT') throw err; // tslint:disable-line | ||
} | ||
return mod; | ||
} |
3 changes: 3 additions & 0 deletions
3
tests/__tests__/__snapshots__/deprecated-transform.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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\\"."`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class Hello { | ||
constructor(readonly msg: string) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters