diff --git a/packages/babel-standalone/test/transform-script-tags.test.js b/packages/babel-standalone/test/transform-script-tags.test.js index 2031e90bb929..58544dfa4409 100644 --- a/packages/babel-standalone/test/transform-script-tags.test.js +++ b/packages/babel-standalone/test/transform-script-tags.test.js @@ -1,9 +1,9 @@ import fs from "fs"; import { createRequire } from "module"; -import { itGte } from "$repo-utils"; +import { describeGte } from "$repo-utils"; const require = createRequire(import.meta.url); -describe("transformScriptTags", () => { +describeGte("16.0.0")("transformScriptTags", () => { let standaloneSource; let JSDOM; beforeAll(async () => { @@ -13,51 +13,45 @@ describe("transformScriptTags", () => { ); JSDOM = require("jsdom").JSDOM; }); - itGte("16.0.0")( - "should transform script element with type 'text/babel'", - () => { - const dom = new JSDOM( - `
`, - { runScripts: "dangerously" }, - ); - return new Promise((resolve, reject) => { - dom.window.addEventListener("DOMContentLoaded", () => { - try { - const transformedScriptElement = - dom.window.document.head.children.item(2); - expect(transformedScriptElement.getAttribute("type")).toBeNull(); - expect(transformedScriptElement.innerHTML).toContain( - "globalThis !== null && globalThis !== void 0 ? globalThis : window", - ); - resolve(); - } catch (err) { - reject(err); - } - }); + it("should transform script element with type 'text/babel'", () => { + const dom = new JSDOM( + ``, + { runScripts: "dangerously" }, + ); + return new Promise((resolve, reject) => { + dom.window.addEventListener("DOMContentLoaded", () => { + try { + const transformedScriptElement = + dom.window.document.head.children.item(2); + expect(transformedScriptElement.getAttribute("type")).toBeNull(); + expect(transformedScriptElement.innerHTML).toContain( + "globalThis !== null && globalThis !== void 0 ? globalThis : window", + ); + resolve(); + } catch (err) { + reject(err); + } }); - }, - ); - itGte("16.0.0")( - "should pass through the nonce attribute to the transformed script element", - () => { - const nonceAttribute = "nonce_example"; + }); + }); + it("should pass through the nonce attribute to the transformed script element", () => { + const nonceAttribute = "nonce_example"; - const dom = new JSDOM( - ``, - { runScripts: "dangerously" }, - ); - return new Promise((resolve, reject) => { - dom.window.addEventListener("DOMContentLoaded", () => { - try { - const transformedScriptElement = - dom.window.document.head.children.item(2); - expect(transformedScriptElement.nonce).toBe(nonceAttribute); - resolve(); - } catch (err) { - reject(err); - } - }); + const dom = new JSDOM( + ``, + { runScripts: "dangerously" }, + ); + return new Promise((resolve, reject) => { + dom.window.addEventListener("DOMContentLoaded", () => { + try { + const transformedScriptElement = + dom.window.document.head.children.item(2); + expect(transformedScriptElement.nonce).toBe(nonceAttribute); + resolve(); + } catch (err) { + reject(err); + } }); - }, - ); + }); + }); }); diff --git a/scripts/repo-utils/index.cjs b/scripts/repo-utils/index.cjs index 6748450a3105..d1520e134315 100644 --- a/scripts/repo-utils/index.cjs +++ b/scripts/repo-utils/index.cjs @@ -44,6 +44,9 @@ if (typeof jest !== "undefined") { exports.describeESM = USE_ESM ? describe : dummy; exports.describeBabel7 = process.env.BABEL_8_BREAKING ? dummy : describe; exports.describeBabel8 = process.env.BABEL_8_BREAKING ? describe : dummy; + exports.describeGte = function (version) { + return semver.gte(process.version, version) ? describe : describe.skip; + }; } exports.commonJS = function (metaUrl) { diff --git a/scripts/repo-utils/index.d.ts b/scripts/repo-utils/index.d.ts index a74d674a2ce8..7710d74bcf0f 100644 --- a/scripts/repo-utils/index.d.ts +++ b/scripts/repo-utils/index.d.ts @@ -17,3 +17,4 @@ export const itBabel7NoESM: jest.It; export const itDummy: jest.It; export const describeBabel7: jest.Describe; export const describeBabel8: jest.Describe; +export function describeGte(version: string): jest.Describe;