-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix regression test to use the proper Babel version (#15476)
- Loading branch information
1 parent
864b086
commit 15bd88c
Showing
1 changed file
with
27 additions
and
14 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,28 +1,41 @@ | ||
import * as babel7_12 from "@babel/core"; | ||
import * as babel7_12 from "@babel/core-7.12"; | ||
import env from "../lib/index.js"; | ||
import path from "path"; | ||
import { fileURLToPath } from "url"; | ||
|
||
describe("#12880", () => { | ||
afterEach(() => { | ||
jest.spyOn(process, "cwd").mockRestore(); | ||
}); | ||
|
||
it("read the .browserslistrc file when using @babel/core < 7.13.0", () => { | ||
const root = path.join( | ||
path.dirname(fileURLToPath(import.meta.url)), | ||
"regressions", | ||
); | ||
|
||
// The browserslistrc file contains "firefox 50". | ||
// a ** b is supported starting from firefox 52; | ||
// a => b is supported starting from firefox 45. | ||
const out = babel7_12.transformSync("a ** b; a => b;", { | ||
configFile: false, | ||
presets: [[env, { modules: false }]], | ||
filename: path.join(root, "input.js"), | ||
root, | ||
}); | ||
// Unfortunatly, when loading the browserslist config through | ||
// @babel/preset-env, it's resolved from process.cwd() and not | ||
// from root. Mock it to isolate this test. | ||
const spy = jest.spyOn(process, "cwd").mockReturnValue(root); | ||
|
||
try { | ||
// The browserslistrc file contains "firefox 50". | ||
// a ** b is supported starting from firefox 52; | ||
// a => b is supported starting from firefox 45. | ||
const out = babel7_12.transformSync("a ** b; a => b;", { | ||
configFile: false, | ||
presets: [[env, { modules: false }]], | ||
filename: path.join(root, "input.js"), | ||
root, | ||
}); | ||
|
||
expect(out.code).toMatchInlineSnapshot(` | ||
"Math.pow(a, b); | ||
a => b;" | ||
`); | ||
expect(out.code).toMatchInlineSnapshot(` | ||
"Math.pow(a, b); | ||
a => b;" | ||
`); | ||
} finally { | ||
spy.mockRestore(); | ||
} | ||
}); | ||
}); |