@@ -5,19 +5,29 @@ const sinon = require("sinon");
55const WebWorkerMainTemplatePlugin = require ( "../lib/webworker/WebWorkerMainTemplatePlugin" ) ;
66const applyPluginWithOptions = require ( "./helpers/applyPluginWithOptions" ) ;
77
8- describe ( "WebWorkerMainTemplatePlugin" , function ( ) {
8+ const createMockChunk = ( ids , chunks ) => {
9+ return {
10+ ids : ids ,
11+ _chunks : new Set ( chunks ) ,
12+ getChunks ( ) {
13+ return this . _chunks ;
14+ }
15+ } ;
16+ } ;
17+
18+ describe ( "WebWorkerMainTemplatePlugin" , function ( ) {
919 let env ;
1020
1121 beforeEach ( ( ) => {
1222 env = { } ;
1323 } ) ;
1424
15- it ( "has apply function" , function ( ) {
25+ it ( "has apply function" , function ( ) {
1626 ( new WebWorkerMainTemplatePlugin ( ) ) . apply . should . be . a . Function ( ) ;
1727 } ) ;
1828
19- describe ( "when applied" , function ( ) {
20- beforeEach ( function ( ) {
29+ describe ( "when applied" , function ( ) {
30+ beforeEach ( function ( ) {
2131 env . eventBindings = applyPluginWithOptions ( WebWorkerMainTemplatePlugin ) ;
2232 env . handlerContext = {
2333 requireFn : 'requireFn' ,
@@ -34,11 +44,11 @@ describe("WebWorkerMainTemplatePlugin", function() {
3444 } ;
3545 } ) ;
3646
37- it ( "binds five event handlers" , function ( ) {
47+ it ( "binds five event handlers" , function ( ) {
3848 env . eventBindings . length . should . be . exactly ( 5 ) ;
3949 } ) ;
4050
41- describe ( "local-vars handler" , function ( ) {
51+ describe ( "local-vars handler" , function ( ) {
4252 beforeEach ( ( ) => {
4353 env . eventBinding = env . eventBindings [ 0 ] ;
4454 } ) ;
@@ -49,10 +59,7 @@ describe("WebWorkerMainTemplatePlugin", function() {
4959
5060 describe ( "when no chunks are provided" , ( ) => {
5161 beforeEach ( ( ) => {
52- const chunk = {
53- ids : [ ] ,
54- chunks : [ ]
55- } ;
62+ const chunk = createMockChunk ( ) ;
5663 env . source = env . eventBinding . handler . call ( env . handlerContext , "moduleSource()" , chunk ) ;
5764 } ) ;
5865
@@ -63,14 +70,11 @@ describe("WebWorkerMainTemplatePlugin", function() {
6370
6471 describe ( "when chunks are provided" , ( ) => {
6572 beforeEach ( ( ) => {
66- const chunk = {
67- ids : [ 1 , 2 , 3 ] ,
68- chunks : [
69- 'foo' ,
70- 'bar' ,
71- 'baz'
72- ]
73- } ;
73+ const chunk = createMockChunk ( [ 1 , 2 , 3 ] , [
74+ 'foo' ,
75+ 'bar' ,
76+ 'baz'
77+ ] ) ;
7478 env . source = env . eventBinding . handler . call ( env . handlerContext , "moduleSource()" , chunk , 'abc123' ) ;
7579 } ) ;
7680
@@ -101,7 +105,7 @@ var installedChunks = {
101105
102106 describe ( "when called" , ( ) => {
103107 beforeEach ( ( ) => {
104- const chunk = { } ;
108+ const chunk = createMockChunk ( ) ;
105109 env . source = env . eventBinding . handler . call ( env . handlerContext , "moduleSource()" , chunk , 'abc123' ) ;
106110 } ) ;
107111
@@ -130,10 +134,7 @@ resolve();
130134
131135 describe ( "when no chunks are provided" , ( ) => {
132136 beforeEach ( ( ) => {
133- const chunk = {
134- ids : [ ] ,
135- chunks : [ ]
136- } ;
137+ const chunk = createMockChunk ( ) ;
137138 env . source = env . eventBinding . handler . call ( env . handlerContext , "moduleSource()" , chunk ) ;
138139 } ) ;
139140
@@ -144,14 +145,11 @@ resolve();
144145
145146 describe ( "when chunks are provided" , ( ) => {
146147 beforeEach ( ( ) => {
147- const chunk = {
148- ids : [ 1 , 2 , 3 ] ,
149- chunks : [
150- 'foo' ,
151- 'bar' ,
152- 'baz'
153- ]
154- } ;
148+ const chunk = createMockChunk ( [ 1 , 2 , 3 ] , [
149+ 'foo' ,
150+ 'bar' ,
151+ 'baz'
152+ ] ) ;
155153 env . source = env . eventBinding . handler . call ( env . handlerContext , "moduleSource()" , chunk ) ;
156154 } ) ;
157155
@@ -181,7 +179,7 @@ installedChunks[chunkIds.pop()] = 1;
181179
182180 describe ( "when called" , ( ) => {
183181 beforeEach ( ( ) => {
184- const chunk = { } ;
182+ const chunk = createMockChunk ( ) ;
185183 env . source = env . eventBinding . handler . call ( env . handlerContext , "moduleSource()" , chunk , 'abc123' ) ;
186184 } ) ;
187185
0 commit comments