Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jan 1, 2020
1 parent a62dd2c commit d16941e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 26 deletions.
62 changes: 36 additions & 26 deletions packages/babel-core/test/config-chain.js
Expand Up @@ -1040,30 +1040,33 @@ describe("buildConfigChain", function() {
});

describe("relative", () => {
test.each(["package.json", ".babelrc", ".babelrc.js", ".babelrc.cjs"])(
"should load %s",
async name => {
const { cwd, tmp, config } = await getTemp(
`babel-test-load-config-${name}`,
);
const filename = tmp("src.js");
test.each([
"package.json",
".babelrc",
".babelrc.json",
".babelrc.js",
".babelrc.cjs",
])("should load %s", async name => {
const { cwd, tmp, config } = await getTemp(
`babel-test-load-config-${name}`,
);
const filename = tmp("src.js");

await config(name);
await config(name);

expect(
loadOptions({
filename,
cwd,
}),
).toEqual({
...getDefaults(),
expect(
loadOptions({
filename,
cwd,
root: cwd,
comments: true,
});
},
);
}),
).toEqual({
...getDefaults(),
filename,
cwd,
root: cwd,
comments: true,
});
});

it("should load .babelignore", () => {
const filename = fixture("config-files", "babelignore", "src.js");
Expand All @@ -1074,7 +1077,13 @@ describe("buildConfigChain", function() {
});

test.each(
pairs(["package.json", ".babelrc", ".babelrc.js", ".babelrc.cjs"]),
pairs([
"package.json",
".babelrc",
".babelrc.json",
".babelrc.js",
".babelrc.cjs",
]),
)("should throw if both %s and %s are used", async (name1, name2) => {
const { cwd, tmp, config } = await getTemp(
`babel-test-dup-config-${name1}-${name2}`,
Expand All @@ -1100,11 +1109,12 @@ describe("buildConfigChain", function() {
});

test.each`
config | dir | error
${".babelrc"} | ${"babelrc-error"} | ${/Error while parsing config - /}
${".babelrc.js"} | ${"babelrc-js-error"} | ${/Babelrc threw an error/}
${".babelrc.cjs"} | ${"babelrc-cjs-error"} | ${/Babelrc threw an error/}
${"package.json"} | ${"pkg-error"} | ${/Error while parsing JSON - /}
config | dir | error
${".babelrc"} | ${"babelrc-error"} | ${/Error while parsing config - /}
${".babelrc.json"} | ${"babelrc-error"} | ${/Error while parsing config - /}
${".babelrc.js"} | ${"babelrc-js-error"} | ${/Babelrc threw an error/}
${".babelrc.cjs"} | ${"babelrc-cjs-error"} | ${/Babelrc threw an error/}
${"package.json"} | ${"pkg-error"} | ${/Error while parsing JSON - /}
`("should show helpful errors for $config", ({ dir, error }) => {
const filename = fixture("config-files", dir, "src.js");

Expand Down
@@ -0,0 +1,3 @@
{
"comments": true
}
@@ -0,0 +1 @@
{45

0 comments on commit d16941e

Please sign in to comment.