1
1
/* globals describe, it, before, after */
2
2
"use strict" ;
3
3
4
- const should = require ( "should" ) ;
5
4
const path = require ( "path" ) ;
6
5
const fs = require ( "fs" ) ;
7
6
8
7
const webpack = require ( "../" ) ;
9
8
const WebpackOptionsDefaulter = require ( "../lib/WebpackOptionsDefaulter" ) ;
10
9
11
- describe ( "Compiler (caching)" , function ( ) {
12
- this . timeout ( 15000 ) ;
10
+ describe ( "Compiler (caching)" , ( ) => {
11
+ jest . setTimeout ( 15000 ) ;
13
12
14
13
function compile ( entry , options , callback ) {
15
14
options . mode = "none" ;
@@ -29,14 +28,14 @@ describe("Compiler (caching)", function() {
29
28
const c = webpack ( options ) ;
30
29
const files = { } ;
31
30
c . outputFileSystem = {
32
- join : function ( ) {
31
+ join ( ) {
33
32
return [ ] . join . call ( arguments , "/" ) . replace ( / \/ + / g, "/" ) ;
34
33
} ,
35
- mkdirp : function ( path , callback ) {
34
+ mkdirp ( path , callback ) {
36
35
logs . mkdirp . push ( path ) ;
37
36
callback ( ) ;
38
37
} ,
39
- writeFile : function ( name , content , callback ) {
38
+ writeFile ( name , content , callback ) {
40
39
logs . writeFile . push ( name , content ) ;
41
40
files [ name ] = content . toString ( "utf-8" ) ;
42
41
callback ( ) ;
@@ -53,19 +52,19 @@ describe("Compiler (caching)", function() {
53
52
}
54
53
c . run ( ( err , stats ) => {
55
54
if ( err ) throw err ;
56
- should . strictEqual ( typeof stats , "object" ) ;
55
+ expect ( typeof stats ) . toBe ( "object" ) ;
57
56
stats = stats . toJson ( {
58
57
modules : true ,
59
58
reasons : true
60
59
} ) ;
61
- should . strictEqual ( typeof stats , "object" ) ;
62
- stats . should . have . property ( "errors" ) ;
63
- Array . isArray ( stats . errors ) . should . be . ok ( ) ;
60
+ expect ( typeof stats ) . toBe ( "object" ) ;
61
+ expect ( stats ) . toHaveProperty ( "errors" ) ;
62
+ expect ( Array . isArray ( stats . errors ) ) . toBe ( true ) ;
64
63
if ( options . expectErrors ) {
65
- stats . errors . length . should . be . eql ( options . expectErrors ) ;
64
+ expect ( stats . errors ) . toHaveLength ( options . expectErrors ) ;
66
65
} else {
67
66
if ( stats . errors . length > 0 ) {
68
- stats . errors [ 0 ] . should . be . type ( "string" ) ;
67
+ expect ( typeof stats . errors [ 0 ] ) . toBe ( "string" ) ;
69
68
throw new Error ( stats . errors [ 0 ] ) ;
70
69
}
71
70
}
@@ -100,8 +99,8 @@ describe("Compiler (caching)", function() {
100
99
ignoreENOENT ( ( ) => fs . unlinkSync ( cFilepath ) ) ;
101
100
ignoreENOENT ( ( ) => fs . rmdirSync ( tempFixturePath ) ) ;
102
101
}
103
- before ( cleanup ) ;
104
- after ( cleanup ) ;
102
+ beforeAll ( cleanup ) ;
103
+ afterAll ( cleanup ) ;
105
104
106
105
function createTempFixture ( ) {
107
106
@@ -138,14 +137,14 @@ describe("Compiler (caching)", function() {
138
137
const helper = compile ( "./temp-cache-fixture/c" , options , ( stats , files ) => {
139
138
140
139
// Not cached the first time
141
- stats . assets [ 0 ] . name . should . be . exactly ( "bundle.js" ) ;
142
- stats . assets [ 0 ] . emitted . should . be . exactly ( true ) ;
140
+ expect ( stats . assets [ 0 ] . name ) . toBe ( "bundle.js" ) ;
141
+ expect ( stats . assets [ 0 ] . emitted ) . toBe ( true ) ;
143
142
144
143
helper . runAgain ( ( stats , files , iteration ) => {
145
144
146
145
// Cached the second run
147
- stats . assets [ 0 ] . name . should . be . exactly ( "bundle.js" ) ;
148
- stats . assets [ 0 ] . emitted . should . be . exactly ( false ) ;
146
+ expect ( stats . assets [ 0 ] . name ) . toBe ( "bundle.js" ) ;
147
+ expect ( stats . assets [ 0 ] . emitted ) . toBe ( false ) ;
149
148
150
149
const aContent = fs . readFileSync ( tempFixture . aFilepath ) . toString ( ) . replace ( "This is a" , "This is a MODIFIED" ) ;
151
150
@@ -155,8 +154,8 @@ describe("Compiler (caching)", function() {
155
154
helper . runAgain ( ( stats , files , iteration ) => {
156
155
157
156
// Cached the third run
158
- stats . assets [ 0 ] . name . should . be . exactly ( "bundle.js" ) ;
159
- stats . assets [ 0 ] . emitted . should . be . exactly ( true ) ;
157
+ expect ( stats . assets [ 0 ] . name ) . toBe ( "bundle.js" ) ;
158
+ expect ( stats . assets [ 0 ] . emitted ) . toBe ( true ) ;
160
159
161
160
done ( ) ;
162
161
} ) ;
@@ -174,15 +173,15 @@ describe("Compiler (caching)", function() {
174
173
const helper = compile ( "./temp-cache-fixture/c" , options , ( stats , files ) => {
175
174
176
175
// Not cached the first time
177
- stats . assets [ 0 ] . name . should . be . exactly ( "bundle.js" ) ;
178
- stats . assets [ 0 ] . emitted . should . be . exactly ( true ) ;
176
+ expect ( stats . assets [ 0 ] . name ) . toBe ( "bundle.js" ) ;
177
+ expect ( stats . assets [ 0 ] . emitted ) . toBe ( true ) ;
179
178
180
179
helper . runAgain ( ( stats , files , iteration ) => {
181
180
// Cached the second run
182
- stats . assets [ 0 ] . name . should . be . exactly ( "bundle.js" ) ;
183
- stats . assets [ 0 ] . emitted . should . be . exactly ( false ) ;
181
+ expect ( stats . assets [ 0 ] . name ) . toBe ( "bundle.js" ) ;
182
+ expect ( stats . assets [ 0 ] . emitted ) . toBe ( false ) ;
184
183
185
- files [ "/bundle.js" ] . should . containEql ( "This is a" ) ;
184
+ expect ( files [ "/bundle.js" ] ) . toMatch ( "This is a" ) ;
186
185
187
186
const aContent = fs . readFileSync ( tempFixture . aFilepath ) . toString ( ) . replace ( "This is a" , "This is a MODIFIED" ) ;
188
187
@@ -191,10 +190,10 @@ describe("Compiler (caching)", function() {
191
190
helper . runAgain ( ( stats , files , iteration ) => {
192
191
193
192
// Cached the third run
194
- stats . assets [ 0 ] . name . should . be . exactly ( "bundle.js" ) ;
195
- stats . assets [ 0 ] . emitted . should . be . exactly ( true ) ;
193
+ expect ( stats . assets [ 0 ] . name ) . toBe ( "bundle.js" ) ;
194
+ expect ( stats . assets [ 0 ] . emitted ) . toBe ( true ) ;
196
195
197
- files [ "/bundle.js" ] . should . containEql ( "This is a MODIFIED" ) ;
196
+ expect ( files [ "/bundle.js" ] ) . toMatch ( "This is a MODIFIED" ) ;
198
197
199
198
done ( ) ;
200
199
} ) ;
@@ -210,21 +209,21 @@ describe("Compiler (caching)", function() {
210
209
const helper = compile ( "./temp-cache-fixture/c" , options , ( stats , files ) => {
211
210
212
211
// Built the first time
213
- stats . modules [ 0 ] . name . should . containEql ( "c.js" ) ;
214
- stats . modules [ 0 ] . built . should . be . exactly ( true , "c.js should have been built" ) ;
212
+ expect ( stats . modules [ 0 ] . name ) . toMatch ( "c.js" ) ;
213
+ expect ( stats . modules [ 0 ] . built ) . toBe ( true ) ;
215
214
216
- stats . modules [ 1 ] . name . should . containEql ( "a.js" ) ;
217
- stats . modules [ 1 ] . built . should . be . exactly ( true , "a.js should have been built" ) ;
215
+ expect ( stats . modules [ 1 ] . name ) . toMatch ( "a.js" ) ;
216
+ expect ( stats . modules [ 1 ] . built ) . toBe ( true ) ;
218
217
219
218
setTimeout ( ( ) => {
220
219
helper . runAgain ( ( stats , files , iteration ) => {
221
220
222
221
// Not built when cached the second run
223
- stats . modules [ 0 ] . name . should . containEql ( "c.js" ) ;
224
- //stats.modules[0].built.should.be.exactly (false, "c.js should not have built" );
222
+ expect ( stats . modules [ 0 ] . name ) . toMatch ( "c.js" ) ;
223
+ // expect( stats.modules[0].built).toBe (false);
225
224
226
- stats . modules [ 1 ] . name . should . containEql ( "a.js" ) ;
227
- //stats.modules[1].built.should.be.exactly (false, "a.js should not have built" );
225
+ expect ( stats . modules [ 1 ] . name ) . toMatch ( "a.js" ) ;
226
+ // expect( stats.modules[1].built).toBe (false);
228
227
229
228
const aContent = fs . readFileSync ( tempFixture . aFilepath ) . toString ( ) . replace ( "This is a" , "This is a MODIFIED" ) ;
230
229
@@ -234,11 +233,11 @@ describe("Compiler (caching)", function() {
234
233
helper . runAgain ( ( stats , files , iteration ) => {
235
234
236
235
// And only a.js built after it was modified
237
- stats . modules [ 0 ] . name . should . containEql ( "c.js" ) ;
238
- stats . modules [ 0 ] . built . should . be . exactly ( false , "c.js should not have built" ) ;
236
+ expect ( stats . modules [ 0 ] . name ) . toMatch ( "c.js" ) ;
237
+ expect ( stats . modules [ 0 ] . built ) . toBe ( false ) ;
239
238
240
- stats . modules [ 1 ] . name . should . containEql ( "a.js" ) ;
241
- stats . modules [ 1 ] . built . should . be . exactly ( true , "a.js should have been built" ) ;
239
+ expect ( stats . modules [ 1 ] . name ) . toMatch ( "a.js" ) ;
240
+ expect ( stats . modules [ 1 ] . built ) . toBe ( true ) ;
242
241
243
242
done ( ) ;
244
243
} ) ;
@@ -256,20 +255,20 @@ describe("Compiler (caching)", function() {
256
255
const helper = compile ( "./temp-cache-fixture/c" , options , ( stats , files ) => {
257
256
258
257
// Built the first time
259
- stats . modules [ 0 ] . name . should . containEql ( "c.js" ) ;
260
- stats . modules [ 0 ] . built . should . be . exactly ( true , "c.js should have been built" ) ;
258
+ expect ( stats . modules [ 0 ] . name ) . toMatch ( "c.js" ) ;
259
+ expect ( stats . modules [ 0 ] . built ) . toBe ( true ) ;
261
260
262
- stats . modules [ 1 ] . name . should . containEql ( "a.js" ) ;
263
- stats . modules [ 1 ] . built . should . be . exactly ( true , "a.js should have been built" ) ;
261
+ expect ( stats . modules [ 1 ] . name ) . toMatch ( "a.js" ) ;
262
+ expect ( stats . modules [ 1 ] . built ) . toBe ( true ) ;
264
263
265
264
helper . runAgain ( ( stats , files , iteration ) => {
266
265
267
266
// Not built when cached the second run
268
- stats . modules [ 0 ] . name . should . containEql ( "c.js" ) ;
269
- //stats.modules[0].built.should.be.exactly (false, "c.js should not have built" );
267
+ expect ( stats . modules [ 0 ] . name ) . toMatch ( "c.js" ) ;
268
+ // expect( stats.modules[0].built).toBe (false);
270
269
271
- stats . modules [ 1 ] . name . should . containEql ( "a.js" ) ;
272
- //stats.modules[1].built.should.be.exactly (false, "a.js should not have built" );
270
+ expect ( stats . modules [ 1 ] . name ) . toMatch ( "a.js" ) ;
271
+ // expect( stats.modules[1].built).toBe (false);
273
272
274
273
const aContent = fs . readFileSync ( tempFixture . aFilepath ) . toString ( ) . replace ( "This is a" , "This is a MODIFIED" ) ;
275
274
@@ -278,11 +277,11 @@ describe("Compiler (caching)", function() {
278
277
helper . runAgain ( ( stats , files , iteration ) => {
279
278
280
279
// And only a.js built after it was modified
281
- stats . modules [ 0 ] . name . should . containEql ( "c.js" ) ;
282
- //stats.modules[0].built.should.be.exactly (false, "c.js should not have built" );
280
+ expect ( stats . modules [ 0 ] . name ) . toMatch ( "c.js" ) ;
281
+ // expect( stats.modules[0].built).toBe (false);
283
282
284
- stats . modules [ 1 ] . name . should . containEql ( "a.js" ) ;
285
- stats . modules [ 1 ] . built . should . be . exactly ( true , "a.js should have been built" ) ;
283
+ expect ( stats . modules [ 1 ] . name ) . toMatch ( "a.js" ) ;
284
+ expect ( stats . modules [ 1 ] . built ) . toBe ( true ) ;
286
285
287
286
done ( ) ;
288
287
} ) ;
0 commit comments