11/* globals describe, it, before, after */
22"use strict" ;
33
4- const should = require ( "should" ) ;
54const path = require ( "path" ) ;
65const fs = require ( "fs" ) ;
76
87const webpack = require ( "../" ) ;
98const WebpackOptionsDefaulter = require ( "../lib/WebpackOptionsDefaulter" ) ;
109
11- describe ( "Compiler (caching)" , function ( ) {
12- this . timeout ( 15000 ) ;
10+ describe ( "Compiler (caching)" , ( ) => {
11+ jest . setTimeout ( 15000 ) ;
1312
1413 function compile ( entry , options , callback ) {
1514 options . mode = "none" ;
@@ -29,14 +28,14 @@ describe("Compiler (caching)", function() {
2928 const c = webpack ( options ) ;
3029 const files = { } ;
3130 c . outputFileSystem = {
32- join : function ( ) {
31+ join ( ) {
3332 return [ ] . join . call ( arguments , "/" ) . replace ( / \/ + / g, "/" ) ;
3433 } ,
35- mkdirp : function ( path , callback ) {
34+ mkdirp ( path , callback ) {
3635 logs . mkdirp . push ( path ) ;
3736 callback ( ) ;
3837 } ,
39- writeFile : function ( name , content , callback ) {
38+ writeFile ( name , content , callback ) {
4039 logs . writeFile . push ( name , content ) ;
4140 files [ name ] = content . toString ( "utf-8" ) ;
4241 callback ( ) ;
@@ -53,19 +52,19 @@ describe("Compiler (caching)", function() {
5352 }
5453 c . run ( ( err , stats ) => {
5554 if ( err ) throw err ;
56- should . strictEqual ( typeof stats , "object" ) ;
55+ expect ( typeof stats ) . toBe ( "object" ) ;
5756 stats = stats . toJson ( {
5857 modules : true ,
5958 reasons : true
6059 } ) ;
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 ) ;
6463 if ( options . expectErrors ) {
65- stats . errors . length . should . be . eql ( options . expectErrors ) ;
64+ expect ( stats . errors ) . toHaveLength ( options . expectErrors ) ;
6665 } else {
6766 if ( stats . errors . length > 0 ) {
68- stats . errors [ 0 ] . should . be . type ( "string" ) ;
67+ expect ( typeof stats . errors [ 0 ] ) . toBe ( "string" ) ;
6968 throw new Error ( stats . errors [ 0 ] ) ;
7069 }
7170 }
@@ -100,8 +99,8 @@ describe("Compiler (caching)", function() {
10099 ignoreENOENT ( ( ) => fs . unlinkSync ( cFilepath ) ) ;
101100 ignoreENOENT ( ( ) => fs . rmdirSync ( tempFixturePath ) ) ;
102101 }
103- before ( cleanup ) ;
104- after ( cleanup ) ;
102+ beforeAll ( cleanup ) ;
103+ afterAll ( cleanup ) ;
105104
106105 function createTempFixture ( ) {
107106
@@ -138,14 +137,14 @@ describe("Compiler (caching)", function() {
138137 const helper = compile ( "./temp-cache-fixture/c" , options , ( stats , files ) => {
139138
140139 // 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 ) ;
143142
144143 helper . runAgain ( ( stats , files , iteration ) => {
145144
146145 // 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 ) ;
149148
150149 const aContent = fs . readFileSync ( tempFixture . aFilepath ) . toString ( ) . replace ( "This is a" , "This is a MODIFIED" ) ;
151150
@@ -155,8 +154,8 @@ describe("Compiler (caching)", function() {
155154 helper . runAgain ( ( stats , files , iteration ) => {
156155
157156 // 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 ) ;
160159
161160 done ( ) ;
162161 } ) ;
@@ -174,15 +173,15 @@ describe("Compiler (caching)", function() {
174173 const helper = compile ( "./temp-cache-fixture/c" , options , ( stats , files ) => {
175174
176175 // 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 ) ;
179178
180179 helper . runAgain ( ( stats , files , iteration ) => {
181180 // 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 ) ;
184183
185- files [ "/bundle.js" ] . should . containEql ( "This is a" ) ;
184+ expect ( files [ "/bundle.js" ] ) . toMatch ( "This is a" ) ;
186185
187186 const aContent = fs . readFileSync ( tempFixture . aFilepath ) . toString ( ) . replace ( "This is a" , "This is a MODIFIED" ) ;
188187
@@ -191,10 +190,10 @@ describe("Compiler (caching)", function() {
191190 helper . runAgain ( ( stats , files , iteration ) => {
192191
193192 // 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 ) ;
196195
197- files [ "/bundle.js" ] . should . containEql ( "This is a MODIFIED" ) ;
196+ expect ( files [ "/bundle.js" ] ) . toMatch ( "This is a MODIFIED" ) ;
198197
199198 done ( ) ;
200199 } ) ;
@@ -210,21 +209,21 @@ describe("Compiler (caching)", function() {
210209 const helper = compile ( "./temp-cache-fixture/c" , options , ( stats , files ) => {
211210
212211 // 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 ) ;
215214
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 ) ;
218217
219218 setTimeout ( ( ) => {
220219 helper . runAgain ( ( stats , files , iteration ) => {
221220
222221 // 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);
225224
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);
228227
229228 const aContent = fs . readFileSync ( tempFixture . aFilepath ) . toString ( ) . replace ( "This is a" , "This is a MODIFIED" ) ;
230229
@@ -234,11 +233,11 @@ describe("Compiler (caching)", function() {
234233 helper . runAgain ( ( stats , files , iteration ) => {
235234
236235 // 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 ) ;
239238
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 ) ;
242241
243242 done ( ) ;
244243 } ) ;
@@ -256,20 +255,20 @@ describe("Compiler (caching)", function() {
256255 const helper = compile ( "./temp-cache-fixture/c" , options , ( stats , files ) => {
257256
258257 // 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 ) ;
261260
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 ) ;
264263
265264 helper . runAgain ( ( stats , files , iteration ) => {
266265
267266 // 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);
270269
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);
273272
274273 const aContent = fs . readFileSync ( tempFixture . aFilepath ) . toString ( ) . replace ( "This is a" , "This is a MODIFIED" ) ;
275274
@@ -278,11 +277,11 @@ describe("Compiler (caching)", function() {
278277 helper . runAgain ( ( stats , files , iteration ) => {
279278
280279 // 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);
283282
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 ) ;
286285
287286 done ( ) ;
288287 } ) ;
0 commit comments