Add tests to test the plugin ordering. (#5571)

This commit is contained in:
Logan Smyth
2017-03-31 18:52:58 -07:00
committed by GitHub
parent d3497348b8
commit 878a7c5fdb
25 changed files with 191 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ import * as babel from "../lib/index";
import buildExternalHelpers from "../lib/tools/build-external-helpers";
import sourceMap from "source-map";
import assert from "assert";
import path from "path";
import Plugin from "../lib/config/plugin";
import generator from "babel-generator";
@@ -271,6 +272,77 @@ describe("api", function () {
});
it("complex plugin and preset ordering", function() {
function pushPlugin(str) {
return {
visitor: {
Program(path) {
path.pushContainer("body", babel.types.expressionStatement(babel.types.identifier(str)));
},
},
};
}
function pushPreset(str) {
return { plugins: [pushPlugin(str)] };
}
const result = babel.transform("", {
filename: path.join(__dirname, "fixtures", "config", "complex-plugin-config", "file.js"),
presets: [
pushPreset("argone"),
pushPreset("argtwo"),
],
env: {
development: {
passPerPreset: true,
presets: [
pushPreset("argthree"),
pushPreset("argfour"),
],
env: {
development: {
passPerPreset: true,
presets: [
pushPreset("argfive"),
pushPreset("argsix"),
],
},
},
},
},
});
assert.equal(result.code, [
"argtwo;",
"argone;",
"eleven;",
"twelve;",
"one;",
"two;",
"five;",
"six;",
"three;",
"four;",
"seventeen;",
"eighteen;",
"nineteen;",
"twenty;",
"thirteen;",
"fourteen;",
"fifteen;",
"sixteen;",
"argfive;",
"argsix;",
"argthree;",
"argfour;",
"seven;",
"eight;",
"nine;",
"ten;",
].join("\n"));
});
it("source map merging", function () {
const result = babel.transform([
/* eslint-disable max-len */

View File

@@ -0,0 +1,21 @@
one.js
two.js
three.js
four.js
five.js
six.js
seven.js
eight.js
nine.js
ten.js
eleven.js
twelve.js
thirteen.js
fourteen.js
fifteen.js
sixteen.js
seventeen.js
eighteen.js
nineteen.js
twenty.js
plugin.js

View File

@@ -0,0 +1,39 @@
{
extends: "./extended.babelrc",
plugins: [
"./one",
"./two",
],
presets: [{
plugins: [
"./three",
"./four",
],
}, {
plugins: [
"./five",
"./six",
],
}, {
passPerPreset: true,
presets: [{
plugins: [
"./seven",
"./eight",
],
}, {
plugins: [
"./nine",
"./ten",
],
}],
}],
env: {
development: {
plugins: [
"./eleven",
"./twelve",
]
},
},
}

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("eight");

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("eighteen");

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("eleven");

View File

@@ -0,0 +1,26 @@
{
plugins: [
"./thirteen",
"./fourteen",
],
presets: [{
plugins: [
"./fifteen",
"./sixteen",
],
}],
env: {
development: {
plugins: [
"./seventeen",
"./eighteen",
],
presets: [{
plugins: [
"./nineteen",
"./twenty",
],
}],
},
},
}

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("fifteen");

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("five");

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("four");

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("fourteen");

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("nine");

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("nineteen");

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("one");

View File

@@ -0,0 +1,13 @@
module.exports = function(str) {
return function(babel) {
return {
visitor: {
Program: function(path) {
path.pushContainer("body", [
babel.types.expressionStatement(babel.types.identifier(str)),
]);
},
},
};
};
};

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("seven");

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("seventeen");

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("six");

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("sixteen");

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("ten");

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("thirteen");

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("three");

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("twelve");

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("twenty");

View File

@@ -0,0 +1 @@
module.exports = require("./plugin")("two");