Skip to content

Commit

Permalink
Fix standalone tests for Babel 8
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Aug 2, 2023
1 parent c8ec22b commit 776da5f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/babel-standalone/test/babel.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import * as env from "./helpers/env.js";
import { createRequire } from "module";
const require = createRequire(import.meta.url);

// Basic smoke tests for @babel/standalone
describe("@babel/standalone", () => {
let Babel;
beforeAll(() => {
Babel = require("../babel.js");
env.setup();
try {
Babel = require("../babel.js");
} finally {
env.teardown();
}
});

it("handles the es2015-no-commonjs preset", () => {
Expand Down
18 changes: 18 additions & 0 deletions packages/babel-standalone/test/helpers/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function setup() {
// chalk, which we bundle in @babel/standalone, relies on `window.navigator`
// for the browser build:
// https://github.com/chalk/chalk/blob/f399cd0ff69841e88cca89d43a49f1cc9ba2efd5/source/vendor/supports-color/browser.js#L4
// We only bundle Chalk 5 in local dev and in Babel 8, so we avoid this
// "polyfill" when releasing Babel 7 to make sure that we do not accidentally
// bundle Chalk 5.

if (!process.env.IS_PUBLISH || process.env.BABEL_8_BREAKING) {
globalThis.navigator = {};
}
}

export function teardown() {
if (!process.env.IS_PUBLISH || process.env.BABEL_8_BREAKING) {
delete globalThis.navigator;
}
}
9 changes: 8 additions & 1 deletion packages/babel-standalone/test/preset-stage-1.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import * as env from "./helpers/env.js";

import { createRequire } from "module";
const require = createRequire(import.meta.url);

describe("stage-1 preset", () => {
let Babel;
beforeAll(() => {
Babel = require("../babel.js");
env.setup();
try {
Babel = require("../babel.js");
} finally {
env.teardown();
}
});

it("should parser decimal literal", () => {
Expand Down

0 comments on commit 776da5f

Please sign in to comment.