From c8d51cf14b600bd0bd2d8ce0378d6749404641d5 Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Sat, 15 Sep 2018 09:35:37 +0200 Subject: [PATCH] fix(babel): fixes the babel 6 hack --- src/util/hacks.spec.ts | 7 +++++-- src/util/hacks.ts | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/util/hacks.spec.ts b/src/util/hacks.spec.ts index eccad3f796..9a1bc3c538 100644 --- a/src/util/hacks.spec.ts +++ b/src/util/hacks.spec.ts @@ -1,5 +1,3 @@ -import { File } from 'babel-core/lib/transformation/file' - import * as hacks from './hacks' jest.mock( @@ -20,10 +18,15 @@ jest.mock( { virtual: true }, ) +beforeEach(() => { + jest.resetModules() +}) + describe('patchBabelCore_githubIssue6577', () => { const INPUT = 'foo:bar' const initOptions = ({ version = '6.0.0', sourceMaps }: { version?: any; sourceMaps?: any } = {}) => { hacks.patchBabelCore_githubIssue6577({ version } as any) + const { File } = require('babel-core/lib/transformation/file') return new File().initOptions({ sourceMaps, inputSourceMap: true }) } diff --git a/src/util/hacks.ts b/src/util/hacks.ts index f2cf57c69a..add0a7b197 100644 --- a/src/util/hacks.ts +++ b/src/util/hacks.ts @@ -12,7 +12,9 @@ export const patchBabelCore_githubIssue6577: ModulePatcher = babel = // This is a hack to bypass it and fix our issue #627 // The bug disallow debugging when using Babel Jest with babel-core@6.x because of // source-maps not being inlined - if (typeof babel.version === 'string' && semver.satisfies(babel.version, '>=6 <7')) { + if (typeof babel.version !== 'string') return babel + const version = semver.coerce(babel.version) + if (version && version.major === 6) { try { const File = require('babel-core/lib/transformation/file').File File.prototype.initOptions = (original => {