Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract more test helpers to repo-utils #15902

Merged
merged 8 commits into from Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions eslint/babel-eslint-parser/test/index.js
Expand Up @@ -22,8 +22,9 @@ const isESLint7 = ESLINT_VERSION.startsWith("7.");
const dirname = path.dirname(fileURLToPath(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 dummy = () => {};
JLHwung marked this conversation as resolved.
Show resolved Hide resolved
const itESLint7 = isESLint7 && !process.env.BABEL_8_BREAKING ? it : dummy;
const itESLint8 = isESLint7 ? dummy : it;

const BABEL_OPTIONS = {
configFile: path.resolve(
Expand Down
6 changes: 2 additions & 4 deletions 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 });
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-core/test/api.js
Expand Up @@ -11,8 +11,7 @@ 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";

const itBabel8 = process.env.BABEL_8_BREAKING ? it : it.skip;
import { itBabel8 } from "$repo-utils";

const cwd = path.dirname(fileURLToPath(import.meta.url));

Expand Down
3 changes: 1 addition & 2 deletions packages/babel-core/test/async.js
Expand Up @@ -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");
Expand Down
4 changes: 1 addition & 3 deletions packages/babel-core/test/config-loading.js
Expand Up @@ -10,12 +10,10 @@ import {
import path from "path";
import { fileURLToPath } from "url";
import { createRequire } from "module";
import { itNoWin32 } from "$repo-utils";
import { itNoWin32, itBabel8 } from "$repo-utils";

const require = createRequire(import.meta.url);

const itBabel8 = process.env.BABEL_8_BREAKING ? it : it.skip;

describe("@babel/core config loading", () => {
const FILEPATH = path.join(
path.dirname(fileURLToPath(import.meta.url)),
Expand Down
8 changes: 6 additions & 2 deletions 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);

Expand All @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions packages/babel-core/test/helpers/esm.js
Expand Up @@ -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(
Expand Down
5 changes: 1 addition & 4 deletions 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));

Expand All @@ -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(() => {
Expand Down
Expand Up @@ -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", () => {
Expand Down
15 changes: 7 additions & 8 deletions 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
Expand All @@ -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++;
Expand All @@ -30,7 +29,7 @@ itBabel7("simplifyAccess with default config", function () {
a++;
foo = a++;
foo = ++a;

let b = bar--;
b = --bar;
bar--;
Expand All @@ -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++;
Expand Down Expand Up @@ -108,7 +107,7 @@ it("simplifyAccess with includeUpdateExpression=false", function () {
a++;
foo = a++;
foo = ++a;

let b = bar--;
b = --bar;
bar--;
Expand All @@ -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++;
Expand Down
3 changes: 1 addition & 2 deletions 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" });
Expand Down
8 changes: 3 additions & 5 deletions 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 () =>
Expand All @@ -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();
});
Expand All @@ -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" }),
Expand Down
4 changes: 1 addition & 3 deletions 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 }) {
Expand Down
6 changes: 1 addition & 5 deletions packages/babel-preset-env/test/index.skip-bundled.js
Expand Up @@ -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", () => {
Expand Down
Expand Up @@ -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", () => {
Expand Down
11 changes: 2 additions & 9 deletions packages/babel-preset-env/test/regressions.js
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
@@ -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(`
Expand Down Expand Up @@ -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();
});
Expand Down
2 changes: 1 addition & 1 deletion 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", () => {
Expand Down
@@ -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'?",
Expand Down Expand Up @@ -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();
});
Expand Down
@@ -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'?",
Expand Down Expand Up @@ -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();
});
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-traverse/test/arrow-transform.js
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions 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 () {
Expand Down
4 changes: 1 addition & 3 deletions 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(
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-types/test/builders/core.js
@@ -1,6 +1,5 @@
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", () => {
Expand Down