Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit bba0d3c

Browse files
committed
added test cases, fixed bug, added CI
1 parent 1f81434 commit bba0d3c

File tree

59 files changed

+253
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+253
-9
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/node_modules
2-
/example/assets
2+
/example/assets
3+
/test/js

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
example/
2+
test/
23
.gitattributes

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- "0.12"
5+
- node
6+
script: npm run travis
7+
8+
after_success:
9+
- cat ./coverage/lcov.info | node_modules/.bin/coveralls --verbose
10+
- cat ./coverage/coverage.json | node_modules/codecov.io/bin/codecov.io.js
11+
- rm -rf ./coverage

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ ExtractTextPlugin.prototype.mergeNonInitialChunks = function(chunk, intoChunk, c
2525
} else if(checkedChunks.indexOf(chunk) < 0) {
2626
checkedChunks.push(chunk);
2727
chunk.modules.slice().forEach(function(module) {
28-
chunk.removeModule(module);
2928
intoChunk.addModule(module);
3029
module.addChunk(intoChunk);
3130
});
@@ -275,6 +274,13 @@ ExtractTextPlugin.prototype.apply = function(compiler) {
275274
if(extractedChunk.initial)
276275
this.mergeNonInitialChunks(extractedChunk);
277276
}, this);
277+
extractedChunks.forEach(function(extractedChunk) {
278+
if(!extractedChunk.initial) {
279+
extractedChunk.modules.forEach(function(module) {
280+
extractedChunk.removeModule(module);
281+
});
282+
}
283+
});
278284
compilation.applyPlugins("optimize-extracted-chunks", extractedChunks);
279285
callback();
280286
}.bind(this));

package.json

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,32 @@
77
"webpack": "^1.9.11"
88
},
99
"dependencies": {
10-
"async": "^1.2.1",
11-
"loader-utils": "~0.2.3"
10+
"async": "^1.5.0",
11+
"loader-utils": "^0.2.3"
1212
},
1313
"devDependencies": {
14-
"file-loader": "*",
15-
"style-loader": "*",
16-
"css-loader": "*",
17-
"webpack": "*"
14+
"codecov.io": "^0.1.2",
15+
"coveralls": "^2.11.2",
16+
"css-loader": "^0.21.0",
17+
"file-loader": "^0.8.4",
18+
"istanbul": "^0.3.13",
19+
"mocha": "^2.3.3",
20+
"mocha-lcov-reporter": "0.0.2",
21+
"raw-loader": "^0.5.1",
22+
"should": "^7.1.1",
23+
"style-loader": "^0.13.0",
24+
"webpack": "^1.12.2"
1825
},
1926
"homepage": "http://github.com/webpack/extract-text-webpack-plugin",
2027
"repository": {
2128
"type": "git",
2229
"url": "http://github.com/webpack/extract-text-webpack-plugin.git"
2330
},
24-
"license": "MIT"
31+
"license": "MIT",
32+
"scripts": {
33+
"test": "mocha",
34+
"travis": "npm run cover -- --report lcovonly",
35+
"cover": "istanbul cover node_modules/mocha/bin/_mocha",
36+
"publish-patch": "mocha && npm version patch && git push && git push --tags && npm publish"
37+
}
2538
}

test/TestCases.test.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
var fs = require("fs");
2+
var vm = require("vm");
3+
var path = require("path");
4+
var webpack = require("webpack");
5+
var should = require("should");
6+
var ExtractTextPlugin = require("../");
7+
8+
var cases = fs.readdirSync(path.join(__dirname, "cases"));
9+
10+
describe("TestCases", function() {
11+
cases.forEach(function(testCase) {
12+
it(testCase, function(done) {
13+
var testDirectory = path.join(__dirname, "cases", testCase);
14+
var outputDirectory = path.join(__dirname, "js", testCase);
15+
var options = { entry: { test: "./index.js" } };
16+
var configFile = path.join(testDirectory, "webpack.config.js");
17+
if(fs.existsSync(configFile))
18+
options = require(configFile);
19+
options.context = testDirectory;
20+
if(!options.module) options.module = {};
21+
if(!options.module.loaders) options.module.loaders = [
22+
{ test: /\.txt$/, loader: ExtractTextPlugin.extract("raw-loader") }
23+
];
24+
if(!options.output) options.output = { filename: "[name].js" };
25+
if(!options.output.path) options.output.path = outputDirectory;
26+
webpack(options, function(err, stats) {
27+
if(err) return done(err);
28+
if(stats.hasErrors()) return done(new Error(stats.toString()));
29+
var testFile = path.join(outputDirectory, "test.js");
30+
if(fs.existsSync(testFile))
31+
require(testFile)(suite);
32+
var expectedDirectory = path.join(testDirectory, "expected");
33+
fs.readdirSync(expectedDirectory).forEach(function(file) {
34+
var filePath = path.join(expectedDirectory, file);
35+
var actualPath = path.join(outputDirectory, file);
36+
readFileOrEmpty(actualPath).should.be.eql(
37+
readFileOrEmpty(filePath),
38+
file + " should be correct");
39+
});
40+
done();
41+
});
42+
});
43+
});
44+
});
45+
46+
function readFileOrEmpty(path) {
47+
try {
48+
return fs.readFileSync(path, "utf-8");
49+
} catch(e) {
50+
return "";
51+
}
52+
}

test/cases/merging-chunk/a.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a

test/cases/merging-chunk/b.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
a
2+
b

test/cases/merging-chunk/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require("./a.txt");
2+
require.ensure([], function() {
3+
require("./b.txt");
4+
});

0 commit comments

Comments
 (0)