Skip to content

Commit 6751696

Browse files
committed
build: updgrade babel and related dependencies
1 parent a9462eb commit 6751696

14 files changed

Lines changed: 734 additions & 737 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ In some cases, projects may not want to have a `.babelrc` file, but still need t
212212
"globals": {
213213
"ts-jest": {
214214
"babelConfig": {
215-
"presets": ["env"]
215+
"presets": ["@babel/env"]
216216
}
217217
}
218218
}

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ function lazyRequire(fnName) {
1010
}
1111

1212
module.exports = {
13-
process: lazyRequire('process'),
1413
getCacheKey: lazyRequire('getCacheKey'),
14+
process: lazyRequire('process'),
1515
};

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,28 @@
7070
"yargs": "^12.0.1"
7171
},
7272
"peerDependencies": {
73-
"babel-core": "^6.26.3 || ^7.0.0-0",
73+
"babel-core": "^7.0.0-0",
7474
"jest": "^23.0.0 || ^24.0.0",
7575
"typescript": "2.x"
7676
},
7777
"devDependencies": {
78-
"@types/babel-core": "latest",
78+
"@babel/core": "^7.0.0-beta.54",
79+
"@babel/preset-env": "^7.0.0-beta.54",
80+
"@types/babel-core": "^6.25.5",
7981
"@types/es6-shim": "0.31.37",
8082
"@types/fs-extra": "5.0.4",
81-
"@types/jest": "^23.1.0",
83+
"@types/jest": "^23.3.0",
8284
"@types/lodash": "^4.14.109",
8385
"@types/node": "10.5.2",
8486
"@types/react": "16.4.6",
8587
"@types/yargs": "^11.0.0",
86-
"babel-core": "^6.26.3",
8788
"babel-plugin-istanbul": "^4.1.6",
88-
"babel-preset-env": "^1.7.0",
89-
"babel-preset-jest": "^23.0.0",
89+
"babel-preset-jest": "^23.2.0",
9090
"cross-spawn": "latest",
9191
"cross-spawn-with-kill": "latest",
9292
"doctoc": "latest",
9393
"husky": "^0.14.3",
94-
"jest": "^23.0.0",
94+
"jest": "^23.4.1",
9595
"lint-staged": "^7.1.2",
9696
"prettier": "^1.12.1",
9797
"react": "16.4.1",

src/jest-types.ts

Lines changed: 11 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -30,74 +30,28 @@ export type PostProcessHook = (
3030
transformOptions: TransformOptions,
3131
) => CodeSourceMapPair;
3232

33-
export type JestConfig = Partial<FullJestProjectConfig>;
34-
35-
export interface FullJestProjectConfig {
36-
automock: boolean;
37-
browser: boolean;
38-
cache: boolean;
39-
cacheDirectory: Path;
40-
clearMocks: boolean;
41-
coveragePathIgnorePatterns: string[];
42-
cwd: Path;
43-
detectLeaks: boolean;
44-
detectOpenHandles: boolean;
45-
displayName: string | null;
46-
errorOnDeprecated: boolean;
47-
filter: Path | null;
48-
forceCoverageMatch: Glob[];
49-
globals: ConfigGlobals;
50-
haste: HasteConfig;
51-
moduleDirectories: string[];
52-
moduleFileExtensions: string[];
53-
moduleLoader: Path;
54-
moduleNameMapper: Array<[string, string]>;
55-
modulePathIgnorePatterns: string[];
56-
modulePaths: string[];
57-
name: string;
58-
resetMocks: boolean;
59-
resetModules: boolean;
60-
resolver: Path | null;
61-
restoreMocks: boolean;
62-
rootDir: Path;
63-
roots: Path[];
64-
runner: string;
65-
setupFiles: Path[];
66-
setupTestFrameworkScriptFile: Path | null;
67-
skipFilter: boolean;
68-
skipNodeResolution: boolean;
69-
snapshotSerializers: Path[];
70-
testEnvironment: string;
71-
testEnvironmentOptions: object;
72-
testLocationInResults: boolean;
73-
testMatch: Glob[];
74-
testPathIgnorePatterns: string[];
75-
testRegex: string;
76-
testRunner: string;
77-
testURL: string;
78-
timers: 'real' | 'fake';
79-
transform: Array<[string, Path]>;
80-
transformIgnorePatterns: Glob[];
81-
watchPathIgnorePatterns: string[];
82-
unmockedModulePathPatterns: string[] | null;
83-
}
33+
export type JestConfig = jest.InitialOptions & {
34+
globals?: jest.ConfigGlobals & {
35+
__TRANSFORM_HTML__?: boolean;
36+
};
37+
};
8438

8539
export interface TsJestConfig {
86-
skipBabel?: boolean;
87-
useBabelrc?: boolean;
8840
babelConfig?: BabelTransformOpts;
89-
tsConfigFile?: string;
41+
disableSourceMapSupport?: boolean;
9042
enableInternalCache?: boolean;
9143
enableTsDiagnostics?: boolean;
92-
disableSourceMapSupport?: boolean;
93-
ignoreCoverageForDecorators?: boolean;
9444
ignoreCoverageForAllDecorators?: boolean;
45+
ignoreCoverageForDecorators?: boolean;
46+
skipBabel?: boolean;
47+
tsConfigFile?: string;
48+
useBabelrc?: boolean;
9549
useExperimentalLanguageServer?: boolean;
9650
}
9751

9852
export interface JestConfigNormalize {
9953
hasDeprecationWarnings: boolean;
100-
options: FullJestProjectConfig;
54+
options: jest.DefaultOptions;
10155
}
10256

10357
export interface CodeSourceMapPair {

src/postprocess.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,27 @@
55
import * as __types__babel from 'babel-core';
66
import __types__istanbulPlugin from 'babel-plugin-istanbul';
77
import * as __types__jestPreset from 'babel-preset-jest';
8-
import * as ts from 'typescript';
98
let babel: typeof __types__babel;
109
let istanbulPlugin: typeof __types__istanbulPlugin;
1110
let jestPreset: typeof __types__jestPreset;
1211
function importBabelDeps() {
1312
if (babel) {
1413
return;
1514
}
16-
babel = require('babel-core');
15+
babel = require('@babel/core');
1716
istanbulPlugin = require('babel-plugin-istanbul').default;
1817
jestPreset = require('babel-preset-jest');
1918
}
2019
import { CompilerOptions } from 'typescript/lib/typescript';
2120
import {
2221
BabelTransformOptions,
2322
CodeSourceMapPair,
24-
FullJestProjectConfig,
2523
JestConfig,
2624
PostProcessHook,
2725
TransformOptions,
2826
TsJestConfig,
2927
} from './jest-types';
3028
import { logOnce } from './logger';
31-
import { BabelFileResult } from 'babel-core';
3229

3330
// Function that takes the transpiled typescript and runs it through babel/whatever.
3431
export function postProcessCode(

tests/__tests__/babel-config.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('babelConfig flag', () => {
1010
const result = runJest('../babel-config-invalid', ['--no-cache', '-u']);
1111
const stderr = result.stderr;
1212
expect(result.status).toBe(1);
13-
expect(stderr).toContain('ReferenceError: [BABEL]');
13+
expect(stderr).toContain('ReferenceError: Unknown option: .foo.');
1414
expect(stderr).toContain(
1515
'Check out http://babeljs.io/docs/usage/options/ for more information about options.',
1616
);
@@ -31,6 +31,6 @@ describe('babelConfig flag', () => {
3131
]);
3232
const stderr = result.stderr;
3333
expect(result.status).toBe(1);
34-
expect(stderr).toContain(`Couldn't find preset "nonexistent"`);
34+
expect(stderr).toContain(`Cannot find module 'babel-preset-nonexistent'`);
3535
});
3636
});

tests/__tests__/babelrc.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe('babelrc flag', () => {
55
const result = runJest('../use-babelrc', ['--no-cache', '-u']);
66
const stderr = result.stderr;
77
expect(result.status).toBe(1);
8-
expect(stderr).toContain('ReferenceError: [BABEL]');
8+
expect(stderr).toContain('ReferenceError: Unknown option: .foo.');
99
expect(stderr).toContain(
1010
'Check out http://babeljs.io/docs/usage/options/ for more information about options.',
1111
);

tests/__tests__/disable-sourcemap-support.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ describe('Typescript errors', () => {
88
const stderr = result.stderr;
99

1010
// The actual error is on line 18 - the line# being wrong here means sourcemaps are disabled.
11-
expect(stderr).toContain('Hello.ts:8');
11+
expect(stderr).toMatch(/at .+Hello\.ts:\d+/);
12+
expect(stderr).not.toContain('Hello.ts:18');
1213
expectJestStatus(result, 1);
1314
});
1415
});

tests/__tests__/import.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import runJest from '../__helpers__/runJest';
2-
import { printStdStreams } from '../utils/test-utils';
32

43
describe('import with relative and absolute paths', () => {
54
it('should run successfully', () => {

tests/__tests__/postprocess.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
jest.mock('babel-core', () => {
1+
jest.mock('@babel/core', () => {
22
return {
33
transform: jest.fn(() => {
44
return { code: 'stubbed_code', map: 'stubbed_map' };
@@ -19,14 +19,14 @@ describe('postprocess', () => {
1919
}
2020

2121
it('skips postprocess when skipBabel=true', () => {
22-
const transformMock = require.requireMock('babel-core').transform;
22+
const transformMock = require.requireMock('@babel/core').transform;
2323

2424
runHook({}, {}, { skipBabel: true });
2525
expect(transformMock).not.toBeCalled();
2626
});
2727

2828
it('Adds no babel plugins by default', () => {
29-
const transformMock = require.requireMock('babel-core').transform;
29+
const transformMock = require.requireMock('@babel/core').transform;
3030

3131
runHook();
3232
getPostProcessHook({}, {}, {})(
@@ -44,7 +44,7 @@ describe('postprocess', () => {
4444
});
4545

4646
it('doesn`t accumulate module transforms on consecutive calls', () => {
47-
const transformMock = require.requireMock('babel-core').transform;
47+
const transformMock = require.requireMock('@babel/core').transform;
4848
const tsJestConfig = {
4949
babelConfig: {
5050
plugins: ['some-plugin'],

0 commit comments

Comments
 (0)