Skip to content

Commit 998f768

Browse files
committed
Migrate HotTestCases to Jest
1 parent cd419d0 commit 998f768

File tree

26 files changed

+178
-154
lines changed

26 files changed

+178
-154
lines changed

test/HotTestCases.test.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@ const checkArrayExpectation = require("./checkArrayExpectation");
99

1010
const webpack = require("../lib/webpack");
1111

12+
function createNestableIt(done) {
13+
let counter = 0;
14+
let aborted = false;
15+
return (title, fn) => {
16+
counter++;
17+
fn((err) => {
18+
if(aborted) {
19+
return;
20+
}
21+
if(err) {
22+
aborted = true;
23+
done(err);
24+
} else {
25+
counter--;
26+
if(counter === 0) {
27+
done();
28+
}
29+
}
30+
});
31+
}
32+
}
33+
1234
describe("HotTestCases", () => {
1335
const casesPath = path.join(__dirname, "hotCases");
1436
let categories = fs.readdirSync(casesPath).filter((dir) =>
@@ -22,9 +44,6 @@ describe("HotTestCases", () => {
2244
categories.forEach((category) => {
2345
describe(category.name, () => {
2446
category.tests.forEach((testName) => {
25-
const suite = describe(testName, function() {
26-
this.timeout(10000);
27-
});
2847
it(testName + " should compile", (done) => {
2948
const testDirectory = path.join(casesPath, category.name, testName);
3049
const outputDirectory = path.join(__dirname, "js", "hot-cases", category.name, testName);
@@ -70,11 +89,10 @@ describe("HotTestCases", () => {
7089
if(checkArrayExpectation(testDirectory, jsonStats, "warning", "Warning", done)) return;
7190
let exportedTests = 0;
7291

92+
const __it = createNestableIt(done);
7393
function _it(title, fn) {
74-
const test = new Test(title, fn);
75-
suite.addTest(test);
94+
__it(title, fn);
7695
exportedTests++;
77-
return test;
7896
}
7997

8098
function _next(callback) {
@@ -93,17 +111,16 @@ describe("HotTestCases", () => {
93111
function _require(module) {
94112
if(module.substr(0, 2) === "./") {
95113
const p = path.join(outputDirectory, module);
96-
const fn = vm.runInThisContext("(function(require, module, exports, __dirname, __filename, it, NEXT, STATS) {" + fs.readFileSync(p, "utf-8") + "\n})", p);
114+
const fn = vm.runInThisContext("(function(require, module, exports, __dirname, __filename, it, expect, NEXT, STATS) {" + fs.readFileSync(p, "utf-8") + "\n})", p);
97115
const m = {
98116
exports: {}
99117
};
100-
fn.call(m.exports, _require, m, m.exports, outputDirectory, p, _it, _next, jsonStats);
118+
fn.call(m.exports, _require, m, m.exports, outputDirectory, p, _it, expect, _next, jsonStats);
101119
return m.exports;
102120
} else return require(module);
103121
}
104122
_require("./bundle.js");
105123
if(exportedTests < 1) return done(new Error("No tests exported by test case"));
106-
process.nextTick(done);
107124
});
108125
});
109126
});

test/hotCases/chunks/accept-system-import/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
it("should import a changed chunk", function(done) {
2-
import("./chunk").then(function(chunk) {
3-
chunk.value.should.be.eql(1);
4-
import("./chunk2").then(function(chunk2) {
5-
chunk2.value.should.be.eql(1);
1+
it("should import a changed chunk", (done) => {
2+
import("./chunk").then((chunk) => {
3+
expect(chunk.value).toBe(1);
4+
import("./chunk2").then((chunk2) => {
5+
expect(chunk2.value).toBe(1);
66
NEXT(require("../../update")(done));
7-
module.hot.accept(["./chunk", "./chunk2"], function() {
8-
import("./chunk").then(function(chunk) {
9-
chunk.value.should.be.eql(2);
10-
import("./chunk2").then(function(chunk2) {
11-
chunk2.value.should.be.eql(2);
7+
module.hot.accept(["./chunk", "./chunk2"], () => {
8+
import("./chunk").then((chunk) => {
9+
expect(chunk.value).toBe(2);
10+
import("./chunk2").then((chunk2) => {
11+
expect(chunk2.value).toBe(2);
1212
done();
1313
}).catch(done);
1414
}).catch(done);

test/hotCases/chunks/dynamic-system-import/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ it("should import a changed chunk (dynamic import)", function(done) {
22
function load(name) {
33
return import("./chunk" + name);
44
}
5-
load(1).then(function(chunk) {
6-
chunk.value.should.be.eql(1);
7-
NEXT(require("../../update")(done, true, function() {
8-
chunk.value.should.be.eql(2);
9-
load(2).then(function(chunk2) {
10-
chunk2.value.should.be.eql(2);
5+
load(1).then((chunk) => {
6+
expect(chunk.value).toBe(1);
7+
NEXT(require("../../update")(done, true, () => {
8+
expect(chunk.value).toBe(2);
9+
load(2).then((chunk2) => {
10+
expect(chunk2.value).toBe(2);
1111
done();
1212
}).catch(done);
1313
}));

test/hotCases/chunks/system-import/index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
it("should import a changed chunk", function(done) {
2-
import("./chunk").then(function(chunk) {
3-
chunk.value.should.be.eql(1);
4-
chunk.value2.should.be.eql(3);
5-
chunk.counter.should.be.eql(0);
6-
NEXT(require("../../update")(done, true, function() {
7-
chunk.value.should.be.eql(2);
8-
chunk.value2.should.be.eql(4);
9-
chunk.counter.should.be.eql(1);
1+
it("should import a changed chunk", (done) => {
2+
import("./chunk").then((chunk) => {
3+
expect(chunk.value).toBe(1);
4+
expect(chunk.value2).toBe(3);
5+
expect(chunk.counter).toBe(0);
6+
NEXT(require("../../update")(done, true, () => {
7+
expect(chunk.value).toBe(2);
8+
expect(chunk.value2).toBe(4);
9+
expect(chunk.counter).toBe(1);
1010
import("./chunk2").then(function(chunk2) {
11-
chunk2.value.should.be.eql(2);
12-
chunk2.value2.should.be.eql(4);
13-
chunk2.counter.should.be.eql(0);
11+
expect(chunk2.value).toBe(2);
12+
expect(chunk2.value2).toBe(4);
13+
expect(chunk2.counter).toBe(0);
1414
done();
1515
}).catch(done);
1616
}));

test/hotCases/concat/reload-compat-flag/index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
var x = require("./module");
22

3-
it("should allow to hot replace modules in a ConcatenatedModule", function(done) {
4-
x.should.be.eql({
5-
default: "ok1",
6-
__esModule: true
3+
it("should allow to hot replace modules in a ConcatenatedModule", (done) => {
4+
expect(x).toEqual({
5+
default: "ok1"
76
});
8-
module.hot.accept("./module", function() {
7+
module.hot.accept("./module", () => {
98
x = require("./module");
10-
x.should.be.eql({
11-
default: "ok2",
12-
__esModule: true
9+
expect(x).toEqual({
10+
default: "ok2"
1311
});
1412
done();
1513
});

test/hotCases/concat/reload-external/module.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import value1 from "./a";
22
import value2 from "./b";
33

4-
it("should allow to hot replace modules in a ConcatenatedModule", function(done) {
5-
value1.should.be.eql(1);
6-
value2.should.be.eql(10);
7-
module.hot.accept("./a", function() {
8-
value1.should.be.eql(2);
4+
it("should allow to hot replace modules in a ConcatenatedModule", (done) => {
5+
expect(value1).toBe(1);
6+
expect(value2).toBe(10);
7+
module.hot.accept("./a", () => {
8+
expect(value1).toBe(2);
99
NEXT(require("../../update")(done));
1010
});
11-
module.hot.accept("./b", function() {
12-
value2.should.be.eql(20);
11+
module.hot.accept("./b", () => {
12+
expect(value2).toBe(20);
1313
done();
1414
});
1515
NEXT(require("../../update")(done));

test/hotCases/errors/decline/index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import a from "./a";
22

3-
it("should abort when module is declined by parent", function(done) {
4-
a.should.be.eql(1);
5-
NEXT(require("../../update")(function(err) {
3+
it("should abort when module is declined by parent", (done) => {
4+
expect(a).toBe(1);
5+
NEXT(require("../../update")((err) => {
66
try {
7-
err.message.should.match(/Aborted because of declined dependency: \.\/b\.js in \.\/a\.js\nUpdate propagation: \.\/c\.js -> \.\/b\.js -> \.\/a\.js/);
7+
expect(/Aborted because of declined dependency: \.\/b\.js in \.\/a\.js/.test(err.message)).toBe(true);
8+
expect(/Update propagation: \.\/c\.js -> \.\/b\.js -> \.\/a\.js/.test(err.message)).toBe(true);
89
done();
9-
} catch(e) { done(e); }
10+
} catch(e) {
11+
done(e);
12+
}
1013
}));
1114
});

test/hotCases/errors/events/index.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,30 @@ import f from "./f";
55
import h from "./h";
66
import j from "./j";
77

8-
it("should fire the correct events", function(done) {
8+
it("should fire the correct events", (done) => {
99
var events = [];
1010
var options = {
1111
ignoreUnaccepted: true,
1212
ignoreDeclined: true,
1313
ignoreErrored: true,
14-
onDeclined: function(data) { events.push(data); },
15-
onUnaccepted: function(data) { events.push(data); },
16-
onAccepted: function(data) { events.push(data); },
17-
onErrored: function(data) { events.push(data); }
14+
onDeclined(data) { events.push(data); },
15+
onUnaccepted(data) { events.push(data); },
16+
onAccepted(data) { events.push(data); },
17+
onErrored(data) { events.push(data); }
1818
};
1919

2020
function waitForUpdate(fn) {
21-
NEXT(require("../../update")(done, options, function() {
21+
NEXT(require("../../update")(done, options, () => {
2222
try {
2323
fn();
24-
} catch(e) { done(e); }
24+
} catch(e) {
25+
done(e);
26+
}
2527
}));
2628
}
2729

28-
waitForUpdate(function() {
29-
events.should.be.eql([
30+
waitForUpdate(() => {
31+
expect(events).toEqual([
3032
{
3133
type: "unaccepted",
3234
moduleId: "./index.js",
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import a from "./a";
22

3-
it("should abort when module is declined by itself", function(done) {
4-
a.should.be.eql(1);
5-
NEXT(require("../../update")(function(err) {
3+
it("should abort when module is declined by itself", (done) => {
4+
expect(a).toBe(1);
5+
NEXT(require("../../update")((err) => {
66
try {
7-
err.message.should.match(/Aborted because of self decline: \.\/a\.js\nUpdate propagation: \.\/c\.js -> \.\/b\.js -> \.\/a\.js/);
7+
expect(/Aborted because of self decline: \.\/a\.js/.test(err.message)).toBe(true);
8+
expect(/Update propagation: \.\/c\.js -> \.\/b\.js -> \.\/a\.js/.test(err.message)).toBe(true);
89
done();
9-
} catch(e) { done(e); }
10+
} catch(e) {
11+
done(e);
12+
}
1013
}));
1114
});

test/hotCases/errors/unaccepted-ignored/index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ import get from "./b";
33

44
var options = { ignoreUnaccepted: true };
55

6-
it("should ignore unaccepted module updates", function(done) {
6+
it("should ignore unaccepted module updates", (done) => {
77
function waitForUpdate(fn) {
88
NEXT(require("../../update")(done, options, fn));
99
}
1010

11-
a.should.be.eql(2);
12-
get().should.be.eql(1);
13-
waitForUpdate(function() {
14-
a.should.be.eql(2);
15-
get().should.be.eql(1);
16-
waitForUpdate(function() {
17-
a.should.be.eql(2);
18-
get().should.be.eql(2);
19-
waitForUpdate(function() {
20-
a.should.be.eql(2);
21-
get().should.be.eql(3);
11+
expect(a).toBe(2);
12+
expect(get()).toBe(1);
13+
waitForUpdate(() => {
14+
expect(a).toBe(2);
15+
expect(get()).toBe(1);
16+
waitForUpdate(() => {
17+
expect(a).toBe(2);
18+
expect(get()).toBe(2);
19+
waitForUpdate(() => {
20+
expect(a).toBe(2);
21+
expect(get()).toBe(3);
2222
done();
2323
});
2424
});

test/hotCases/errors/unaccepted/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import a from "./a";
22
import b from "./b";
33

4-
it("should abort when module is not accepted", function(done) {
5-
a.should.be.eql(2);
6-
b.should.be.eql(1);
7-
NEXT(require("../../update")(function(err) {
4+
it("should abort when module is not accepted", (done) => {
5+
expect(a).toBe(2);
6+
expect(b).toBe(1);
7+
NEXT(require("../../update")((err) => {
88
try {
9-
err.message.should.match(/Aborted because \.\/c\.js is not accepted\nUpdate propagation: \.\/c\.js -> \.\/b\.js -> \.\/index\.js/);
9+
expect(/Aborted because \.\/c\.js is not accepted/.test(err.message)).toBe(true);
10+
expect(/Update propagation: \.\/c\.js -> \.\/b\.js -> \.\/index\.js/.test(err.message)).toBe(true);
1011
done();
1112
} catch(e) { done(e); }
1213
}));
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import value from "./file";
22

3-
it("should auto-import a ES6 imported default value from non-harmony module on accept", function(done) {
4-
value.should.be.eql(1);
5-
module.hot.accept("./file", function() {
6-
value.should.be.eql(2);
3+
it("should auto-import a ES6 imported default value from non-harmony module on accept", (done) => {
4+
expect(value).toBe(1);
5+
module.hot.accept("./file", () => {
6+
expect(value).toBe(2);
77
outside();
88
done();
99
});
1010
NEXT(require("../../update")(done));
1111
});
1212

1313
function outside() {
14-
value.should.be.eql(2);
14+
expect(value).toBe(2);
1515
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { value } from "./file";
22
import value2 from "./commonjs";
33

4-
it("should auto-import multiple ES6 imported values on accept", function(done) {
5-
value.should.be.eql(1);
6-
value2.should.be.eql(10);
7-
module.hot.accept(["./file", "./commonjs"], function() {
8-
value.should.be.eql(2);
9-
value2.should.be.eql(20);
4+
it("should auto-import multiple ES6 imported values on accept", (done) => {
5+
expect(value).toBe(1);
6+
expect(value2).toBe(10);
7+
module.hot.accept(["./file", "./commonjs"], () => {
8+
expect(value).toBe(2);
9+
expect(value2).toBe(20);
1010
outside();
1111
done();
1212
});
1313
NEXT(require("../../update")(done));
1414
});
1515

1616
function outside() {
17-
value.should.be.eql(2);
18-
value2.should.be.eql(20);
17+
expect(value).toBe(2);
18+
expect(value2).toBe(20);
1919
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { value } from "./file";
22

33
it("should auto-import a ES6 imported value on accept", function(done) {
4-
value.should.be.eql(1);
4+
expect(value).toBe(1);
55
module.hot.accept("./file", function() {
6-
value.should.be.eql(2);
6+
expect(value).toBe(2);
77
outside();
88
done();
99
});
1010
NEXT(require("../../update")(done));
1111
});
1212

1313
function outside() {
14-
value.should.be.eql(2);
14+
expect(value).toBe(2);
1515
}

0 commit comments

Comments
 (0)