From 5b0a16cea3a4ff43f802937c0122d87bd00dfe5c Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 4 Jan 2017 18:28:34 +0100 Subject: [PATCH] added test case for loader chaining (#3746) --- test/configCases/rule-set/chaining/abc.js | 1 + test/configCases/rule-set/chaining/def.js | 1 + test/configCases/rule-set/chaining/index.js | 16 ++++++++++++++++ test/configCases/rule-set/chaining/loader.js | 8 ++++++++ .../rule-set/chaining/webpack.config.js | 14 ++++++++++++++ 5 files changed, 40 insertions(+) create mode 100644 test/configCases/rule-set/chaining/abc.js create mode 100644 test/configCases/rule-set/chaining/def.js create mode 100644 test/configCases/rule-set/chaining/index.js create mode 100644 test/configCases/rule-set/chaining/loader.js create mode 100644 test/configCases/rule-set/chaining/webpack.config.js diff --git a/test/configCases/rule-set/chaining/abc.js b/test/configCases/rule-set/chaining/abc.js new file mode 100644 index 000000000..b5b745c32 --- /dev/null +++ b/test/configCases/rule-set/chaining/abc.js @@ -0,0 +1 @@ +module.exports = ["abc"]; diff --git a/test/configCases/rule-set/chaining/def.js b/test/configCases/rule-set/chaining/def.js new file mode 100644 index 000000000..b80c4dbfe --- /dev/null +++ b/test/configCases/rule-set/chaining/def.js @@ -0,0 +1 @@ +module.exports = ["def"]; diff --git a/test/configCases/rule-set/chaining/index.js b/test/configCases/rule-set/chaining/index.js new file mode 100644 index 000000000..ca3b76c2c --- /dev/null +++ b/test/configCases/rule-set/chaining/index.js @@ -0,0 +1,16 @@ +it("should match rule with multiple loaders in 'loader'", function() { + var abc = require("./abc"); + abc.should.be.eql([ + "abc", + "?b", + "?a" + ]); +}); +it("should match rule with multiple loaders in 'loaders'", function() { + var def = require("./def"); + def.should.be.eql([ + "def", + "?d", + "?c" + ]); +}); diff --git a/test/configCases/rule-set/chaining/loader.js b/test/configCases/rule-set/chaining/loader.js new file mode 100644 index 000000000..f78d43c0b --- /dev/null +++ b/test/configCases/rule-set/chaining/loader.js @@ -0,0 +1,8 @@ +module.exports = function(source) { + var query = this.query; + if(typeof query === "object" && typeof query.get === "function") { + query = query.get(); + } + return source + "\nmodule.exports.push(" + JSON.stringify(query) + ");"; +}; + diff --git a/test/configCases/rule-set/chaining/webpack.config.js b/test/configCases/rule-set/chaining/webpack.config.js new file mode 100644 index 000000000..c50dd55ea --- /dev/null +++ b/test/configCases/rule-set/chaining/webpack.config.js @@ -0,0 +1,14 @@ +module.exports = { + module: { + rules: [ + { + resource: /abc\.js$/, + loader: "./loader?a!./loader?b" + }, + { + resource: /def\.js$/, + loaders: "./loader?c!./loader?d" + } + ] + } +}