Skip to content

Commit 0b92eb0

Browse files
authored
Merge pull request webpack#4053 from shubheksha/refactor-test-WatchDetection
refactor(ES6): WatchDetection.test.js
2 parents 105d970 + e27901d commit 0b92eb0

1 file changed

Lines changed: 31 additions & 28 deletions

File tree

test/WatchDetection.test.js

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
1+
"use strict";
2+
13
/*globals describe it before after */
2-
var should = require("should");
3-
var path = require("path");
4-
var fs = require("fs");
5-
var MemoryFs = require("memory-fs");
4+
const should = require("should");
5+
const path = require("path");
6+
const fs = require("fs");
7+
const MemoryFs = require("memory-fs");
68

7-
var webpack = require("../");
9+
const webpack = require("../");
810

9-
describe("WatchDetection", function() {
10-
for(var changeTimeout = 0; changeTimeout < 100; changeTimeout += 10) {
11+
describe("WatchDetection", () => {
12+
for(let changeTimeout = 0; changeTimeout < 100; changeTimeout += 10) {
1113
createTestCase(changeTimeout);
1214
}
13-
for(var changeTimeout = 100; changeTimeout <= 2000; changeTimeout += 100) {
15+
for(let changeTimeout = 100; changeTimeout <= 2000; changeTimeout += 100) {
1416
createTestCase(changeTimeout);
1517
}
1618

1719
function createTestCase(changeTimeout) {
1820
describe("time between changes " + changeTimeout + "ms", function() {
1921
this.timeout(10000);
20-
var fixturePath = path.join(__dirname, "fixtures", "temp-" + changeTimeout);
21-
var filePath = path.join(fixturePath, "file.js");
22-
var file2Path = path.join(fixturePath, "file2.js");
23-
var loaderPath = path.join(__dirname, "fixtures", "delay-loader.js");
24-
before(function() {
22+
const fixturePath = path.join(__dirname, "fixtures", "temp-" + changeTimeout);
23+
const filePath = path.join(fixturePath, "file.js");
24+
const file2Path = path.join(fixturePath, "file2.js");
25+
const loaderPath = path.join(__dirname, "fixtures", "delay-loader.js");
26+
before(() => {
2527
try {
2628
fs.mkdirSync(fixturePath);
2729
} catch(e) {}
2830
fs.writeFileSync(filePath, "require('./file2')", "utf-8");
2931
fs.writeFileSync(file2Path, "original", "utf-8");
3032
});
31-
after(function(done) {
32-
setTimeout(function() {
33+
after((done) => {
34+
setTimeout(() => {
3335
try {
3436
fs.unlinkSync(filePath);
3537
} catch(e) {}
@@ -42,33 +44,34 @@ describe("WatchDetection", function() {
4244
done();
4345
}, 100); // cool down a bit
4446
});
45-
it("should build the bundle correctly", function(done) {
46-
var compiler = webpack({
47+
it("should build the bundle correctly", (done) => {
48+
const compiler = webpack({
4749
entry: loaderPath + "!" + filePath,
4850
output: {
4951
path: "/",
5052
filename: "bundle.js"
5153
}
5254
});
53-
var memfs = compiler.outputFileSystem = new MemoryFs();
54-
var onChange;
55-
compiler.plugin("done", function() {
56-
if(onChange) onChange();
55+
const memfs = compiler.outputFileSystem = new MemoryFs();
56+
let onChange;
57+
compiler.plugin("done", () => {
58+
if(onChange)
59+
onChange();
5760
});
5861

59-
var watcher;
62+
let watcher;
6063

6164
step1();
6265

6366
function step1() {
64-
onChange = function() {
67+
onChange = () => {
6568
if(memfs.readFileSync("/bundle.js") && memfs.readFileSync("/bundle.js").toString().indexOf("original") >= 0)
6669
step2();
67-
}
70+
};
6871

6972
watcher = compiler.watch({
7073
aggregateTimeout: 50
71-
}, function() {});
74+
}, () => {});
7275
}
7376

7477
function step2() {
@@ -88,10 +91,10 @@ describe("WatchDetection", function() {
8891
}
8992

9093
function step4() {
91-
onChange = function() {
94+
onChange = () => {
9295
if(memfs.readFileSync("/bundle.js").toString().indexOf("correct") >= 0)
9396
step4();
94-
}
97+
};
9598

9699
fs.writeFile(file2Path, "correct", "utf-8", handleError);
97100
}
@@ -108,6 +111,6 @@ describe("WatchDetection", function() {
108111
if(err) done(err);
109112
}
110113
});
111-
})
114+
});
112115
}
113116
});

0 commit comments

Comments
 (0)