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

Avoid resolveTargets call if browsers is an empty array #14294

Merged
merged 15 commits into from Mar 14, 2022
Merged
Changes from 2 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
Expand Up @@ -293,18 +293,14 @@ describe("getTargets", () => {
},
);

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

(process.env.BABEL_8_BREAKING ? it.skip : it)(
"The final 'browsers' handled variable will have no effect if it is an empty array - Babel 7",
() => {
it("The final 'browsers' handled variable will have no effect if it is an empty array", () => {
expect(getTargets({ esmodules: "intersect", browsers: [] })).toEqual(
getTargets(
{ esmodules: "intersect" },
Expand All @@ -314,6 +310,19 @@ describe("getTargets", () => {
},
);

it("'resolveTargets' will be called rightly if 'browsers' is an array with some value", () => {
let x = 0;

// 'test' is an unknown browser query, so methods of 'browserslist' library will throw an error
try {
getTargets({ esmodules: "intersect", browsers: ["test"] });
} catch {
x++;
}

expect(x).toBe(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jest has native support for this:

expect(() => getTargets({ esmodules: "intersect", browsers: ["test"] })).toThrow();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, I've fixed it.

});

(process.env.BABEL_8_BREAKING ? it : it.skip)(
"'intersect' behaves like no-op if no browsers are specified",
() => {
Expand Down