Skip to content

Commit

Permalink
Fix regression test to use the proper Babel version (#15476)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Mar 10, 2023
1 parent 864b086 commit 15bd88c
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions packages/babel-preset-env/test/regressions.js
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();
}
});
});

0 comments on commit 15bd88c

Please sign in to comment.