Skip to content

Commit e968b50

Browse files
alistairjcbrownTheLarkInn
authored andcommitted
Add tests for WebWorkerHotUpdateChunkTemplatePlugin (webpack#3685)
1 parent 9f3b868 commit e968b50

3 files changed

Lines changed: 124 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"memory-fs": "~0.4.1",
1818
"mkdirp": "~0.5.0",
1919
"node-libs-browser": "^2.0.0",
20+
"sinon": "^1.17.7",
2021
"source-map": "^0.5.3",
2122
"supports-color": "^3.1.0",
2223
"tapable": "~0.2.5",
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
var should = require("should");
2+
var sinon = require("sinon");
3+
var ConcatSource = require("webpack-sources").ConcatSource;
4+
var WebWorkerHotUpdateChunkTemplatePlugin = require("../lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin");
5+
var applyPluginWithOptions = require("./helpers/applyPluginWithOptions");
6+
7+
describe("WebWorkerHotUpdateChunkTemplatePlugin", function() {
8+
var handlerContext;
9+
10+
beforeEach(function() {
11+
handlerContext = {
12+
outputOptions: {
13+
hotUpdateFunction: "Foo",
14+
library: "Bar"
15+
}
16+
};
17+
});
18+
19+
it("has apply function", function() {
20+
(new WebWorkerHotUpdateChunkTemplatePlugin()).apply.should.be.a.Function();
21+
});
22+
23+
describe("when applied", function() {
24+
var eventBindings, eventBinding;
25+
26+
beforeEach(function() {
27+
eventBindings = applyPluginWithOptions(WebWorkerHotUpdateChunkTemplatePlugin);
28+
});
29+
30+
it("binds two event handlers", function() {
31+
eventBindings.length.should.be.exactly(2);
32+
});
33+
34+
describe("render handler", function() {
35+
beforeEach(function() {
36+
eventBinding = eventBindings[0];
37+
});
38+
39+
it("binds to render event", function() {
40+
eventBinding.name.should.be.exactly("render");
41+
});
42+
43+
describe("with hot update function name set", function() {
44+
it("creates source wrapper with function name", function() {
45+
var source = eventBinding.handler.call(handlerContext, "moduleSource()", [], [], {}, 100);
46+
source.should.be.instanceof(ConcatSource);
47+
source.source().should.be.exactly("Foo(100,moduleSource())");
48+
});
49+
});
50+
51+
describe("without hot update function name set", function() {
52+
it("creates source wrapper with library name", function() {
53+
delete handlerContext.outputOptions.hotUpdateFunction;
54+
var source = eventBinding.handler.call(handlerContext, "moduleSource()", [], [], {}, 100);
55+
source.should.be.instanceof(ConcatSource);
56+
source.source().should.be.exactly("webpackHotUpdateBar(100,moduleSource())");
57+
});
58+
});
59+
});
60+
61+
describe("hash handler", function() {
62+
var hashMock;
63+
64+
beforeEach(function() {
65+
eventBinding = eventBindings[1];
66+
hashMock = {
67+
update: sinon.spy()
68+
};
69+
});
70+
71+
it("binds to hash event", function() {
72+
eventBinding.name.should.be.exactly("hash");
73+
});
74+
75+
it("updates hash object", function() {
76+
eventBinding.handler.call(handlerContext, hashMock);
77+
hashMock.update.callCount.should.be.exactly(4);
78+
sinon.assert.calledWith(hashMock.update, "WebWorkerHotUpdateChunkTemplatePlugin");
79+
sinon.assert.calledWith(hashMock.update, "3");
80+
sinon.assert.calledWith(hashMock.update, "Foo");
81+
sinon.assert.calledWith(hashMock.update, "Bar");
82+
});
83+
});
84+
});
85+
});

yarn.lock

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,16 @@ escope@^3.6.0:
11401140
esrecurse "^4.1.0"
11411141
estraverse "^4.1.1"
11421142

1143+
eslint-plugin-node@^3.0.5:
1144+
version "3.0.5"
1145+
resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-3.0.5.tgz#03c8e23c6011eabd240e7ebf3556ec6e50fc734e"
1146+
dependencies:
1147+
ignore "^3.0.11"
1148+
minimatch "^3.0.2"
1149+
object-assign "^4.0.1"
1150+
resolve "^1.1.7"
1151+
semver "5.3.0"
1152+
11431153
eslint@3.12.2:
11441154
version "3.12.2"
11451155
resolved "https://registry.yarnpkg.com/eslint/-/eslint-3.12.2.tgz#6be5a9aa29658252abd7f91e9132bab1f26f3c34"
@@ -1427,6 +1437,12 @@ form-data@~2.1.1:
14271437
combined-stream "^1.0.5"
14281438
mime-types "^2.1.12"
14291439

1440+
formatio@1.1.1:
1441+
version "1.1.1"
1442+
resolved "https://registry.yarnpkg.com/formatio/-/formatio-1.1.1.tgz#5ed3ccd636551097383465d996199100e86161e9"
1443+
dependencies:
1444+
samsam "~1.1"
1445+
14301446
forwarded@~0.1.0:
14311447
version "0.1.0"
14321448
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.0.tgz#19ef9874c4ae1c297bcf078fde63a09b66a84363"
@@ -1702,7 +1718,7 @@ ieee754@^1.1.4:
17021718
version "1.1.8"
17031719
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.8.tgz#be33d40ac10ef1926701f6f08a2d86fbfd1ad3e4"
17041720

1705-
ignore@^3.2.0:
1721+
ignore@^3.0.11, ignore@^3.2.0:
17061722
version "3.2.0"
17071723
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.2.0.tgz#8d88f03c3002a0ac52114db25d2c673b0bf1e435"
17081724

@@ -2232,6 +2248,10 @@ log-driver@1.2.5:
22322248
version "1.2.5"
22332249
resolved "https://registry.yarnpkg.com/log-driver/-/log-driver-1.2.5.tgz#7ae4ec257302fd790d557cb10c97100d857b0056"
22342250

2251+
lolex@1.3.2:
2252+
version "1.3.2"
2253+
resolved "https://registry.yarnpkg.com/lolex/-/lolex-1.3.2.tgz#7c3da62ffcb30f0f5a80a2566ca24e45d8a01f31"
2254+
22352255
longest@^1.0.1:
22362256
version "1.0.1"
22372257
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
@@ -3300,7 +3320,7 @@ resolve-from@^1.0.0:
33003320
version "1.0.1"
33013321
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226"
33023322

3303-
resolve@1.1.x, resolve@^1.1.6:
3323+
resolve@1.1.x, resolve@^1.1.6, resolve@^1.1.7:
33043324
version "1.1.7"
33053325
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"
33063326

@@ -3343,6 +3363,10 @@ rx-lite@^3.1.2:
33433363
version "3.1.2"
33443364
resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-3.1.2.tgz#19ce502ca572665f3b647b10939f97fd1615f102"
33453365

3366+
samsam@1.1.2, samsam@~1.1:
3367+
version "1.1.2"
3368+
resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.1.2.tgz#bec11fdc83a9fda063401210e40176c3024d1567"
3369+
33463370
sax@~1.2.1:
33473371
version "1.2.1"
33483372
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.1.tgz#7b8e656190b228e81a66aea748480d828cd2d37a"
@@ -3353,7 +3377,7 @@ script-loader@~0.7.0:
33533377
dependencies:
33543378
raw-loader "~0.5.1"
33553379

3356-
"semver@2 || 3 || 4 || 5", semver@^5.0.3, semver@~5.3.0:
3380+
"semver@2 || 3 || 4 || 5", semver@5.3.0, semver@^5.0.3, semver@~5.3.0:
33573381
version "5.3.0"
33583382
resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"
33593383

@@ -3475,6 +3499,15 @@ signal-exit@^3.0.0:
34753499
version "3.0.2"
34763500
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
34773501

3502+
sinon@^1.17.7:
3503+
version "1.17.7"
3504+
resolved "https://registry.yarnpkg.com/sinon/-/sinon-1.17.7.tgz#4542a4f49ba0c45c05eb2e9dd9d203e2b8efe0bf"
3505+
dependencies:
3506+
formatio "1.1.1"
3507+
lolex "1.3.2"
3508+
samsam "1.1.2"
3509+
util ">=0.10.3 <1"
3510+
34783511
slice-ansi@0.0.4:
34793512
version "0.0.4"
34803513
resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-0.0.4.tgz#edbf8903f66f7ce2f8eafd6ceed65e264c831b35"
@@ -3873,7 +3906,7 @@ util-deprecate@~1.0.1:
38733906
version "1.0.2"
38743907
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
38753908

3876-
util@0.10.3, util@^0.10.3:
3909+
util@0.10.3, "util@>=0.10.3 <1", util@^0.10.3:
38773910
version "0.10.3"
38783911
resolved "https://registry.yarnpkg.com/util/-/util-0.10.3.tgz#7afb1afe50805246489e3db7fe0ed379336ac0f9"
38793912
dependencies:
@@ -3924,7 +3957,7 @@ void-elements@~2.0.1:
39243957
version "2.0.1"
39253958
resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-2.0.1.tgz#c066afb582bb1cb4128d60ea92392e94d5e9dbec"
39263959

3927-
watchpack@^1.0.0:
3960+
watchpack@^1.2.0:
39283961
version "1.2.0"
39293962
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.2.0.tgz#15d4620f1e7471f13fcb551d5c030d2c3eb42dbb"
39303963
dependencies:

0 commit comments

Comments
 (0)