Skip to content

Commit

Permalink
fix: add default value for browserslist config path (#13159)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Apr 15, 2021
1 parent cbfcee5 commit 5d55055
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/babel-helper-compilation-targets/src/index.js
Expand Up @@ -179,6 +179,7 @@ export default function getTargets(
options: GetTargetsOption = {},
): Targets {
let { browsers, esmodules } = inputTargets;
const { configPath = "." } = options;

validateBrowsers(browsers);

Expand All @@ -193,7 +194,7 @@ export default function getTargets(
if (!browsers && shouldSearchForConfig) {
browsers = browserslist.loadConfig({
config: options.configFile,
path: options.configPath,
path: configPath,
env: options.browserslistEnv,
});
if (browsers == null) {
Expand Down
@@ -0,0 +1,19 @@
import getTargets from "../..";
import { fileURLToPath } from "url";
import path from "path";

const oldCwd = process.cwd();

beforeAll(() => {
process.chdir(path.dirname(fileURLToPath(import.meta.url)));
});

afterAll(() => {
process.chdir(oldCwd);
});

it("loads packageJson.browserslist", () => {
const actual = getTargets({}, {});

expect(actual).toEqual({ chrome: "4.0.0" });
});
@@ -0,0 +1,3 @@
{
"browserslist": "chrome 4"
}
@@ -0,0 +1,4 @@
chrome 4

[development]
chrome 88
@@ -0,0 +1,30 @@
import getTargets from "../..";
import { fileURLToPath } from "url";
import path from "path";

const oldCwd = process.cwd();

beforeAll(() => {
process.chdir(path.dirname(fileURLToPath(import.meta.url)));
});

afterAll(() => {
process.chdir(oldCwd);
});

it("loads browserslistrc", () => {
const actual = getTargets({}, {});

expect(actual).toEqual({ chrome: "4.0.0" });
});

it("loads browserslistrc and respects browserslistEnv", () => {
const actual = getTargets(
{},
{
browserslistEnv: "development",
},
);

expect(actual).toEqual({ chrome: "88.0.0" });
});

0 comments on commit 5d55055

Please sign in to comment.