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

enable jest/no-standalone-expect #15872

Merged
merged 3 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 20 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,26 @@ module.exports = [
config.rules = {
...config.rules,
"jest/expect-expect": "off",
"jest/no-standalone-expect": "off",
"jest/no-standalone-expect": [
"error",
{
additionalTestBlockFunctions: [
"itBabel7",
"itBabel7NoESM",
"itBabel7NodeGte14NoESM",
"itBabel8",
"itESLint7",
"itESLint8",
"itNoESM",
"itNoWin32",
"itESM",
"nodeGte8",
"nodeGte12",
"nodeGte12NoESM",
"testFn",
],
},
],
"jest/no-test-callback": "off",
"jest/valid-describe": "off",
"import/extensions": ["error", "always"],
Expand Down
10 changes: 5 additions & 5 deletions eslint/babel-eslint-parser/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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 itNotESLint7 = isESLint7 ? it.skip : it;
const itESLint8 = isESLint7 ? it.skip : it;

const BABEL_OPTIONS = {
configFile: path.resolve(
Expand Down Expand Up @@ -435,7 +435,7 @@ describe("Babel and Espree", () => {
expect(babylonAST.tokens[3].value).toEqual("#");
});

itNotESLint7("private identifier (token) - ESLint 8", () => {
itESLint8("private identifier (token) - ESLint 8", () => {
const code = "class A { #x }";
const babylonAST = parseForESLint(code, {
eslintVisitorKeys: true,
Expand Down Expand Up @@ -492,7 +492,7 @@ describe("Babel and Espree", () => {
expect(classDeclaration.body.body[0].type).toEqual("PropertyDefinition");
});

itNotESLint7("class fields with ESLint 8", () => {
itESLint8("class fields with ESLint 8", () => {
parseAndAssertSame(
`
class A {
Expand Down Expand Up @@ -536,7 +536,7 @@ describe("Babel and Espree", () => {
).toMatchObject(staticKw);
});

itNotESLint7("static (token) - ESLint 8", () => {
itESLint8("static (token) - ESLint 8", () => {
const code = `
class A {
static m() {}
Expand Down Expand Up @@ -593,7 +593,7 @@ describe("Babel and Espree", () => {
expect(babylonAST.tokens[17]).toMatchObject(topicToken);
});

itNotESLint7("pipeline # topic token - ESLint 8", () => {
itESLint8("pipeline # topic token - ESLint 8", () => {
const code = `
x |> #
y |> #[0]
Expand Down
4 changes: 2 additions & 2 deletions eslint/babel-eslint-tests/test/integration/config-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { USE_ESM } from "$repo-utils";

describe("Babel config files", () => {
const itESM = USE_ESM ? it : it.skip;
const itNode12upNoESM =
const nodeGte12NoESM =
USE_ESM || parseInt(process.versions.node) < 12 ? it.skip : it;

itESM("works with babel.config.mjs", async () => {
Expand All @@ -20,7 +20,7 @@ describe("Babel config files", () => {
).toMatchObject([{ errorCount: 0 }]);
});

itNode12upNoESM(
nodeGte12NoESM(
"experimental worker works with babel.config.mjs",
async () => {
const engine = new ESLint({ ignore: false });
Expand Down
5 changes: 3 additions & 2 deletions eslint/babel-eslint-tests/test/integration/parser-override.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from "path";
import { fileURLToPath } from "url";
import { createRequire } from "module";
import * as babelESLint from "@babel/eslint-parser";
import { itGte } from "$repo-utils";

describe("parserOverride", () => {
const expectedAST = {
Expand Down Expand Up @@ -31,8 +32,8 @@ describe("parserOverride", () => {
expect(ast).toMatchObject(expectedAST);
});

const babel7node12 = parseInt(process.versions.node) < 12 ? it.skip : it;
babel7node12("works when parsing in a worker", async () => {
const nodeGte12 = itGte("12.0.0");
nodeGte12("works when parsing in a worker", async () => {
const require = createRequire(import.meta.url);
// eslint-disable-next-line import/extensions
const babelESLintWorker = require("@babel/eslint-parser/experimental-worker");
Expand Down
55 changes: 24 additions & 31 deletions packages/babel-core/test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ 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;

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

function assertIgnored(result) {
Expand Down Expand Up @@ -173,26 +175,20 @@ describe("api", function () {
expect(babel.tokTypes).toBeDefined();
});

(process.env.BABEL_8_BREAKING ? it : it.skip)(
"parse throws on undefined callback",
() => {
expect(() => parse("", {})).toThrowErrorMatchingInlineSnapshot(
`"Starting from Babel 8.0.0, the 'parse' function expects a callback. If you need to call it synchronously, please use 'parseSync'."`,
);
},
);
itBabel8("parse throws on undefined callback", () => {
expect(() => parse("", {})).toThrowErrorMatchingInlineSnapshot(
`"Starting from Babel 8.0.0, the 'parse' function expects a callback. If you need to call it synchronously, please use 'parseSync'."`,
);
});

(process.env.BABEL_8_BREAKING ? it : it.skip)(
"transform throws on undefined callback",
() => {
const options = {
filename: "example.js",
};
expect(() => transform("", options)).toThrowErrorMatchingInlineSnapshot(
`"Starting from Babel 8.0.0, the 'transform' function expects a callback. If you need to call it synchronously, please use 'transformSync'."`,
);
},
);
itBabel8("transform throws on undefined callback", () => {
const options = {
filename: "example.js",
};
expect(() => transform("", options)).toThrowErrorMatchingInlineSnapshot(
`"Starting from Babel 8.0.0, the 'transform' function expects a callback. If you need to call it synchronously, please use 'transformSync'."`,
);
});

it("transformFile", function () {
const options = {
Expand Down Expand Up @@ -249,18 +245,15 @@ describe("api", function () {
expect(options).toEqual({ babelrc: false });
});

(process.env.BABEL_8_BREAKING ? it : it.skip)(
"transformFromAst throws on undefined callback",
() => {
const program = "const identifier = 1";
const node = parseSync(program);
expect(() =>
transformFromAst(node, program),
).toThrowErrorMatchingInlineSnapshot(
`"Starting from Babel 8.0.0, the 'transformFromAst' function expects a callback. If you need to call it synchronously, please use 'transformFromAstSync'."`,
);
},
);
itBabel8("transformFromAst throws on undefined callback", () => {
const program = "const identifier = 1";
const node = parseSync(program);
expect(() =>
transformFromAst(node, program),
).toThrowErrorMatchingInlineSnapshot(
`"Starting from Babel 8.0.0, the 'transformFromAst' function expects a callback. If you need to call it synchronously, please use 'transformFromAstSync'."`,
);
});

it("transformFromAst should generate same code with different cloneInputAst", function () {
const program = `//test1
Expand Down
9 changes: 4 additions & 5 deletions packages/babel-core/test/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import {
itESM,
} from "./helpers/esm.js";

const nodeGte8 = (...args) => {
// "minNodeVersion": "8.0.0" <-- For Ctrl+F when dropping node 6
const testFn = process.version.slice(0, 3) === "v6." ? it.skip : it;
testFn(...args);
};
import { itGte } from "$repo-utils";

// "minNodeVersion": "8.0.0" <-- For Ctrl+F when dropping node 6
const nodeGte8 = itGte("8.0.0");

describe("asynchronicity", () => {
const base = path.join(
Expand Down
7 changes: 3 additions & 4 deletions packages/babel-core/test/config-loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import path from "path";
import { fileURLToPath } from "url";
import { createRequire } from "module";
import { itNoWin32 } from "$repo-utils";

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

Expand Down Expand Up @@ -65,9 +66,7 @@ describe("@babel/core config loading", () => {

describe("createConfigItemSync", () => {
// Windows uses different file paths
const noWin = process.platform === "win32" ? it.skip : it;

noWin("can be called synchronously with one param", () => {
itNoWin32("can be called synchronously with one param", () => {
function myPlugin() {
return {};
}
Expand All @@ -81,7 +80,7 @@ describe("@babel/core config loading", () => {
});
});

noWin("can be called synchronously with two params", () => {
itNoWin32("can be called synchronously with two params", () => {
function myPlugin() {
return {};
}
Expand Down
33 changes: 16 additions & 17 deletions packages/babel-core/test/errors-stacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { spawnSync } from "child_process";

const { __dirname } = commonJS(import.meta.url);

const nodeGte12 = itGte("12.0.0");

const replaceAll = "".replaceAll
? Function.call.bind("".replaceAll)
: (str, find, replace) => str.split(find).join(replace);
Expand Down Expand Up @@ -282,27 +284,24 @@ describe("@babel/core errors", function () {
`);
});

itGte("12.0.0")(
"should not throw in `node --frozen-intrinsics`",
function () {
expect(
spawnSync(
process.execPath,
[
"--frozen-intrinsics",
"--input-type=module",
"-e",
`
nodeGte12("should not throw in `node --frozen-intrinsics`", function () {
expect(
spawnSync(
process.execPath,
[
"--frozen-intrinsics",
"--input-type=module",
"-e",
`
import * as babel from "../lib/index.js";
babel.parseSync("foo;", {
root: String.raw\`${fixture("valid")}\`,
});
console.log("%done%");
`,
],
{ cwd: __dirname },
).output + "",
).toContain("%done%");
},
);
],
{ cwd: __dirname },
).output + "",
).toContain("%done%");
});
});
4 changes: 2 additions & 2 deletions packages/babel-core/test/option-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ function loadOptionsAsync(opts) {
}

const itBabel7 = process.env.BABEL_8_BREAKING ? it.skip : it;
const itBabel7cjs = process.env.BABEL_8_BREAKING || USE_ESM ? it.skip : it;
const itBabel7NoESM = process.env.BABEL_8_BREAKING || USE_ESM ? it.skip : it;

describe("option-manager", () => {
itBabel7cjs("throws for babel 5 plugin", () => {
itBabel7NoESM("throws for babel 5 plugin", () => {
return expect(() => {
loadOptions({
plugins: [({ Plugin }) => new Plugin("object-assign", {})],
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-core/test/resolution.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as babel from "../lib/index.js";
import path from "path";
import { fileURLToPath } from "url";
import { itGte } from "$repo-utils";

describe("addon resolution", function () {
const base = path.join(
Expand Down Expand Up @@ -464,7 +465,7 @@ describe("addon resolution", function () {
}).toThrow(/Cannot (?:find|resolve) module 'babel-plugin-foo'/);
});

const nodeGte12 = parseInt(process.versions.node, 10) >= 12 ? it : it.skip;
const nodeGte12 = itGte("12.0.0");

nodeGte12(
"should suggest -transform- as an alternative to -proposal-",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ 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;

describe("getTargets", () => {
it("parses", () => {
expect(
Expand Down Expand Up @@ -284,7 +287,7 @@ describe("getTargets", () => {
).toMatchSnapshot();
});

(process.env.BABEL_8_BREAKING ? it.skip : it)(
itBabel7(
"'intersect' behaves like 'true' if no browsers are specified - Babel 7",
() => {
expect(getTargets({ esmodules: "intersect" })).toEqual(
Expand All @@ -293,7 +296,7 @@ describe("getTargets", () => {
},
);

(process.env.BABEL_8_BREAKING ? it.skip : it)(
itBabel7(
"'browsers' option will have no effect if it is an empty array - Babel 7",
() => {
expect(getTargets({ esmodules: "intersect", browsers: [] })).toEqual(
Expand All @@ -318,7 +321,7 @@ describe("getTargets", () => {
).toThrow();
});

(process.env.BABEL_8_BREAKING ? it : it.skip)(
itBabel8(
"'intersect' behaves like no-op if no browsers are specified",
() => {
expect(getTargets({ esmodules: "intersect" })).toEqual(getTargets({}));
Expand Down
4 changes: 3 additions & 1 deletion packages/babel-parser/test/plugin-options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { parse } from "../lib/index.js";

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

function getParser(code, plugins) {
return () => parse(code, { plugins, sourceType: "module" });
}
Expand Down Expand Up @@ -66,7 +68,7 @@ describe("plugin options", function () {
});
});
describe("'moduleAttributes' plugin", () => {
(process.env.BABEL_8_BREAKING ? it : it.skip)("removed in Babel 8", () => {
itBabel8("removed in Babel 8", () => {
expect(
getParser("", ["moduleAttributes"]),
).toThrowErrorMatchingInlineSnapshot(
Expand Down