Skip to content

Commit c0afdf9

Browse files
committed
beautify tests, lint hot and scripts
1 parent 9d88ada commit c0afdf9

14 files changed

Lines changed: 232 additions & 142 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"pretest": "npm run lint && npm run beautify-lint",
7777
"test": "mocha",
7878
"travis": "npm run cover -- --report lcovonly",
79-
"lint": "eslint lib bin",
79+
"lint": "eslint lib bin hot scripts",
8080
"beautify-lint": "node ./scripts/beautify-check",
8181
"beautify": "node ./scripts/beautify-rewrite",
8282
"precover": "npm run lint && npm run beautify-lint",

scripts/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
exports.beautify = {
2-
files: "{{lib,hot,scripts,bin}/**/*.js,benchmark/*.js}"
2+
files: "{{lib,hot,scripts,bin}/**/*.js,{benchmark,test}/*.js}"
33
};

test/ConfigTestCases.test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,33 @@ describe("ConfigTestCases", function() {
4444
if(checkArrayExpectation(testDirectory, jsonStats, "error", "Error", done)) return;
4545
if(checkArrayExpectation(testDirectory, jsonStats, "warning", "Warning", done)) return;
4646
var exportedTests = 0;
47+
4748
function _it(title, fn) {
4849
var test = new Test(title, fn);
4950
suite.addTest(test);
5051
exportedTests++;
5152
return test;
5253
}
54+
5355
function _require(module) {
5456
if(module.substr(0, 2) === "./") {
5557
var p = path.join(outputDirectory, module);
5658
var fn;
57-
if (options.target === "web") {
59+
if(options.target === "web") {
5860
fn = vm.runInNewContext("(function(require, module, exports, __dirname, __filename, it) {" + fs.readFileSync(p, "utf-8") + "\n})", {}, p);
5961
} else {
6062
fn = vm.runInThisContext("(function(require, module, exports, __dirname, __filename, it) {" + fs.readFileSync(p, "utf-8") + "\n})", p);
6163
}
62-
var module = { exports: {} };
64+
var module = {
65+
exports: {}
66+
};
6367
fn.call(module.exports, _require, module, module.exports, outputDirectory, p, _it);
6468
return module.exports;
6569
} else return require(module);
6670
}
6771
var filesCount = 0;
6872
var testConfig = {
69-
findBundle: function (i, options) {
73+
findBundle: function(i, options) {
7074
if(fs.existsSync(path.join(options.output.path, "bundle" + i + ".js"))) {
7175
return "./bundle" + i + ".js";
7276
}
@@ -78,7 +82,7 @@ describe("ConfigTestCases", function() {
7882
} catch(e) {}
7983
for(var i = 0; i < optionsArr.length; i++) {
8084
var bundlePath = testConfig.findBundle(i, optionsArr[i]);
81-
if (bundlePath) {
85+
if(bundlePath) {
8286
filesCount++;
8387
_require(bundlePath);
8488
}

test/Errors.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ describe("Errors", function() {
2121
};
2222
return files;
2323
}
24+
2425
function getErrors(options, callback) {
2526
options.context = base;
2627
var c = webpack(options);
2728
customOutputFilesystem(c);
2829
c.run(function(err, stats) {
2930
if(err) throw err;
3031
should.strictEqual(typeof stats, "object");
31-
stats = stats.toJson({ errorDetails: false });
32+
stats = stats.toJson({
33+
errorDetails: false
34+
});
3235
should.strictEqual(typeof stats, "object");
3336
stats.should.have.property("errors");
3437
stats.should.have.property("warnings");

test/Examples.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe("Examples", function() {
2222
options.forEach(processOptions);
2323
else
2424
processOptions(options);
25+
2526
function processOptions(options) {
2627
options.context = examplePath;
2728
options.optimize = options.optimize || {};
@@ -43,4 +44,4 @@ describe("Examples", function() {
4344
});
4445
});
4546
});
46-
});
47+
});

test/HotModuleReplacementPlugin.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ describe("HotModuleReplacementPlugin", function() {
88
it("should not have circular hashes but equal if unmodified", function(done) {
99
var entryFile = path.join(__dirname, "js", "entry.js");
1010
var recordsFile = path.join(__dirname, "js", "records.json");
11-
try { fs.mkdirSync(path.join(__dirname, "js")); } catch(e) {}
12-
try { fs.unlinkSync(recordsFile); } catch(e) {}
11+
try {
12+
fs.mkdirSync(path.join(__dirname, "js"));
13+
} catch(e) {}
14+
try {
15+
fs.unlinkSync(recordsFile);
16+
} catch(e) {}
1317
var compiler = webpack({
1418
cache: false,
1519
entry: entryFile,
@@ -58,4 +62,4 @@ describe("HotModuleReplacementPlugin", function() {
5862
});
5963
});
6064
});
61-
});
65+
});

test/Integration.test.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,40 @@ describe("Integration", function() {
3636
},
3737
bail: true,
3838
module: {
39-
postLoaders: [
40-
{
41-
test: /extra2\.js/,
42-
loader: "raw!extra!val?cacheable"
43-
}
44-
]
39+
postLoaders: [{
40+
test: /extra2\.js/,
41+
loader: "raw!extra!val?cacheable"
42+
}]
4543
},
4644
amd: {
4745
fromOptions: true
4846
},
4947
resolve: {
5048
// cannot resolve should outside the outermost node_modules
5149
// so it is injected here
52-
alias: { should: require.resolve("should") }
50+
alias: {
51+
should: require.resolve("should")
52+
}
5353
},
5454
plugins: [
55-
new webpack.optimize.LimitChunkCountPlugin({maxChunks: 1}),
55+
new webpack.optimize.LimitChunkCountPlugin({
56+
maxChunks: 1
57+
}),
5658
new webpack.DefinePlugin({
5759
"typeof CONST_TYPEOF": JSON.stringify("typeof"),
5860
CONST_TRUE: true,
5961
CONST_FALSE: false,
60-
CONST_FUNCTION: function() { return "ok"; },
62+
CONST_FUNCTION: function() {
63+
return "ok";
64+
},
6165
CONST_NUMBER: 123,
6266
CONST_NUMBER_EXPR: "1*100+23",
6367
CONST_OBJECT: {
6468
A: 1,
6569
B: JSON.stringify("B"),
66-
C: function() { return "C"; }
70+
C: function() {
71+
return "C";
72+
}
6773
}
6874
}),
6975
function() {
@@ -84,4 +90,4 @@ describe("Integration", function() {
8490
done();
8591
});
8692
});
87-
});
93+
});

test/NodeTemplatePlugin.test.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ describe("NodeTemplatePlugin", function() {
3030
result.loadChunk(456, function(chunk) {
3131
chunk.should.be.eql(123);
3232
result.loadChunk(567, function(chunk) {
33-
chunk.should.be.eql({a: 1});
33+
chunk.should.be.eql({
34+
a: 1
35+
});
3436
done();
3537
});
3638
});
@@ -50,7 +52,9 @@ describe("NodeTemplatePlugin", function() {
5052
},
5153
entry: "./entry",
5254
plugins: [
53-
new webpack.optimize.LimitChunkCountPlugin({maxChunks: 1}),
55+
new webpack.optimize.LimitChunkCountPlugin({
56+
maxChunks: 1
57+
}),
5458
new webpack.optimize.UglifyJsPlugin()
5559
]
5660
}, function(err, stats) {
@@ -64,7 +68,9 @@ describe("NodeTemplatePlugin", function() {
6468
chunk.should.be.eql(123);
6569
sameTick.should.be.eql(true);
6670
result.loadChunk(567, function(chunk) {
67-
chunk.should.be.eql({a: 1});
71+
chunk.should.be.eql({
72+
a: 1
73+
});
6874
done();
6975
});
7076
});

test/NodeWatchFileSystem.test.js

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ describe("NodeWatchFileSystem", function() {
2222
it("should register a file change (change delayed)", function(done) {
2323
var startTime = new Date().getTime();
2424
var wfs = new NodeWatchFileSystem();
25-
var watcher = wfs.watch([fileDirect], [], [], startTime, { aggregateTimeout: 1000 }, function(err, filesModified, dirsModified, missingCreated, fileTimestamps /*, dirTimestamps */) {
25+
var watcher = wfs.watch([fileDirect], [], [], startTime, {
26+
aggregateTimeout: 1000
27+
}, function(err, filesModified, dirsModified, missingCreated, fileTimestamps /*, dirTimestamps */ ) {
2628
if(err) throw err;
2729
filesModified.should.be.eql([fileDirect]);
2830
dirsModified.should.be.eql([]);
@@ -39,7 +41,9 @@ describe("NodeWatchFileSystem", function() {
3941
var startTime = new Date().getTime();
4042
setTimeout(function() {
4143
var wfs = new NodeWatchFileSystem();
42-
var watcher = wfs.watch([fileDirect], [], [], startTime, { aggregateTimeout: 1000 }, function(err, filesModified, dirsModified, missingCreated, fileTimestamps /*, dirTimestamps */) {
44+
var watcher = wfs.watch([fileDirect], [], [], startTime, {
45+
aggregateTimeout: 1000
46+
}, function(err, filesModified, dirsModified, missingCreated, fileTimestamps /*, dirTimestamps */ ) {
4347
if(err) throw err;
4448
filesModified.should.be.eql([fileDirect]);
4549
dirsModified.should.be.eql([]);
@@ -54,7 +58,9 @@ describe("NodeWatchFileSystem", function() {
5458
it("should register a context change (change delayed)", function(done) {
5559
var startTime = new Date().getTime();
5660
var wfs = new NodeWatchFileSystem();
57-
var watcher = wfs.watch([], [fixtures], [], startTime, { aggregateTimeout: 1000 }, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
61+
var watcher = wfs.watch([], [fixtures], [], startTime, {
62+
aggregateTimeout: 1000
63+
}, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
5864
if(err) throw err;
5965
filesModified.should.be.eql([]);
6066
dirsModified.should.be.eql([fixtures]);
@@ -71,7 +77,9 @@ describe("NodeWatchFileSystem", function() {
7177
var startTime = new Date().getTime();
7278
setTimeout(function() {
7379
var wfs = new NodeWatchFileSystem();
74-
var watcher = wfs.watch([], [fixtures], [], startTime, { aggregateTimeout: 1000 }, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
80+
var watcher = wfs.watch([], [fixtures], [], startTime, {
81+
aggregateTimeout: 1000
82+
}, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
7583
if(err) throw err;
7684
filesModified.should.be.eql([]);
7785
dirsModified.should.be.eql([fixtures]);
@@ -86,7 +94,9 @@ describe("NodeWatchFileSystem", function() {
8694
it("should register a context change (change delayed, subdirectory)", function(done) {
8795
var startTime = new Date().getTime();
8896
var wfs = new NodeWatchFileSystem();
89-
var watcher = wfs.watch([], [fixtures], [], startTime, { aggregateTimeout: 1000 }, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
97+
var watcher = wfs.watch([], [fixtures], [], startTime, {
98+
aggregateTimeout: 1000
99+
}, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
90100
if(err) throw err;
91101
filesModified.should.be.eql([]);
92102
dirsModified.should.be.eql([fixtures]);
@@ -103,7 +113,9 @@ describe("NodeWatchFileSystem", function() {
103113
var startTime = new Date().getTime();
104114
setTimeout(function() {
105115
var wfs = new NodeWatchFileSystem();
106-
var watcher = wfs.watch([], [fixtures], [], startTime, { aggregateTimeout: 1000 }, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
116+
var watcher = wfs.watch([], [fixtures], [], startTime, {
117+
aggregateTimeout: 1000
118+
}, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
107119
if(err) throw err;
108120
filesModified.should.be.eql([]);
109121
dirsModified.should.be.eql([fixtures]);
@@ -119,7 +131,9 @@ describe("NodeWatchFileSystem", function() {
119131
var startTime = new Date().getTime();
120132
setTimeout(function() {
121133
var wfs = new NodeWatchFileSystem();
122-
var watcher = wfs.watch([fileDirect, fileSubdir], [fixtures], [], startTime, { aggregateTimeout: 1000 }, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
134+
var watcher = wfs.watch([fileDirect, fileSubdir], [fixtures], [], startTime, {
135+
aggregateTimeout: 1000
136+
}, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
123137
if(err) throw err;
124138
filesModified.should.be.eql([fileSubdir, fileDirect]);
125139
dirsModified.should.be.eql([fixtures]);
@@ -136,17 +150,19 @@ describe("NodeWatchFileSystem", function() {
136150
});
137151
it("should sum up multiple changes", function(done) {
138152
var startTime = new Date().getTime();
139-
var wfs = new NodeWatchFileSystem();
140-
var watcher = wfs.watch([fileDirect, fileSubdir], [fixtures], [], startTime, { aggregateTimeout: 1000 }, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
141-
if(err) throw err;
142-
filesModified.should.be.eql([fileSubdir, fileDirect]);
143-
dirsModified.should.be.eql([fixtures]);
144-
fileTimestamps.should.have.property(fileDirect).have.type("number");
145-
fileTimestamps.should.have.property(fileSubdir).have.type("number");
146-
dirTimestamps.should.have.property(fixtures).have.type("number");
147-
watcher.close();
148-
done();
149-
});
153+
var wfs = new NodeWatchFileSystem();
154+
var watcher = wfs.watch([fileDirect, fileSubdir], [fixtures], [], startTime, {
155+
aggregateTimeout: 1000
156+
}, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
157+
if(err) throw err;
158+
filesModified.should.be.eql([fileSubdir, fileDirect]);
159+
dirsModified.should.be.eql([fixtures]);
160+
fileTimestamps.should.have.property(fileDirect).have.type("number");
161+
fileTimestamps.should.have.property(fileSubdir).have.type("number");
162+
dirTimestamps.should.have.property(fixtures).have.type("number");
163+
watcher.close();
164+
done();
165+
});
150166

151167
setTimeout(function() {
152168
fs.writeFile(fileDirect, "", function() {});

0 commit comments

Comments
 (0)