@@ -34,25 +34,25 @@ const makeBundle = (name, options) => del(`expected/${name}`).then(() => {
34
34
describe ( 'worker-loader' , ( ) => {
35
35
it ( 'should create chunk with worker' , ( ) =>
36
36
makeBundle ( 'worker' ) . then ( ( stats ) => {
37
- const workerFile = stats . toJson ( 'minimal' ) . children
37
+ const files = stats . toJson ( 'minimal' ) . children
38
38
. map ( item => item . chunks )
39
39
. reduce ( ( acc , item ) => acc . concat ( item ) , [ ] )
40
40
. map ( item => item . files )
41
- . map ( item => `expected/worker/${ item } ` ) [ 0 ] ;
42
- assert ( workerFile ) ;
43
- assert . notEqual ( readFile ( workerFile ) . indexOf ( '// worker test mark' ) , - 1 ) ;
41
+ . map ( item => `expected/worker/${ item } ` ) ;
42
+ assert . equal ( files . length , 1 ) ;
43
+ assert . notEqual ( readFile ( files [ 0 ] ) . indexOf ( '// worker test mark' ) , - 1 ) ;
44
44
} )
45
45
) ;
46
46
47
47
it ( 'should create chunk with specified name in query' , ( ) =>
48
48
makeBundle ( 'name-query' ) . then ( ( stats ) => {
49
- const file = stats . toJson ( 'minimal' ) . children
49
+ const files = stats . toJson ( 'minimal' ) . children
50
50
. map ( item => item . chunks )
51
51
. reduce ( ( acc , item ) => acc . concat ( item ) , [ ] )
52
52
. map ( item => item . files )
53
- . map ( item => `expected/name-query/${ item } ` ) [ 0 ] ;
54
- assert . equal ( file , 'expected/name-query/namedWorker.js' ) ;
55
- assert . notEqual ( readFile ( file ) . indexOf ( '// named worker test mark' ) , - 1 ) ;
53
+ . map ( item => `expected/name-query/${ item } ` ) ;
54
+ assert . equal ( files [ 0 ] , 'expected/name-query/namedWorker.js' ) ;
55
+ assert . notEqual ( readFile ( files [ 0 ] ) . indexOf ( '// named worker test mark' ) , - 1 ) ;
56
56
} )
57
57
) ;
58
58
@@ -74,24 +74,22 @@ describe('worker-loader', () => {
74
74
. map ( item => item . chunks )
75
75
. reduce ( ( acc , item ) => acc . concat ( item ) , [ ] )
76
76
. map ( item => item . files )
77
- . map ( item => `expected/name-options/${ item } ` ) ;
78
- const w1 = files . find ( file => file === 'expected/name-options/w1.js' ) ;
79
- const w2 = files . find ( file => file === 'expected/name-options/w2.js' ) ;
80
- assert ( w1 ) ;
81
- assert ( w2 ) ;
82
- assert . notEqual ( readFile ( w1 ) . indexOf ( '// w1 via worker options' ) , - 1 ) ;
83
- assert . notEqual ( readFile ( w2 ) . indexOf ( '// w2 via worker options' ) , - 1 ) ;
77
+ . map ( item => `expected/name-options/${ item } ` )
78
+ . sort ( ) ;
79
+ assert . equal ( files . length , 2 ) ;
80
+ assert . notEqual ( readFile ( files [ 0 ] ) . indexOf ( '// w1 via worker options' ) , - 1 ) ;
81
+ assert . notEqual ( readFile ( files [ 1 ] ) . indexOf ( '// w2 via worker options' ) , - 1 ) ;
84
82
} )
85
83
) ;
86
84
87
85
it ( 'should inline worker with inline option in query' , ( ) =>
88
86
makeBundle ( 'inline-query' ) . then ( ( stats ) => {
89
- const bundleFile = stats . toJson ( 'minimal' ) . chunks
87
+ const files = stats . toJson ( 'minimal' ) . chunks
90
88
. map ( item => item . files )
91
89
. reduce ( ( acc , item ) => acc . concat ( item ) , [ ] )
92
- . map ( item => `expected/inline-query/${ item } ` ) [ 0 ] ;
93
- assert ( bundleFile ) ;
94
- assert . notEqual ( readFile ( bundleFile ) . indexOf ( '// inlined worker test mark' ) , - 1 ) ;
90
+ . map ( item => `expected/inline-query/${ item } ` ) ;
91
+ assert . equal ( files . length , 1 ) ;
92
+ assert . notEqual ( readFile ( files [ 0 ] ) . indexOf ( '// inlined worker test mark' ) , - 1 ) ;
95
93
} )
96
94
) ;
97
95
@@ -109,13 +107,13 @@ describe('worker-loader', () => {
109
107
] ,
110
108
} ,
111
109
} ) . then ( ( stats ) => {
112
- const bundleFile = stats . toJson ( 'minimal' ) . chunks
110
+ const files = stats . toJson ( 'minimal' ) . chunks
113
111
. map ( item => item . files )
114
112
. reduce ( ( acc , item ) => acc . concat ( item ) , [ ] )
115
- . map ( item => `expected/inline-options/${ item } ` ) [ 0 ] ;
116
- assert ( bundleFile ) ;
117
- assert . notEqual ( readFile ( bundleFile ) . indexOf ( '// w1 inlined via options' ) , - 1 ) ;
118
- assert . notEqual ( readFile ( bundleFile ) . indexOf ( '// w2 inlined via options' ) , - 1 ) ;
113
+ . map ( item => `expected/inline-options/${ item } ` ) ;
114
+ assert . equal ( files . length , 1 ) ;
115
+ assert . notEqual ( readFile ( files [ 0 ] ) . indexOf ( '// w1 inlined via options' ) , - 1 ) ;
116
+ assert . notEqual ( readFile ( files [ 0 ] ) . indexOf ( '// w2 inlined via options' ) , - 1 ) ;
119
117
} )
120
118
) ;
121
119
0 commit comments