Skip to content

Commit 0c8dfc1

Browse files
authored
enable jest/no-standalone-expect (#15872)
1 parent 8f1c34a commit 0c8dfc1

21 files changed

Lines changed: 135 additions & 117 deletions

File tree

eslint.config.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,26 @@ module.exports = [
188188
config.rules = {
189189
...config.rules,
190190
"jest/expect-expect": "off",
191-
"jest/no-standalone-expect": "off",
191+
"jest/no-standalone-expect": [
192+
"error",
193+
{
194+
additionalTestBlockFunctions: [
195+
"itBabel7",
196+
"itBabel7NoESM",
197+
"itBabel7NodeGte14NoESM",
198+
"itBabel8",
199+
"itESLint7",
200+
"itESLint8",
201+
"itNoESM",
202+
"itNoWin32",
203+
"itESM",
204+
"nodeGte8",
205+
"nodeGte12",
206+
"nodeGte12NoESM",
207+
"testFn",
208+
],
209+
},
210+
],
192211
"jest/no-test-callback": "off",
193212
"jest/valid-describe": "off",
194213
"import/extensions": ["error", "always"],

eslint/babel-eslint-parser/test/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const dirname = path.dirname(fileURLToPath(import.meta.url));
2323

2424
// @babel/eslint-parser 8 will drop ESLint 7 support
2525
const itESLint7 = isESLint7 && !process.env.BABEL_8_BREAKING ? it : it.skip;
26-
const itNotESLint7 = isESLint7 ? it.skip : it;
26+
const itESLint8 = isESLint7 ? it.skip : it;
2727

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

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

495-
itNotESLint7("class fields with ESLint 8", () => {
495+
itESLint8("class fields with ESLint 8", () => {
496496
parseAndAssertSame(
497497
`
498498
class A {
@@ -536,7 +536,7 @@ describe("Babel and Espree", () => {
536536
).toMatchObject(staticKw);
537537
});
538538

539-
itNotESLint7("static (token) - ESLint 8", () => {
539+
itESLint8("static (token) - ESLint 8", () => {
540540
const code = `
541541
class A {
542542
static m() {}
@@ -593,7 +593,7 @@ describe("Babel and Espree", () => {
593593
expect(babylonAST.tokens[17]).toMatchObject(topicToken);
594594
});
595595

596-
itNotESLint7("pipeline # topic token - ESLint 8", () => {
596+
itESLint8("pipeline # topic token - ESLint 8", () => {
597597
const code = `
598598
x |> #
599599
y |> #[0]

eslint/babel-eslint-tests/test/integration/config-files.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { USE_ESM } from "$repo-utils";
55

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

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

23-
itNode12upNoESM(
23+
nodeGte12NoESM(
2424
"experimental worker works with babel.config.mjs",
2525
async () => {
2626
const engine = new ESLint({ ignore: false });

eslint/babel-eslint-tests/test/integration/parser-override.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from "path";
22
import { fileURLToPath } from "url";
33
import { createRequire } from "module";
44
import * as babelESLint from "@babel/eslint-parser";
5+
import { itGte } from "$repo-utils";
56

67
describe("parserOverride", () => {
78
const expectedAST = {
@@ -31,8 +32,8 @@ describe("parserOverride", () => {
3132
expect(ast).toMatchObject(expectedAST);
3233
});
3334

34-
const babel7node12 = parseInt(process.versions.node) < 12 ? it.skip : it;
35-
babel7node12("works when parsing in a worker", async () => {
35+
const nodeGte12 = itGte("12.0.0");
36+
nodeGte12("works when parsing in a worker", async () => {
3637
const require = createRequire(import.meta.url);
3738
// eslint-disable-next-line import/extensions
3839
const babelESLintWorker = require("@babel/eslint-parser/experimental-worker");

packages/babel-core/test/api.js

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import pluginSyntaxFlow from "@babel/plugin-syntax-flow";
1212
import pluginSyntaxJSX from "@babel/plugin-syntax-jsx";
1313
import pluginFlowStripTypes from "@babel/plugin-transform-flow-strip-types";
1414

15+
const itBabel8 = process.env.BABEL_8_BREAKING ? it : it.skip;
16+
1517
const cwd = path.dirname(fileURLToPath(import.meta.url));
1618

1719
function assertIgnored(result) {
@@ -173,26 +175,20 @@ describe("api", function () {
173175
expect(babel.tokTypes).toBeDefined();
174176
});
175177

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

185-
(process.env.BABEL_8_BREAKING ? it : it.skip)(
186-
"transform throws on undefined callback",
187-
() => {
188-
const options = {
189-
filename: "example.js",
190-
};
191-
expect(() => transform("", options)).toThrowErrorMatchingInlineSnapshot(
192-
`"Starting from Babel 8.0.0, the 'transform' function expects a callback. If you need to call it synchronously, please use 'transformSync'."`,
193-
);
194-
},
195-
);
184+
itBabel8("transform throws on undefined callback", () => {
185+
const options = {
186+
filename: "example.js",
187+
};
188+
expect(() => transform("", options)).toThrowErrorMatchingInlineSnapshot(
189+
`"Starting from Babel 8.0.0, the 'transform' function expects a callback. If you need to call it synchronously, please use 'transformSync'."`,
190+
);
191+
});
196192

197193
it("transformFile", function () {
198194
const options = {
@@ -249,18 +245,15 @@ describe("api", function () {
249245
expect(options).toEqual({ babelrc: false });
250246
});
251247

252-
(process.env.BABEL_8_BREAKING ? it : it.skip)(
253-
"transformFromAst throws on undefined callback",
254-
() => {
255-
const program = "const identifier = 1";
256-
const node = parseSync(program);
257-
expect(() =>
258-
transformFromAst(node, program),
259-
).toThrowErrorMatchingInlineSnapshot(
260-
`"Starting from Babel 8.0.0, the 'transformFromAst' function expects a callback. If you need to call it synchronously, please use 'transformFromAstSync'."`,
261-
);
262-
},
263-
);
248+
itBabel8("transformFromAst throws on undefined callback", () => {
249+
const program = "const identifier = 1";
250+
const node = parseSync(program);
251+
expect(() =>
252+
transformFromAst(node, program),
253+
).toThrowErrorMatchingInlineSnapshot(
254+
`"Starting from Babel 8.0.0, the 'transformFromAst' function expects a callback. If you need to call it synchronously, please use 'transformFromAstSync'."`,
255+
);
256+
});
264257

265258
it("transformFromAst should generate same code with different cloneInputAst", function () {
266259
const program = `//test1

packages/babel-core/test/async.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ import {
99
itESM,
1010
} from "./helpers/esm.js";
1111

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

1817
describe("asynchronicity", () => {
1918
const base = path.join(

packages/babel-core/test/config-loading.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import path from "path";
1111
import { fileURLToPath } from "url";
1212
import { createRequire } from "module";
13+
import { itNoWin32 } from "$repo-utils";
1314

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

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

6667
describe("createConfigItemSync", () => {
6768
// Windows uses different file paths
68-
const noWin = process.platform === "win32" ? it.skip : it;
69-
70-
noWin("can be called synchronously with one param", () => {
69+
itNoWin32("can be called synchronously with one param", () => {
7170
function myPlugin() {
7271
return {};
7372
}
@@ -81,7 +80,7 @@ describe("@babel/core config loading", () => {
8180
});
8281
});
8382

84-
noWin("can be called synchronously with two params", () => {
83+
itNoWin32("can be called synchronously with two params", () => {
8584
function myPlugin() {
8685
return {};
8786
}

packages/babel-core/test/errors-stacks.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { spawnSync } from "child_process";
66

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

9+
const nodeGte12 = itGte("12.0.0");
10+
911
const replaceAll = "".replaceAll
1012
? Function.call.bind("".replaceAll)
1113
: (str, find, replace) => str.split(find).join(replace);
@@ -282,27 +284,24 @@ describe("@babel/core errors", function () {
282284
`);
283285
});
284286

285-
itGte("12.0.0")(
286-
"should not throw in `node --frozen-intrinsics`",
287-
function () {
288-
expect(
289-
spawnSync(
290-
process.execPath,
291-
[
292-
"--frozen-intrinsics",
293-
"--input-type=module",
294-
"-e",
295-
`
287+
nodeGte12("should not throw in `node --frozen-intrinsics`", function () {
288+
expect(
289+
spawnSync(
290+
process.execPath,
291+
[
292+
"--frozen-intrinsics",
293+
"--input-type=module",
294+
"-e",
295+
`
296296
import * as babel from "../lib/index.js";
297297
babel.parseSync("foo;", {
298298
root: String.raw\`${fixture("valid")}\`,
299299
});
300300
console.log("%done%");
301301
`,
302-
],
303-
{ cwd: __dirname },
304-
).output + "",
305-
).toContain("%done%");
306-
},
307-
);
302+
],
303+
{ cwd: __dirname },
304+
).output + "",
305+
).toContain("%done%");
306+
});
308307
});

packages/babel-core/test/option-manager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ function loadOptionsAsync(opts) {
1414
}
1515

1616
const itBabel7 = process.env.BABEL_8_BREAKING ? it.skip : it;
17-
const itBabel7cjs = process.env.BABEL_8_BREAKING || USE_ESM ? it.skip : it;
17+
const itBabel7NoESM = process.env.BABEL_8_BREAKING || USE_ESM ? it.skip : it;
1818

1919
describe("option-manager", () => {
20-
itBabel7cjs("throws for babel 5 plugin", () => {
20+
itBabel7NoESM("throws for babel 5 plugin", () => {
2121
return expect(() => {
2222
loadOptions({
2323
plugins: [({ Plugin }) => new Plugin("object-assign", {})],

packages/babel-core/test/resolution.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as babel from "../lib/index.js";
22
import path from "path";
33
import { fileURLToPath } from "url";
4+
import { itGte } from "$repo-utils";
45

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

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

469470
nodeGte12(
470471
"should suggest -transform- as an alternative to -proposal-",

0 commit comments

Comments
 (0)