diff --git a/babel.config.js b/babel.config.js index 47680d11f0ea..e327de7516c2 100644 --- a/babel.config.js +++ b/babel.config.js @@ -696,10 +696,10 @@ function pluginImportMetaUrl({ types: t, template }) { // We must be sure to run this before the istanbul plugins, because its // instrumentation breaks our detection. programPath.traverse({ - // fileURLToPath(import.meta.url) CallExpression(path) { const { node } = path; + // fileURLToPath(import.meta.url) if ( (function () { if ( @@ -731,6 +731,7 @@ function pluginImportMetaUrl({ types: t, template }) { return; } + // const { __dirname: cwd } = commonJS(import.meta.url) if ( !t.isIdentifier(node.callee, { name: "commonJS" }) || node.arguments.length !== 1 diff --git a/eslint/babel-eslint-parser/test/index.js b/eslint/babel-eslint-parser/test/index.js index c165964116cd..7ed5ed9ee3cf 100644 --- a/eslint/babel-eslint-parser/test/index.js +++ b/eslint/babel-eslint-parser/test/index.js @@ -1,10 +1,9 @@ import path from "path"; import escope from "eslint-scope"; import unpad from "dedent"; -import { fileURLToPath } from "url"; -import { createRequire } from "module"; import { parseForESLint as parseForESLintOriginal } from "../lib/index.cjs"; import { ESLint } from "eslint"; +import { itDummy, commonJS } from "$repo-utils"; function parseForESLint(code, options) { return parseForESLintOriginal(code, { @@ -19,11 +18,12 @@ function parseForESLint(code, options) { const ESLINT_VERSION = ESLint.version; const isESLint7 = ESLINT_VERSION.startsWith("7."); -const dirname = path.dirname(fileURLToPath(import.meta.url)); +const { __dirname: dirname, require } = commonJS(import.meta.url); // @babel/eslint-parser 8 will drop ESLint 7 support -const itESLint7 = isESLint7 && !process.env.BABEL_8_BREAKING ? it : it.skip; -const itESLint8 = isESLint7 ? it.skip : it; + +const itESLint7 = isESLint7 && !process.env.BABEL_8_BREAKING ? it : itDummy; +const itESLint8 = isESLint7 ? itDummy : it; const BABEL_OPTIONS = { configFile: path.resolve( @@ -122,8 +122,6 @@ describe("Babel and Espree", () => { } beforeAll(() => { - const require = createRequire(import.meta.url); - // Use the version of Espree that is a dependency of // the version of ESLint we are testing against. const espreePath = require.resolve("espree", { diff --git a/eslint/babel-eslint-tests/test/integration/config-files.js b/eslint/babel-eslint-tests/test/integration/config-files.js index 4f52c10c07e8..2a313be2284e 100644 --- a/eslint/babel-eslint-tests/test/integration/config-files.js +++ b/eslint/babel-eslint-tests/test/integration/config-files.js @@ -1,12 +1,10 @@ import { ESLint } from "eslint"; import path from "path"; import { fileURLToPath } from "url"; -import { USE_ESM } from "$repo-utils"; +import { itESM, itGteNoESM } from "$repo-utils"; describe("Babel config files", () => { - const itESM = USE_ESM ? it : it.skip; - const nodeGte12NoESM = - USE_ESM || parseInt(process.versions.node) < 12 ? it.skip : it; + const nodeGte12NoESM = itGteNoESM("12.0.0"); itESM("works with babel.config.mjs", async () => { const engine = new ESLint({ ignore: false }); diff --git a/packages/babel-core/test/api.js b/packages/babel-core/test/api.js index 3aeaf67bec97..79a0d9ae7973 100644 --- a/packages/babel-core/test/api.js +++ b/packages/babel-core/test/api.js @@ -2,7 +2,6 @@ import * as babel from "../lib/index.js"; import { TraceMap, originalPositionFor } from "@jridgewell/trace-mapping"; import path from "path"; import generator from "@babel/generator"; -import { fileURLToPath } from "url"; import _Plugin from "../lib/config/plugin.js"; const Plugin = _Plugin.default || _Plugin; @@ -11,10 +10,10 @@ import presetEnv from "@babel/preset-env"; import pluginSyntaxFlow from "@babel/plugin-syntax-flow"; import pluginSyntaxJSX from "@babel/plugin-syntax-jsx"; import pluginFlowStripTypes from "@babel/plugin-transform-flow-strip-types"; +import { itBabel8, commonJS } from "$repo-utils"; -const itBabel8 = process.env.BABEL_8_BREAKING ? it : it.skip; - -const cwd = path.dirname(fileURLToPath(import.meta.url)); +const { __dirname } = commonJS(import.meta.url); +const cwd = __dirname; function assertIgnored(result) { expect(result).toBeNull(); diff --git a/packages/babel-core/test/async.js b/packages/babel-core/test/async.js index 4b3495040bb7..1068f6fe3021 100644 --- a/packages/babel-core/test/async.js +++ b/packages/babel-core/test/async.js @@ -6,10 +6,9 @@ import { spawnTransformAsync, spawnTransformSync, supportsESM, - itESM, } from "./helpers/esm.js"; -import { itGte } from "$repo-utils"; +import { itGte, itESM } from "$repo-utils"; // "minNodeVersion": "8.0.0" <-- For Ctrl+F when dropping node 6 const nodeGte8 = itGte("8.0.0"); diff --git a/packages/babel-core/test/config-loading.js b/packages/babel-core/test/config-loading.js index 427cf5fda468..5a20c7dc7b53 100644 --- a/packages/babel-core/test/config-loading.js +++ b/packages/babel-core/test/config-loading.js @@ -8,17 +8,13 @@ import { createConfigItemSync, } from "../lib/index.js"; import path from "path"; -import { fileURLToPath } from "url"; -import { createRequire } from "module"; -import { itNoWin32 } from "$repo-utils"; +import { itNoWin32, itBabel8, commonJS } from "$repo-utils"; -const require = createRequire(import.meta.url); - -const itBabel8 = process.env.BABEL_8_BREAKING ? it : it.skip; +const { require, __dirname } = commonJS(import.meta.url); describe("@babel/core config loading", () => { const FILEPATH = path.join( - path.dirname(fileURLToPath(import.meta.url)), + __dirname, "fixtures", "config-loading", "folder", @@ -152,7 +148,7 @@ describe("@babel/core config loading", () => { it("should always set 'rootMode' to 'root'", async () => { const cwd = path.join( - path.dirname(fileURLToPath(import.meta.url)), + __dirname, "fixtures", "config-loading", "root", diff --git a/packages/babel-core/test/esm-cjs-integration.js b/packages/babel-core/test/esm-cjs-integration.js index d87f2000d3e7..1d6c833008a2 100644 --- a/packages/babel-core/test/esm-cjs-integration.js +++ b/packages/babel-core/test/esm-cjs-integration.js @@ -1,6 +1,6 @@ import { execFile } from "child_process"; import { createRequire } from "module"; -import { outputType } from "./helpers/esm.js"; +import { describeESM } from "$repo-utils"; const require = createRequire(import.meta.url); @@ -18,7 +18,11 @@ async function run(name) { }); } -(outputType === "module" ? describe : describe.skip)("usage from cjs", () => { +describe("dummy", () => { + it("dummy", () => {}); +}); + +describeESM("usage from cjs", () => { it("lazy plugin required", async () => { expect(await run("lazy-plugin-required.cjs")).toMatchInlineSnapshot(` Object { diff --git a/packages/babel-core/test/helpers/esm.js b/packages/babel-core/test/helpers/esm.js index fac6e6ccfa0a..dc191a184725 100644 --- a/packages/babel-core/test/helpers/esm.js +++ b/packages/babel-core/test/helpers/esm.js @@ -14,8 +14,6 @@ export const outputType = USE_ESM ? "module" : "script"; export const isMJS = file => path.extname(file) === ".mjs"; -export const itESM = supportsESM ? it : it.skip; - export function skipUnsupportedESM(name) { if (!supportsESM) { console.warn( diff --git a/packages/babel-core/test/option-manager.js b/packages/babel-core/test/option-manager.js index 0fcd5cb96720..11aef78b8afb 100644 --- a/packages/babel-core/test/option-manager.js +++ b/packages/babel-core/test/option-manager.js @@ -1,7 +1,7 @@ import * as babel from "../lib/index.js"; import path from "path"; import { fileURLToPath } from "url"; -import { USE_ESM } from "$repo-utils"; +import { itBabel7, itBabel7NoESM } from "$repo-utils"; const cwd = path.dirname(fileURLToPath(import.meta.url)); @@ -13,9 +13,6 @@ function loadOptionsAsync(opts) { return babel.loadOptionsAsync({ cwd, ...opts }); } -const itBabel7 = process.env.BABEL_8_BREAKING ? it.skip : it; -const itBabel7NoESM = process.env.BABEL_8_BREAKING || USE_ESM ? it.skip : it; - describe("option-manager", () => { itBabel7NoESM("throws for babel 5 plugin", () => { return expect(() => { diff --git a/packages/babel-helper-compilation-targets/test/targets-parser.spec.js b/packages/babel-helper-compilation-targets/test/targets-parser.spec.js index 759699642d70..a1dfa858d0c0 100644 --- a/packages/babel-helper-compilation-targets/test/targets-parser.spec.js +++ b/packages/babel-helper-compilation-targets/test/targets-parser.spec.js @@ -4,9 +4,7 @@ import { fileURLToPath } from "url"; import _getTargets from "../lib/index.js"; const getTargets = _getTargets.default || _getTargets; - -const itBabel7 = process.env.BABEL_8_BREAKING ? it.skip : it; -const itBabel8 = process.env.BABEL_8_BREAKING ? it : it.skip; +import { itBabel8, itBabel7 } from "$repo-utils"; describe("getTargets", () => { it("parses", () => { diff --git a/packages/babel-helper-simple-access/test/index.js b/packages/babel-helper-simple-access/test/index.js index 349593c0cde3..a7bb3755504f 100644 --- a/packages/babel-helper-simple-access/test/index.js +++ b/packages/babel-helper-simple-access/test/index.js @@ -1,5 +1,6 @@ import * as babel from "@babel/core"; import simplifyAccess from "../lib/index.js"; +import { itBabel7 } from "$repo-utils"; const plugin = (_api, options) => { // TODO(Babel 8): Remove includeUpdateExpression @@ -18,8 +19,6 @@ const plugin = (_api, options) => { }; }; -const itBabel7 = process.env.BABEL_8_BREAKING ? it.skip : it; - itBabel7("simplifyAccess with default config", function () { const code = ` let a = foo++; @@ -30,7 +29,7 @@ itBabel7("simplifyAccess with default config", function () { a++; foo = a++; foo = ++a; - + let b = bar--; b = --bar; bar--; @@ -39,11 +38,11 @@ itBabel7("simplifyAccess with default config", function () { b--; bar = b--; bar = --b; - + let c = baz += 1; baz += 1; c += 1; - + function f() { let foo = 1; let a = foo++; @@ -108,7 +107,7 @@ it("simplifyAccess with includeUpdateExpression=false", function () { a++; foo = a++; foo = ++a; - + let b = bar--; b = --bar; bar--; @@ -117,11 +116,11 @@ it("simplifyAccess with includeUpdateExpression=false", function () { b--; bar = b--; bar = --b; - + let c = baz += 1; baz += 1; c += 1; - + function f() { let foo = 1; let a = foo++; diff --git a/packages/babel-parser/test/plugin-options.js b/packages/babel-parser/test/plugin-options.js index ca35440a38cc..55bf43158191 100644 --- a/packages/babel-parser/test/plugin-options.js +++ b/packages/babel-parser/test/plugin-options.js @@ -1,6 +1,5 @@ import { parse } from "../lib/index.js"; - -const itBabel8 = process.env.BABEL_8_BREAKING ? it : it.skip; +import { itBabel8 } from "$repo-utils"; function getParser(code, plugins) { return () => parse(code, { plugins, sourceType: "module" }); diff --git a/packages/babel-plugin-syntax-decorators/test/index.js b/packages/babel-plugin-syntax-decorators/test/index.js index 7052f834848b..191bb694a1a3 100644 --- a/packages/babel-plugin-syntax-decorators/test/index.js +++ b/packages/babel-plugin-syntax-decorators/test/index.js @@ -1,5 +1,6 @@ import { parseSync } from "@babel/core"; import syntaxDecorators from "../lib/index.js"; +import { itBabel8, describeBabel7 } from "$repo-utils"; function makeParser(code, options) { return () => @@ -10,10 +11,7 @@ function makeParser(code, options) { }); } -const itBabel8 = process.env.BABEL_8_BREAKING ? test : test.skip; -const babel7describe = process.env.BABEL_8_BREAKING ? describe.skip : describe; - -babel7describe("'legacy' option", function () { +describeBabel7("'legacy' option", function () { test("legacy must be boolean", function () { expect(makeParser("", { legacy: "legacy" })).toThrow(); }); @@ -31,7 +29,7 @@ babel7describe("'legacy' option", function () { }); }); -babel7describe("'decoratorsBeforeExport' option", function () { +describeBabel7("'decoratorsBeforeExport' option", function () { test("decoratorsBeforeExport must be boolean", function () { expect( makeParser("", { version: "2021-12", decoratorsBeforeExport: "before" }), diff --git a/packages/babel-preset-env/test/import-meta.js b/packages/babel-preset-env/test/import-meta.js index 072b38a8cae5..70c8878377b0 100644 --- a/packages/babel-preset-env/test/import-meta.js +++ b/packages/babel-preset-env/test/import-meta.js @@ -1,8 +1,6 @@ import env from "../lib/index.js"; import * as babel from "@babel/core"; -import { itNoESM } from "$repo-utils"; - -const itBabel7NoESM = process.env.BABEL_8_BREAKING ? it.skip : itNoESM; +import { itBabel7NoESM } from "$repo-utils"; describe("preset-env", () => { function extractParserOptions(api, { ref }) { diff --git a/packages/babel-preset-env/test/index.skip-bundled.js b/packages/babel-preset-env/test/index.skip-bundled.js index 98fe4c2d2450..9db59aa13a1d 100644 --- a/packages/babel-preset-env/test/index.skip-bundled.js +++ b/packages/babel-preset-env/test/index.skip-bundled.js @@ -34,11 +34,7 @@ if (/* commonjs */ _transformations.default) { pluginCoreJS3 = _pluginCoreJS3_esm; pluginRegenerator = _pluginRegenerator_esm; } - -const itBabel7 = process.env.BABEL_8_BREAKING ? it.skip : it; -const itBabel8 = process.env.BABEL_8_BREAKING ? it : it.skip; - -const describeBabel7 = process.env.BABEL_8_BREAKING ? describe.skip : describe; +import { itBabel7, itBabel8, describeBabel7 } from "$repo-utils"; describe("babel-preset-env", () => { describe("transformIncludesAndExcludes", () => { diff --git a/packages/babel-preset-env/test/normalize-options.skip-bundled.js b/packages/babel-preset-env/test/normalize-options.skip-bundled.js index 4bfbd1a0b173..586432464fdd 100644 --- a/packages/babel-preset-env/test/normalize-options.skip-bundled.js +++ b/packages/babel-preset-env/test/normalize-options.skip-bundled.js @@ -5,8 +5,7 @@ import _normalizeOptions, { normalizePluginName, } from "../lib/normalize-options.js"; const normalizeOptions = _normalizeOptions.default || _normalizeOptions; - -const itBabel7 = process.env.BABEL_8_BREAKING ? it.skip : it; +import { itBabel7 } from "$repo-utils"; describe("normalize-options", () => { describe("normalizeOptions", () => { diff --git a/packages/babel-preset-env/test/regressions.js b/packages/babel-preset-env/test/regressions.js index c4a8770ea7f0..ac4994151fb6 100644 --- a/packages/babel-preset-env/test/regressions.js +++ b/packages/babel-preset-env/test/regressions.js @@ -3,18 +3,10 @@ import * as babel from "@babel/core"; import env from "../lib/index.js"; import path from "path"; import { fileURLToPath } from "url"; -import { USE_ESM, commonJS } from "$repo-utils"; +import { commonJS, itBabel7, itBabel7GteNoESM } from "$repo-utils"; const { require } = commonJS(import.meta.url); -const itBabel7 = process.env.BABEL_8_BREAKING ? it.skip : it; -const itBabel7NodeGte14NoESM = - process.env.BABEL_8_BREAKING || - parseInt(process.versions.node) < 14 || - USE_ESM - ? it.skip - : it; - describe("regressions", () => { it("empty", () => { // TODO(Babel 8): Delete this file @@ -54,6 +46,7 @@ describe("regressions", () => { }, ); + const itBabel7NodeGte14NoESM = itBabel7GteNoESM("14.0.0"); // create-reat-app missing dependency fallback // jest fake timers only work in the Jest version we are using for Node.js 14+ itBabel7NodeGte14NoESM( diff --git a/packages/babel-preset-flow/test/normalize-options.skip-bundled.js b/packages/babel-preset-flow/test/normalize-options.skip-bundled.js index 024a87cddd65..18323896b46f 100644 --- a/packages/babel-preset-flow/test/normalize-options.skip-bundled.js +++ b/packages/babel-preset-flow/test/normalize-options.skip-bundled.js @@ -1,8 +1,9 @@ import _normalizeOptions from "../lib/normalize-options.js"; const normalizeOptions = _normalizeOptions.default || _normalizeOptions; +import { describeBabel8, describeBabel7 } from "$repo-utils"; describe("normalize options", () => { - (process.env.BABEL_8_BREAKING ? describe : describe.skip)("Babel 8", () => { + describeBabel8("Babel 8", () => { it("should throw on unknown options", () => { expect(() => normalizeOptions({ al: true })) .toThrowErrorMatchingInlineSnapshot(` @@ -34,7 +35,7 @@ describe("normalize options", () => { `); }); }); - (process.env.BABEL_8_BREAKING ? describe.skip : describe)("Babel 7", () => { + describeBabel7("Babel 7", () => { it("should not throw on unknown options", () => { expect(() => normalizeOptions({ allDeclareField: true })).not.toThrow(); }); diff --git a/packages/babel-preset-react/test/index.js b/packages/babel-preset-react/test/index.js index 265c8a610387..0e3dd168f5c3 100644 --- a/packages/babel-preset-react/test/index.js +++ b/packages/babel-preset-react/test/index.js @@ -1,7 +1,7 @@ import _reactPreset from "../lib/index.js"; const reactPreset = _reactPreset.default || _reactPreset; -const itBabel8 = process.env.BABEL_8_BREAKING ? it : it.skip; +import { itBabel8 } from "$repo-utils"; describe("react preset", () => { it("does throw clear error when no options passed for Babel 6", () => { diff --git a/packages/babel-preset-react/test/normalize-options.skip-bundled.js b/packages/babel-preset-react/test/normalize-options.skip-bundled.js index f12872002120..805cf49eaa52 100644 --- a/packages/babel-preset-react/test/normalize-options.skip-bundled.js +++ b/packages/babel-preset-react/test/normalize-options.skip-bundled.js @@ -1,8 +1,9 @@ import _normalizeOptions from "../lib/normalize-options.js"; const normalizeOptions = _normalizeOptions.default || _normalizeOptions; +import { describeBabel8, describeBabel7 } from "$repo-utils"; describe("normalize options", () => { - (process.env.BABEL_8_BREAKING ? describe : describe.skip)("Babel 8", () => { + describeBabel8("Babel 8", () => { it("should throw on unknown options", () => { expect(() => normalizeOptions({ throwIfNamespaces: true })).toThrow( "@babel/preset-react: 'throwIfNamespaces' is not a valid top-level option.\n- Did you mean 'throwIfNamespace'?", @@ -80,7 +81,7 @@ describe("normalize options", () => { `); }); }); - (process.env.BABEL_8_BREAKING ? describe.skip : describe)("Babel 7", () => { + describeBabel7("Babel 7", () => { it("should not throw on unknown options", () => { expect(() => normalizeOptions({ throwIfNamespaces: true })).not.toThrow(); }); diff --git a/packages/babel-preset-typescript/test/normalize-options.skip-bundled.js b/packages/babel-preset-typescript/test/normalize-options.skip-bundled.js index b8552c183fc2..b17ebbb319b6 100644 --- a/packages/babel-preset-typescript/test/normalize-options.skip-bundled.js +++ b/packages/babel-preset-typescript/test/normalize-options.skip-bundled.js @@ -1,8 +1,9 @@ import _normalizeOptions from "../lib/normalize-options.js"; const normalizeOptions = _normalizeOptions.default || _normalizeOptions; +import { describeBabel8, describeBabel7 } from "$repo-utils"; describe("normalize options", () => { - (process.env.BABEL_8_BREAKING ? describe : describe.skip)("Babel 8", () => { + describeBabel8("Babel 8", () => { it("should throw on unknown options", () => { expect(() => normalizeOptions({ allowNamespace: true })).toThrow( "@babel/preset-typescript: 'allowNamespace' is not a valid top-level option.\n- Did you mean 'allowNamespaces'?", @@ -51,7 +52,7 @@ describe("normalize options", () => { `); }); }); - (process.env.BABEL_8_BREAKING ? describe.skip : describe)("Babel 7", () => { + describeBabel7("Babel 7", () => { it("should not throw on unknown options", () => { expect(() => normalizeOptions({ allowNamespace: true })).not.toThrow(); }); diff --git a/packages/babel-traverse/test/arrow-transform.js b/packages/babel-traverse/test/arrow-transform.js index 2105e9762761..91492d941b3f 100644 --- a/packages/babel-traverse/test/arrow-transform.js +++ b/packages/babel-traverse/test/arrow-transform.js @@ -5,6 +5,8 @@ import * as t from "@babel/types"; import _generate from "@babel/generator"; const generate = _generate.default || _generate; +import { itBabel7 } from "$repo-utils"; + function assertConversion( input, output, @@ -48,8 +50,6 @@ function wrapMethod(body, methodName, extend) { ); } -const itBabel7 = process.env.BABEL_8_BREAKING ? it.skip : it; - describe("arrow function conversion", () => { it("should convert super calls in constructors", () => { assertConversion( diff --git a/packages/babel-traverse/test/hub.js b/packages/babel-traverse/test/hub.js index e179684f528a..b3447b30c00b 100644 --- a/packages/babel-traverse/test/hub.js +++ b/packages/babel-traverse/test/hub.js @@ -1,7 +1,6 @@ import { transformSync } from "@babel/core"; import { Hub } from "../lib/index.js"; - -const itBabel8 = process.env.BABEL_8_BREAKING ? it : it.skip; +import { itBabel8 } from "$repo-utils"; describe("hub", function () { it("default buildError should return TypeError", function () { diff --git a/packages/babel-traverse/test/visitors.js b/packages/babel-traverse/test/visitors.js index c6ae6effae0f..ca0cc9b045a9 100644 --- a/packages/babel-traverse/test/visitors.js +++ b/packages/babel-traverse/test/visitors.js @@ -1,10 +1,8 @@ import { parse } from "@babel/parser"; - +import { itBabel8 } from "$repo-utils"; import _traverse, { visitors } from "../lib/index.js"; const traverse = _traverse.default || _traverse; -const itBabel8 = process.env.BABEL_8_BREAKING ? it : it.skip; - describe("visitors", () => { describe("merge", () => { itBabel8( diff --git a/packages/babel-types/test/builders/core.js b/packages/babel-types/test/builders/core.js index 15b09ad75aac..380b4b67aab7 100644 --- a/packages/babel-types/test/builders/core.js +++ b/packages/babel-types/test/builders/core.js @@ -1,13 +1,15 @@ import * as t from "../../lib/index.js"; - -const itBabel8 = process.env.BABEL_8_BREAKING ? it : it.skip; +import { itBabel8 } from "$repo-utils"; describe("builders", function () { - itBabel8("t.numericLiteral expexts a non-negative finite value", () => { + itBabel8("t.numericLiteral expects a non-negative finite value", () => { expect(() => t.numericLiteral(-1)).toThrow(); expect(() => t.numericLiteral(-0)).toThrow(); expect(() => t.numericLiteral(-Infinity)).toThrow(); expect(() => t.numericLiteral(Infinity)).toThrow(); expect(() => t.numericLiteral(NaN)).toThrow(); }); + it("t.bigIntLiteral expects a string value", () => { + expect(t.bigIntLiteral("1")).toHaveProperty("value", "1"); + }); }); diff --git a/packages/babel-types/test/builders/typescript/tsTypeParameter.js b/packages/babel-types/test/builders/typescript/tsTypeParameter.js index 95c8287cd33b..8db7ad5beb55 100644 --- a/packages/babel-types/test/builders/typescript/tsTypeParameter.js +++ b/packages/babel-types/test/builders/typescript/tsTypeParameter.js @@ -1,17 +1,16 @@ import * as t from "../../../lib/index.js"; +import { describeBabel8, describeBabel7 } from "$repo-utils"; describe("builders", function () { describe("typescript", function () { - (process.env.BABEL_8_BREAKING ? describe : describe.skip)( - "tsTypeParameter", - function () { - it("accept name as argument for tsTypeParameter", function () { - const tsTypeParameter = t.tsTypeParameter( - t.tsTypeReference(t.identifier("bar")), - t.tsTypeReference(t.identifier("baz")), - t.identifier("foo"), - ); - expect(tsTypeParameter).toMatchInlineSnapshot(` + describeBabel8("tsTypeParameter", function () { + it("accept name as argument for tsTypeParameter", function () { + const tsTypeParameter = t.tsTypeParameter( + t.tsTypeReference(t.identifier("bar")), + t.tsTypeReference(t.identifier("baz")), + t.identifier("foo"), + ); + expect(tsTypeParameter).toMatchInlineSnapshot(` Object { "constraint": Object { "type": "TSTypeReference", @@ -36,29 +35,26 @@ describe("builders", function () { "type": "TSTypeParameter", } `); - }); - it("throws when name is missing", function () { - expect(() => { - t.tsTypeParameter( - t.tsTypeReference(t.identifier("bar")), - t.tsTypeReference(t.identifier("baz")), - ); - }).toThrow( - 'Property name of TSTypeParameter expected node to be of a type ["Identifier"] but instead got undefined', - ); - }); - }, - ); - (process.env.BABEL_8_BREAKING ? describe.skip : describe)( - "tsTypeParameter - Babel 7", - function () { - it("accept name as argument for tsTypeParameter in Babel 7", function () { - const tsTypeParameter = t.tsTypeParameter( + }); + it("throws when name is missing", function () { + expect(() => { + t.tsTypeParameter( t.tsTypeReference(t.identifier("bar")), t.tsTypeReference(t.identifier("baz")), - "foo", ); - expect(tsTypeParameter).toMatchInlineSnapshot(` + }).toThrow( + 'Property name of TSTypeParameter expected node to be of a type ["Identifier"] but instead got undefined', + ); + }); + }); + describeBabel7("tsTypeParameter - Babel 7", function () { + it("accept name as argument for tsTypeParameter in Babel 7", function () { + const tsTypeParameter = t.tsTypeParameter( + t.tsTypeReference(t.identifier("bar")), + t.tsTypeReference(t.identifier("baz")), + "foo", + ); + expect(tsTypeParameter).toMatchInlineSnapshot(` Object { "constraint": Object { "type": "TSTypeReference", @@ -80,16 +76,15 @@ describe("builders", function () { "type": "TSTypeParameter", } `); - }); - it("throws when name is missing in Babel 7", function () { - expect(() => { - t.tsTypeParameter( - t.tsTypeReference(t.identifier("bar")), - t.tsTypeReference(t.identifier("baz")), - ); - }).toThrow("Property name expected type of string but got undefined"); - }); - }, - ); + }); + it("throws when name is missing in Babel 7", function () { + expect(() => { + t.tsTypeParameter( + t.tsTypeReference(t.identifier("bar")), + t.tsTypeReference(t.identifier("baz")), + ); + }).toThrow("Property name expected type of string but got undefined"); + }); + }); }); }); diff --git a/packages/babel-types/test/regressions.js b/packages/babel-types/test/regressions.js index 1b6695a41a77..69e704c956f9 100644 --- a/packages/babel-types/test/regressions.js +++ b/packages/babel-types/test/regressions.js @@ -1,9 +1,8 @@ import * as t from "../lib/index.js"; import * as vm from "vm"; +import { itBabel7 } from "$repo-utils"; describe("regressions", () => { - const itBabel7 = process.env.BABEL_TYPES_8_BREAKING ? it.skip : it; - itBabel7("jest .toMatchInlineSnapshot used 'Line' for comments", () => { expect(() => { t.file(t.program([]), [{ type: "Line" }]); diff --git a/scripts/repo-utils/index.cjs b/scripts/repo-utils/index.cjs index 2b0da1f6f7a2..6748450a3105 100644 --- a/scripts/repo-utils/index.cjs +++ b/scripts/repo-utils/index.cjs @@ -18,18 +18,32 @@ try { exports.USE_ESM = USE_ESM; if (typeof jest !== "undefined") { - exports.itNoESM = USE_ESM ? it.skip : it; - exports.itESM = USE_ESM ? it : it.skip; + const dummy = () => {}; + dummy.only = dummy.skip = dummy; + exports.itDummy = dummy; + exports.itNoESM = USE_ESM ? dummy : it; + exports.itESM = USE_ESM ? it : dummy; exports.itGteESM = function (version) { - return USE_ESM && semver.gte(process.version, version) ? it : it.skip; + return USE_ESM && semver.gte(process.version, version) ? it : dummy; }; exports.itGteNoESM = function (version) { - return !USE_ESM && semver.gte(process.version, version) ? it : it.skip; + return !USE_ESM && semver.gte(process.version, version) ? it : dummy; }; exports.itGte = function (version) { - return semver.gte(process.version, version) ? it : it.skip; + return semver.gte(process.version, version) ? it : dummy; }; - exports.itNoWin32 = process.platform === "win32" ? it.skip : it; + exports.itNoWin32 = process.platform === "win32" ? dummy : it; + exports.itBabel8 = process.env.BABEL_8_BREAKING ? it : dummy; + exports.itBabel7 = process.env.BABEL_8_BREAKING ? dummy : it; + exports.itBabel7NoESM = process.env.BABEL_8_BREAKING + ? dummy + : exports.itNoESM; + exports.itBabel7GteNoESM = function (version) { + return process.env.BABEL_8_BREAKING ? dummy : exports.itGteNoESM(version); + }; + 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.commonJS = function (metaUrl) { diff --git a/scripts/repo-utils/index.d.ts b/scripts/repo-utils/index.d.ts index 77920b8d2796..a74d674a2ce8 100644 --- a/scripts/repo-utils/index.d.ts +++ b/scripts/repo-utils/index.d.ts @@ -9,3 +9,11 @@ export const itESM: jest.It; export function itGteNoESM(version: string): jest.It; export function itGteESM(version: string): jest.It; export function itGte(version: string): jest.It; +export function itBabel7GteNoESM(version: string): jest.It; +export const itNoWin32: jest.It; +export const itBabel8: jest.It; +export const itBabel7: jest.It; +export const itBabel7NoESM: jest.It; +export const itDummy: jest.It; +export const describeBabel7: jest.Describe; +export const describeBabel8: jest.Describe;