Skip to content

Commit 808b32a

Browse files
committed
added test cases for extract-text-plugin
1 parent 159ed35 commit 808b32a

11 files changed

Lines changed: 105 additions & 10 deletions

File tree

test/HotTestCases.test.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var path = require("path");
33
var fs = require("fs");
44
var vm = require("vm");
55
var Test = require("mocha/lib/test");
6+
var ExtractTextPlugin = require("extract-text-webpack-plugin");
67
var checkArrayExpectation = require("./checkArrayExpectation");
78

89
var webpack = require("../lib/webpack");
@@ -48,13 +49,20 @@ describe("HotTestCases", function() {
4849
loaders: [{
4950
test: /\.js$/,
5051
loader: path.join(__dirname, "hotCases", "fake-update-loader.js")
52+
}, {
53+
test: /\.css$/,
54+
loader: ExtractTextPlugin.extract({
55+
fallbackLoader: "style-loader",
56+
loader: "css-loader"
57+
})
5158
}]
5259
},
5360
target: "async-node",
5461
plugins: [
5562
new webpack.HotModuleReplacementPlugin(),
5663
new webpack.NamedModulesPlugin(),
57-
new webpack.LoaderOptionsPlugin(fakeUpdateLoaderOptions)
64+
new webpack.LoaderOptionsPlugin(fakeUpdateLoaderOptions),
65+
new ExtractTextPlugin("bundle.css")
5866
],
5967
recordsPath: recordsPath
6068
}
@@ -84,18 +92,18 @@ describe("HotTestCases", function() {
8492
});
8593
if(checkArrayExpectation(testDirectory, jsonStats, "error", "errors" + fakeUpdateLoaderOptions.options.updateIndex, "Error", done)) return;
8694
if(checkArrayExpectation(testDirectory, jsonStats, "warning", "warnings" + fakeUpdateLoaderOptions.options.updateIndex, "Warning", done)) return;
87-
if(callback) callback();
95+
if(callback) callback(jsonStats);
8896
})
8997
}
9098

9199
function _require(module) {
92100
if(module.substr(0, 2) === "./") {
93101
var p = path.join(outputDirectory, module);
94-
var fn = vm.runInThisContext("(function(require, module, exports, __dirname, __filename, it, NEXT) {" + fs.readFileSync(p, "utf-8") + "\n})", p);
102+
var fn = vm.runInThisContext("(function(require, module, exports, __dirname, __filename, it, NEXT, STATS) {" + fs.readFileSync(p, "utf-8") + "\n})", p);
95103
var module = {
96104
exports: {}
97105
};
98-
fn.call(module.exports, _require, module, module.exports, outputDirectory, p, _it, _next);
106+
fn.call(module.exports, _require, module, module.exports, outputDirectory, p, _it, _next, jsonStats);
99107
return module.exports;
100108
} else return require(module);
101109
}

test/Stats.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ var webpack = require("../lib/webpack");
99
var base = path.join(__dirname, "statsCases");
1010
var outputBase = path.join(__dirname, "js", "stats");
1111
var tests = fs.readdirSync(base).filter(function(testName) {
12-
return fs.existsSync(path.join(base, testName, "index.js"))
12+
return fs.existsSync(path.join(base, testName, "index.js")) ||
13+
fs.existsSync(path.join(base, testName, "webpack.config.js"))
1314
});
1415
var Stats = require("../lib/Stats");
1516

@@ -26,9 +27,9 @@ describe("Stats", function() {
2627
options = require(path.join(base, testName, "webpack.config.js"));
2728
}
2829
(Array.isArray(options) ? options : [options]).forEach(function(options) {
29-
options.context = path.join(base, testName);
30-
options.output = options.output || {};
31-
options.output.path = path.join(outputBase, testName);
30+
if(!options.context) options.context = path.join(base, testName);
31+
if(!options.output) options.output = options.output || {};
32+
if(!options.output.path) options.output.path = path.join(outputBase, testName);
3233
});
3334
var c = webpack(options);
3435
var compilers = c.compilers ? c.compilers : [c];
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body { background: red; }
2+
---
3+
body { background: green; }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import "./file.css";
2+
3+
it("should not change hash of file after css update", function(done) {
4+
var hash1 = STATS.chunks[0].hash;
5+
NEXT(require("../../update")(done, true, function(newSTATS) {
6+
var hash2 = newSTATS.chunks[0].hash;
7+
hash1.should.be.eql(hash2);
8+
done();
9+
}));
10+
});

test/hotCases/update.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
module.exports = function(done, options, callback) {
2-
return function() {
3-
module.hot.check(options || true).then(callback || function() {}).catch(function(err) {
2+
return function(stats) {
3+
module.hot.check(options || true).then(function() {
4+
if(callback)
5+
callback(stats);
6+
}).catch(function(err) {
47
done(err);
58
});
69
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
body { background: red; }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require("./file.css");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
body { background: green; }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require("./file.css");
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Hash: 9ff2cfa8882f273c8c6d9ff2cfa8882f273c8c6d
2+
Child
3+
Hash: 9ff2cfa8882f273c8c6d
4+
Time: Xms
5+
Asset Size Chunks Chunk Names
6+
f49aa1e6c5ada5da859b.js 2.57 kB 0 [emitted] main
7+
c815cf440254d4f3bba4e7041db00a28.css 26 bytes 0 [emitted] main
8+
chunk {0} f49aa1e6c5ada5da859b.js, c815cf440254d4f3bba4e7041db00a28.css (main) 64 bytes [entry] [rendered]
9+
[0] (webpack)/test/statsCases/separate-css-bundle/a/file.css 41 bytes {0} [built]
10+
[1] (webpack)/test/statsCases/separate-css-bundle/a/index.js 23 bytes {0} [built]
11+
Child extract-text-webpack-plugin:
12+
chunk {0} extract-text-webpack-plugin-output-filename 1.65 kB [entry] [rendered]
13+
[0] (webpack)/~/css-loader/lib/css-base.js 1.46 kB {0} [built]
14+
[1] (webpack)/~/css-loader!(webpack)/test/statsCases/separate-css-bundle/a/file.css 192 bytes {0} [built]
15+
Child
16+
Hash: 9ff2cfa8882f273c8c6d
17+
Time: Xms
18+
Asset Size Chunks Chunk Names
19+
f49aa1e6c5ada5da859b.js 2.57 kB 0 [emitted] main
20+
a3f385680aef7a9bb2a517699532cc34.css 28 bytes 0 [emitted] main
21+
chunk {0} f49aa1e6c5ada5da859b.js, a3f385680aef7a9bb2a517699532cc34.css (main) 64 bytes [entry] [rendered]
22+
[0] (webpack)/test/statsCases/separate-css-bundle/b/file.css 41 bytes {0} [built]
23+
[1] (webpack)/test/statsCases/separate-css-bundle/b/index.js 23 bytes {0} [built]
24+
Child extract-text-webpack-plugin:
25+
chunk {0} extract-text-webpack-plugin-output-filename 1.65 kB [entry] [rendered]
26+
[0] (webpack)/~/css-loader/lib/css-base.js 1.46 kB {0} [built]
27+
[1] (webpack)/~/css-loader!(webpack)/test/statsCases/separate-css-bundle/b/file.css 194 bytes {0} [built]

0 commit comments

Comments
 (0)