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

Fix eslint-plugin-jest config #15826

Merged
merged 3 commits into from
Aug 2, 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
35 changes: 19 additions & 16 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,25 @@ module.exports = [
},
},
...compat.extends("plugin:jest/recommended").map(config => {
config.files = [
...testFiles,
"packages/babel-helper-transform-fixture-test-runner/src/helpers.{ts,js}",
"test/**/*.js",
];
config.rules = {
...config.rules,
"jest/expect-expect": "off",
"jest/no-identical-title": "off",
"jest/no-standalone-expect": "off",
"jest/no-test-callback": "off",
"jest/valid-describe": "off",
"import/extensions": ["error", "always"],
"import/no-extraneous-dependencies": "off",
"no-restricted-imports": ["error", { patterns: ["**/src/**"] }],
};
if (config.files == null) {
config.files = [
...testFiles,
"packages/babel-helper-transform-fixture-test-runner/src/helpers.{ts,js}",
"test/**/*.js",
];
}
if (config.rules != null) {
config.rules = {
...config.rules,
"jest/expect-expect": "off",
"jest/no-standalone-expect": "off",
"jest/no-test-callback": "off",
"jest/valid-describe": "off",
"import/extensions": ["error", "always"],
"import/no-extraneous-dependencies": "off",
"no-restricted-imports": ["error", { patterns: ["**/src/**"] }],
};
}
return config;
}),
{
Expand Down
4 changes: 2 additions & 2 deletions eslint/babel-eslint-parser/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ describe("Babel and Espree", () => {
parseAndAssertSame("/affix-top|affix-bottom|affix|[a-z]/");
});

it("regexp", () => {
it("regexp without flag", () => {
parseAndAssertSame("const foo = /foo/;");
});

Expand Down Expand Up @@ -893,7 +893,7 @@ describe("Babel and Espree", () => {
}).not.toThrow();
});
} else {
it("super outside method", () => {
it("super outside method in Babel 7", () => {
expect(() => {
parseForESLint("function F() { super(); }", {
babelOptions: BABEL_OPTIONS,
Expand Down
4 changes: 2 additions & 2 deletions eslint/babel-eslint-tests/test/integration/eslint/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -1282,14 +1282,14 @@ describe("verify", () => {
);
});

it("does not mark spread variables false-positive", () => {
it("does not mark spread variables false-positive: multiple destructuring bindings", () => {
verifyAndAssertMessages(
"var originalObject = {}; var {field1, field2, ...clone} = originalObject;",
{ "no-undef": 1, "no-redeclare": 1 },
);
});

it("does not mark spread variables false-positive", () => {
it("does not mark spread variables false-positive: single destructuring binding", () => {
verifyAndAssertMessages(
"const props = { yo: 'yo' }; const { ...otherProps } = props;",
{ "no-undef": 1, "no-redeclare": 1 },
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-code-frame/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("@babel/code-frame", function () {
chalk.enabled = originalChalkEnabled;
babelHighlightChalk.supportsColor = originalHighlightChalkSupportsColor;
babelHighlightChalk.level = originalHighlightChalkLevel;
babelHighlightChalk.enabled = originalChalkEnabled;
babelHighlightChalk.enabled = originalHighlightChalkEnabled;
});
}

Expand Down
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 @@ -205,15 +205,15 @@ describe("option-manager", () => {
});

describe("mergeOptions", () => {
it("throws for removed babel 5 options", () => {
it("throws for removed babel 5 options: randomOption", () => {
return expect(() => {
loadOptions({
randomOption: true,
});
}).toThrow(/Unknown option: .randomOption/);
});

it("throws for removed babel 5 options", () => {
it("throws for removed babel 5 options: auxiliaryComment", () => {
return expect(() => {
loadOptions({
auxiliaryComment: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/test/resolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe("addon resolution", function () {
});
});

it("should find @babel scoped plugins", function () {
it("should find @babel scoped plugins with an existing prefix", function () {
process.chdir("babel-org-paths");

babel.transformSync("", {
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-highlight/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ describe("@babel/highlight", function () {
});

describeBabel7NoESM("getChalk", function () {
let getChalk;
beforeAll(() => {
let getChalk;
beforeAll(() => {
({ getChalk } = require("../lib/index.js"));
});

Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-syntax-decorators/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const babel8 = process.env.BABEL_8_BREAKING ? test : test.skip;
const babel7describe = process.env.BABEL_8_BREAKING ? describe.skip : describe;

babel7describe("'legacy' option", function () {
test("must be boolean", function () {
test("legacy must be boolean", function () {
expect(makeParser("", { legacy: "legacy" })).toThrow();
});

Expand All @@ -32,7 +32,7 @@ babel7describe("'legacy' option", function () {
});

babel7describe("'decoratorsBeforeExport' option", function () {
test("must be boolean", function () {
test("decoratorsBeforeExport must be boolean", function () {
expect(
makeParser("", { version: "2021-12", decoratorsBeforeExport: "before" }),
).toThrow();
Expand Down
77 changes: 37 additions & 40 deletions packages/babel-preset-env/test/index.skip-bundled.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,17 @@ describe("babel-preset-env", () => {
shouldTransformDynamicImport: false,
shouldTransformExportNamespaceFrom: false,
});
if (process.env.BABEL_8_BREAKING) {
expect(names).toEqual(["transform-modules-commonjs"]);
} else {
expect(names).toEqual([
"transform-modules-commonjs",
"syntax-dynamic-import",
"syntax-export-namespace-from",
"syntax-top-level-await",
"syntax-import-meta",
]);
}
expect(names).toEqual(
process.env.BABEL_8_BREAKING
? ["transform-modules-commonjs"]
: [
"transform-modules-commonjs",
"syntax-dynamic-import",
"syntax-export-namespace-from",
"syntax-top-level-await",
"syntax-import-meta",
],
);
});
});
describe("dynamic imports should be transformed", () => {
Expand All @@ -132,20 +132,17 @@ describe("babel-preset-env", () => {
shouldTransformDynamicImport: true,
shouldTransformExportNamespaceFrom: false,
});
if (process.env.BABEL_8_BREAKING) {
expect(names).toEqual([
"transform-modules-systemjs",
"transform-dynamic-import",
]);
} else {
expect(names).toEqual([
"transform-modules-systemjs",
"transform-dynamic-import",
"syntax-export-namespace-from",
"syntax-top-level-await",
"syntax-import-meta",
]);
}
expect(names).toEqual(
process.env.BABEL_8_BREAKING
? ["transform-modules-systemjs", "transform-dynamic-import"]
: [
"transform-modules-systemjs",
"transform-dynamic-import",
"syntax-export-namespace-from",
"syntax-top-level-await",
"syntax-import-meta",
],
);
});
describe("export namespace from should be transformed", () => {
it("works", () => {
Expand All @@ -156,21 +153,21 @@ describe("babel-preset-env", () => {
shouldTransformDynamicImport: true,
shouldTransformExportNamespaceFrom: true,
});
if (process.env.BABEL_8_BREAKING) {
expect(names).toEqual([
"transform-modules-systemjs",
"transform-dynamic-import",
"transform-export-namespace-from",
]);
} else {
expect(names).toEqual([
"transform-modules-systemjs",
"transform-dynamic-import",
"transform-export-namespace-from",
"syntax-top-level-await",
"syntax-import-meta",
]);
}
expect(names).toEqual(
process.env.BABEL_8_BREAKING
? [
"transform-modules-systemjs",
"transform-dynamic-import",
"transform-export-namespace-from",
]
: [
"transform-modules-systemjs",
"transform-dynamic-import",
"transform-export-namespace-from",
"syntax-top-level-await",
"syntax-import-meta",
],
);
});
});
});
Expand Down
14 changes: 10 additions & 4 deletions packages/babel-preset-env/test/normalize-options.skip-bundled.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,21 @@ describe("normalize-options", () => {

describe("RegExp include/exclude", () => {
it("should not allow invalid plugins in `include` and `exclude`", () => {
const normalizeWithNonExistingPlugin = () => {
const normalizeIncludeWithNonExistingPlugin = () => {
normalizeOptions({
include: ["non-existing-plugin"],
});
};
expect(normalizeWithNonExistingPlugin).toThrow(Error);
const normalizeExcludeWithNonExistingPlugin = () => {
normalizeOptions({
exclude: ["non-existing-plugin"],
});
};
expect(normalizeIncludeWithNonExistingPlugin).toThrow(Error);
expect(normalizeExcludeWithNonExistingPlugin).toThrow(Error);
});

it("should expand regular expressions in `include` and `exclude`", () => {
it("should expand regular expressions in `include`", () => {
const normalized = normalizeOptions({
include: ["^[a-z]*-spread", "babel-plugin-transform-classes"],
});
Expand All @@ -131,7 +137,7 @@ describe("normalize-options", () => {
]);
});

it("should expand regular expressions in `include` and `exclude`", () => {
it("should expand regular expressions in `exclude`", () => {
const normalized = normalizeOptions({
useBuiltIns: "entry",
corejs: 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("normalize options", () => {
expect(() => normalizeOptions({ [optionName]: 0 })).not.toThrow();
},
);
it("default values", () => {
it("default values in Babel 7", () => {
expect(normalizeOptions({})).toMatchInlineSnapshot(`
Object {
"all": undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe("normalize options", () => {
expect(() => normalizeOptions({ [optionName]: 0 })).not.toThrow();
},
);
it("default values", () => {
it("default values in Babel 7", () => {
expect(normalizeOptions({})).toMatchInlineSnapshot(`
Object {
"development": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe("normalize options", () => {
);
},
);
it("default values", () => {
it("default values in Babel 7", () => {
expect(normalizeOptions({})).toMatchInlineSnapshot(`
Object {
"allExtensions": false,
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-traverse/test/conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ describe("conversion", function () {
expect(generateCode(rootPath)).toBe("() => {\n return true;\n};");
});

it("preserves arrow function body's context", function () {
it("preserves arrow function body's context when replaced with a boolean literal", function () {
const rootPath = getPath("() => true").get("expression");
const body = rootPath.get("body");
rootPath.ensureBlock();
body.replaceWith(t.booleanLiteral(false));
expect(generateCode(rootPath)).toBe("() => {\n return false;\n};");
});

it("preserves arrow function body's context", function () {
it("preserves arrow function body's context when replace with multiple nodes", function () {
const rootPath = getPath("() => true").get("expression");
const body = rootPath.get("body");
rootPath.ensureBlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe("builders", function () {
(process.env.BABEL_8_BREAKING ? describe.skip : describe)(
"tsTypeParameter - Babel 7",
function () {
it("accept name as argument for tsTypeParameter", 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")),
Expand Down Expand Up @@ -81,7 +81,7 @@ describe("builders", function () {
}
`);
});
it("throws when name is missing", function () {
it("throws when name is missing in Babel 7", function () {
expect(() => {
t.tsTypeParameter(
t.tsTypeReference(t.identifier("bar")),
Expand Down