Skip to content

Commit 5dacac6

Browse files
authored
Merge pull request webpack#4651 from sendilkumarn/refactor-wwmtp
refactoring WebWorkerMainTemplatePlugin.test.js to ES6
2 parents 75efda9 + 9a1e429 commit 5dacac6

File tree

1 file changed

+48
-46
lines changed

1 file changed

+48
-46
lines changed

test/WebWorkerMainTemplatePlugin.test.js

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
var should = require("should");
2-
var sinon = require("sinon");
3-
var WebWorkerMainTemplatePlugin = require("../lib/webworker/WebWorkerMainTemplatePlugin");
4-
var applyPluginWithOptions = require("./helpers/applyPluginWithOptions");
1+
"use strict";
2+
3+
const should = require("should");
4+
const sinon = require("sinon");
5+
const WebWorkerMainTemplatePlugin = require("../lib/webworker/WebWorkerMainTemplatePlugin");
6+
const applyPluginWithOptions = require("./helpers/applyPluginWithOptions");
57

68
describe("WebWorkerMainTemplatePlugin", function() {
7-
var env;
9+
let env;
810

9-
beforeEach(function() {
11+
beforeEach(() => {
1012
env = {};
1113
});
1214

@@ -26,7 +28,7 @@ describe("WebWorkerMainTemplatePlugin", function() {
2628
chunkFilename: 'chunkFilename'
2729
},
2830
applyPluginsWaterfall: (moduleName, fileName, data) => {
29-
return '"' + moduleName + data.hash + data.hashWithLength() + (data.chunk && data.chunk.id || '') + '"';
31+
return `"${moduleName}${data.hash}${data.hashWithLength()}${data.chunk && data.chunk.id || ''}"`;
3032
},
3133
renderAddModule: () => 'renderAddModuleSource();',
3234
};
@@ -37,31 +39,31 @@ describe("WebWorkerMainTemplatePlugin", function() {
3739
});
3840

3941
describe("local-vars handler", function() {
40-
beforeEach(function() {
42+
beforeEach(() => {
4143
env.eventBinding = env.eventBindings[0];
4244
});
4345

44-
it("binds to local-vars event", function() {
46+
it("binds to local-vars event", () => {
4547
env.eventBinding.name.should.be.exactly("local-vars");
4648
});
4749

48-
describe("when no chunks are provided", function() {
49-
beforeEach(function() {
50-
var chunk = {
50+
describe("when no chunks are provided", () => {
51+
beforeEach(() => {
52+
const chunk = {
5153
ids: [],
5254
chunks: []
5355
};
5456
env.source = env.eventBinding.handler.call(env.handlerContext, "moduleSource()", chunk);
5557
});
5658

57-
it("returns the original source", function() {
59+
it("returns the original source", () => {
5860
env.source.should.be.exactly("moduleSource()")
5961
});
6062
});
6163

62-
describe("when chunks are provided", function() {
63-
beforeEach(function() {
64-
var chunk = {
64+
describe("when chunks are provided", () => {
65+
beforeEach(() => {
66+
const chunk = {
6567
ids: [1, 2, 3],
6668
chunks: [
6769
'foo',
@@ -72,7 +74,7 @@ describe("WebWorkerMainTemplatePlugin", function() {
7274
env.source = env.eventBinding.handler.call(env.handlerContext, "moduleSource()", chunk, 'abc123');
7375
});
7476

75-
it("returns the original source with installed mapping", function() {
77+
it("returns the original source with installed mapping", () => {
7678
env.source.should.be.exactly(`
7779
moduleSource()
7880
@@ -88,22 +90,22 @@ var installedChunks = {
8890
});
8991
});
9092

91-
describe("require-ensure handler", function() {
92-
beforeEach(function() {
93+
describe("require-ensure handler", () => {
94+
beforeEach(() => {
9395
env.eventBinding = env.eventBindings[1];
9496
});
9597

96-
it("binds to require-ensure event", function() {
98+
it("binds to require-ensure event", () => {
9799
env.eventBinding.name.should.be.exactly("require-ensure");
98100
});
99101

100-
describe("when called", function() {
101-
beforeEach(function() {
102-
var chunk = {};
102+
describe("when called", () => {
103+
beforeEach(() => {
104+
const chunk = {};
103105
env.source = env.eventBinding.handler.call(env.handlerContext, "moduleSource()", chunk, 'abc123');
104106
});
105107

106-
it("creates import scripts call and promise resolve", function() {
108+
it("creates import scripts call and promise resolve", () => {
107109
env.source.should.be.exactly(`
108110
// "1" is the signal for "already loaded"
109111
if(!installedChunks[chunkId]) {
@@ -115,32 +117,32 @@ return Promise.resolve();
115117
});
116118
});
117119

118-
describe("bootstrap handler", function() {
119-
beforeEach(function() {
120+
describe("bootstrap handler", () => {
121+
beforeEach(() => {
120122
env.eventBinding = env.eventBindings[2];
121123
});
122124

123-
it("binds to bootstrap event", function() {
125+
it("binds to bootstrap event", () => {
124126
env.eventBinding.name.should.be.exactly("bootstrap");
125127
});
126128

127-
describe("when no chunks are provided", function() {
128-
beforeEach(function() {
129-
var chunk = {
129+
describe("when no chunks are provided", () => {
130+
beforeEach(() => {
131+
const chunk = {
130132
ids: [],
131133
chunks: []
132134
};
133135
env.source = env.eventBinding.handler.call(env.handlerContext, "moduleSource()", chunk);
134136
});
135137

136-
it("returns the original source", function() {
138+
it("returns the original source", () => {
137139
env.source.should.be.exactly("moduleSource()")
138140
});
139141
});
140142

141-
describe("when chunks are provided", function() {
142-
beforeEach(function() {
143-
var chunk = {
143+
describe("when chunks are provided", () => {
144+
beforeEach(() => {
145+
const chunk = {
144146
ids: [1, 2, 3],
145147
chunks: [
146148
'foo',
@@ -151,7 +153,7 @@ return Promise.resolve();
151153
env.source = env.eventBinding.handler.call(env.handlerContext, "moduleSource()", chunk);
152154
});
153155

154-
it("returns the original source with chunk callback", function() {
156+
it("returns the original source with chunk callback", () => {
155157
env.source.should.be.exactly(`
156158
moduleSource()
157159
this["webpackChunk"] = function webpackChunkCallback(chunkIds, moreModules) {
@@ -166,22 +168,22 @@ installedChunks[chunkIds.pop()] = 1;
166168
});
167169
});
168170

169-
describe("hot-bootstrap handler", function() {
170-
beforeEach(function() {
171+
describe("hot-bootstrap handler", () => {
172+
beforeEach(() => {
171173
env.eventBinding = env.eventBindings[3];
172174
});
173175

174-
it("binds to hot-bootstrap event", function() {
176+
it("binds to hot-bootstrap event", () => {
175177
env.eventBinding.name.should.be.exactly("hot-bootstrap");
176178
});
177179

178-
describe("when called", function() {
179-
beforeEach(function() {
180-
var chunk = {};
180+
describe("when called", () => {
181+
beforeEach(() => {
182+
const chunk = {};
181183
env.source = env.eventBinding.handler.call(env.handlerContext, "moduleSource()", chunk, 'abc123');
182184
});
183185

184-
it("returns the original source with hot update callback", function() {
186+
it("returns the original source with hot update callback", () => {
185187
env.source.should.be.exactly(`
186188
moduleSource()
187189
var parentHotUpdateCallback = this["webpackHotUpdate"];
@@ -240,8 +242,8 @@ function hotDisposeChunk(chunkId) { //eslint-disable-line no-unused-vars
240242
});
241243
});
242244

243-
describe("hash handler", function() {
244-
beforeEach(function() {
245+
describe("hash handler", () => {
246+
beforeEach(() => {
245247
env.eventBinding = env.eventBindings[4];
246248
env.handlerContext = {
247249
outputOptions: {
@@ -258,11 +260,11 @@ function hotDisposeChunk(chunkId) { //eslint-disable-line no-unused-vars
258260
env.eventBinding.handler.call(env.handlerContext, env.hashMock);
259261
});
260262

261-
it("binds to hash event", function() {
263+
it("binds to hash event", () => {
262264
env.eventBinding.name.should.be.exactly("hash");
263265
});
264266

265-
it("updates hash object", function() {
267+
it("updates hash object", () => {
266268
env.hashMock.update.callCount.should.be.exactly(7);
267269
sinon.assert.calledWith(env.hashMock.update, "webworker");
268270
sinon.assert.calledWith(env.hashMock.update, "3");

0 commit comments

Comments
 (0)