Replace repeated plugins/preset in top-level config instead of running both.
This commit is contained in:
@@ -310,30 +310,30 @@ describe("api", function() {
|
||||
assert.equal(
|
||||
result.code,
|
||||
[
|
||||
"argtwo;",
|
||||
"argone;",
|
||||
"eleven;",
|
||||
"twelve;",
|
||||
"thirteen;",
|
||||
"fourteen;",
|
||||
"seventeen;",
|
||||
"eighteen;",
|
||||
"one;",
|
||||
"two;",
|
||||
"eleven;",
|
||||
"twelve;",
|
||||
"argtwo;",
|
||||
"argone;",
|
||||
"five;",
|
||||
"six;",
|
||||
"three;",
|
||||
"four;",
|
||||
"seventeen;",
|
||||
"eighteen;",
|
||||
"nineteen;",
|
||||
"twenty;",
|
||||
"thirteen;",
|
||||
"fourteen;",
|
||||
"fifteen;",
|
||||
"sixteen;",
|
||||
"argthree;",
|
||||
"argfour;",
|
||||
"seven;",
|
||||
"eight;",
|
||||
"nine;",
|
||||
"ten;",
|
||||
"argthree;",
|
||||
"argfour;",
|
||||
].join("\n"),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -42,10 +42,10 @@ describe("@babel/core config loading", () => {
|
||||
|
||||
const options1 = loadConfig(opts).options;
|
||||
expect(options1.plugins.map(p => p.key)).to.eql([
|
||||
"plugin6",
|
||||
"plugin5",
|
||||
"plugin1",
|
||||
"plugin2",
|
||||
"plugin6",
|
||||
"plugin5",
|
||||
"plugin4",
|
||||
"plugin3",
|
||||
]);
|
||||
@@ -86,7 +86,7 @@ describe("@babel/core config loading", () => {
|
||||
expect(options2.plugins.length).to.equal(options1.plugins.length);
|
||||
|
||||
for (let i = 0; i < options1.plugins.length; i++) {
|
||||
if (i === 2) {
|
||||
if (i === 0) {
|
||||
expect(options2.plugins[i]).not.to.equal(options1.plugins[i]);
|
||||
} else {
|
||||
expect(options2.plugins[i]).to.equal(options1.plugins[i]);
|
||||
@@ -99,7 +99,7 @@ describe("@babel/core config loading", () => {
|
||||
expect(options3.plugins.length).to.equal(options1.plugins.length);
|
||||
|
||||
for (let i = 0; i < options1.plugins.length; i++) {
|
||||
if (i === 2 || i === 5) {
|
||||
if (i === 0 || i === 5) {
|
||||
expect(options3.plugins[i]).not.to.equal(options1.plugins[i]);
|
||||
} else {
|
||||
expect(options3.plugins[i]).to.equal(options1.plugins[i]);
|
||||
@@ -150,7 +150,7 @@ describe("@babel/core config loading", () => {
|
||||
expect(options2.plugins.length).to.equal(options1.plugins.length);
|
||||
|
||||
for (let i = 0; i < options1.plugins.length; i++) {
|
||||
if (i === 2 || i === 3 || i === 4 || i === 5 || i === 6) {
|
||||
if (i === 0 || i === 1 || i === 4 || i === 5 || i === 6) {
|
||||
expect(options2.plugins[i]).not.to.equal(options1.plugins[i]);
|
||||
} else {
|
||||
expect(options2.plugins[i]).to.equal(options1.plugins[i]);
|
||||
@@ -185,7 +185,7 @@ describe("@babel/core config loading", () => {
|
||||
expect(options2.plugins.length).to.equal(options1.plugins.length);
|
||||
|
||||
for (let i = 0; i < options2.plugins.length; i++) {
|
||||
if (i === 0) {
|
||||
if (i === 2) {
|
||||
expect(options2.plugins[i]).not.to.equal(options1.plugins[i]);
|
||||
} else {
|
||||
expect(options2.plugins[i]).to.equal(options1.plugins[i]);
|
||||
@@ -205,7 +205,7 @@ describe("@babel/core config loading", () => {
|
||||
expect(options2.plugins.length).to.equal(options1.plugins.length);
|
||||
|
||||
for (let i = 0; i < options2.plugins.length; i++) {
|
||||
if (i === 1) {
|
||||
if (i === 3) {
|
||||
expect(options2.plugins[i]).not.to.equal(options1.plugins[i]);
|
||||
} else {
|
||||
expect(options2.plugins[i]).to.equal(options1.plugins[i]);
|
||||
@@ -224,7 +224,7 @@ describe("@babel/core config loading", () => {
|
||||
expect(options2.plugins.length).to.equal(options1.plugins.length);
|
||||
|
||||
for (let i = 0; i < options1.plugins.length; i++) {
|
||||
if (i === 0) {
|
||||
if (i === 2) {
|
||||
expect(options2.plugins[i]).not.to.equal(options1.plugins[i]);
|
||||
} else {
|
||||
expect(options2.plugins[i]).to.equal(options1.plugins[i]);
|
||||
@@ -243,7 +243,7 @@ describe("@babel/core config loading", () => {
|
||||
expect(options2.plugins.length).to.equal(options1.plugins.length);
|
||||
|
||||
for (let i = 0; i < options1.plugins.length; i++) {
|
||||
if (i === 1) {
|
||||
if (i === 3) {
|
||||
expect(options2.plugins[i]).not.to.equal(options1.plugins[i]);
|
||||
} else {
|
||||
expect(options2.plugins[i]).to.equal(options1.plugins[i]);
|
||||
|
||||
@@ -11,6 +11,113 @@ describe("option-manager", () => {
|
||||
}, /Babel 5 plugin is being run with an unsupported Babel/);
|
||||
});
|
||||
|
||||
describe("config plugin/preset flattening and overriding", () => {
|
||||
function makePlugin() {
|
||||
const calls = [];
|
||||
const plugin = (api, opts) => {
|
||||
calls.push(opts);
|
||||
return {};
|
||||
};
|
||||
return { plugin, calls };
|
||||
}
|
||||
|
||||
it("should throw if a plugin is repeated", () => {
|
||||
const { calls, plugin } = makePlugin();
|
||||
|
||||
assert.throws(() => {
|
||||
manageOptions({
|
||||
plugins: [plugin, plugin],
|
||||
});
|
||||
}, /Duplicate plugin\/preset detected/);
|
||||
assert.deepEqual(calls, []);
|
||||
});
|
||||
|
||||
it("should not throw if a repeated plugin has a different name", () => {
|
||||
const { calls: calls1, plugin: plugin1 } = makePlugin();
|
||||
const { calls: calls2, plugin: plugin2 } = makePlugin();
|
||||
|
||||
manageOptions({
|
||||
plugins: [[plugin1, { arg: 1 }], [plugin2, { arg: 2 }, "some-name"]],
|
||||
});
|
||||
assert.deepEqual(calls1, [{ arg: 1 }]);
|
||||
assert.deepEqual(calls2, [{ arg: 2 }]);
|
||||
});
|
||||
|
||||
it("should merge .env[] plugins with parent presets", () => {
|
||||
const { calls: calls1, plugin: plugin1 } = makePlugin();
|
||||
const { calls: calls2, plugin: plugin2 } = makePlugin();
|
||||
|
||||
manageOptions({
|
||||
envName: "test",
|
||||
plugins: [[plugin1, { arg: 1 }]],
|
||||
env: {
|
||||
test: {
|
||||
plugins: [[plugin1, { arg: 3 }], [plugin2, { arg: 2 }]],
|
||||
},
|
||||
},
|
||||
});
|
||||
assert.deepEqual(calls1, [{ arg: 3 }]);
|
||||
assert.deepEqual(calls2, [{ arg: 2 }]);
|
||||
});
|
||||
|
||||
it("should throw if a preset is repeated", () => {
|
||||
const { calls, plugin: preset } = makePlugin();
|
||||
|
||||
assert.throws(() => {
|
||||
manageOptions({
|
||||
presets: [preset, preset],
|
||||
});
|
||||
}, /Duplicate plugin\/preset detected/);
|
||||
assert.deepEqual(calls, []);
|
||||
});
|
||||
|
||||
it("should not throw if a repeated preset has a different name", () => {
|
||||
const { calls: calls1, plugin: preset1 } = makePlugin();
|
||||
const { calls: calls2, plugin: preset2 } = makePlugin();
|
||||
|
||||
manageOptions({
|
||||
presets: [[preset1, { arg: 1 }], [preset2, { arg: 2 }, "some-name"]],
|
||||
});
|
||||
assert.deepEqual(calls1, [{ arg: 1 }]);
|
||||
assert.deepEqual(calls2, [{ arg: 2 }]);
|
||||
});
|
||||
|
||||
it("should merge .env[] presets with parent presets", () => {
|
||||
const { calls: calls1, plugin: preset1 } = makePlugin();
|
||||
const { calls: calls2, plugin: preset2 } = makePlugin();
|
||||
|
||||
manageOptions({
|
||||
envName: "test",
|
||||
presets: [[preset1, { arg: 1 }]],
|
||||
env: {
|
||||
test: {
|
||||
presets: [[preset1, { arg: 3 }], [preset2, { arg: 2 }]],
|
||||
},
|
||||
},
|
||||
});
|
||||
assert.deepEqual(calls1, [{ arg: 3 }]);
|
||||
assert.deepEqual(calls2, [{ arg: 2 }]);
|
||||
});
|
||||
|
||||
it("should not merge .env[] presets with parent presets when passPerPreset", () => {
|
||||
const { calls: calls1, plugin: preset1 } = makePlugin();
|
||||
const { calls: calls2, plugin: preset2 } = makePlugin();
|
||||
|
||||
manageOptions({
|
||||
envName: "test",
|
||||
passPerPreset: true,
|
||||
presets: [[preset1, { arg: 1 }]],
|
||||
env: {
|
||||
test: {
|
||||
presets: [[preset1, { arg: 3 }], [preset2, { arg: 2 }]],
|
||||
},
|
||||
},
|
||||
});
|
||||
assert.deepEqual(calls1, [{ arg: 1 }, { arg: 3 }]);
|
||||
assert.deepEqual(calls2, [{ arg: 2 }]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("mergeOptions", () => {
|
||||
it("throws for removed babel 5 options", () => {
|
||||
return assert.throws(() => {
|
||||
|
||||
Reference in New Issue
Block a user