Skip to content

Commit d1ecae6

Browse files
test: refactor
1 parent 483a9ea commit d1ecae6

File tree

1 file changed

+42
-34
lines changed

1 file changed

+42
-34
lines changed

test/middleware.test.js

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,23 @@ describe('middleware', () => {
4242
}
4343

4444
function close(done) {
45-
instance.close();
45+
if (instance.context.watching.closed) {
46+
if (listen) {
47+
listen.close(done);
48+
} else {
49+
done();
50+
}
4651

47-
if (listen) {
48-
listen.close(done);
49-
} else {
50-
done();
52+
return;
5153
}
54+
55+
instance.close(() => {
56+
if (listen) {
57+
listen.close(done);
58+
} else {
59+
done();
60+
}
61+
});
5262
}
5363

5464
describe('basic', () => {
@@ -2147,10 +2157,10 @@ describe('middleware', () => {
21472157
listen = listenShorthand(done);
21482158
});
21492159

2150-
afterAll(() => {
2160+
afterAll((done) => {
21512161
spy.mockRestore();
21522162

2153-
close();
2163+
close(done);
21542164
});
21552165

21562166
it('should pass arguments to the "watch" method', (done) => {
@@ -2186,10 +2196,10 @@ describe('middleware', () => {
21862196
listen = listenShorthand(done);
21872197
});
21882198

2189-
afterAll(() => {
2199+
afterAll((done) => {
21902200
spy.mockRestore();
21912201

2192-
close();
2202+
close(done);
21932203
});
21942204

21952205
it('should pass arguments to the "watch" method', (done) => {
@@ -2228,10 +2238,10 @@ describe('middleware', () => {
22282238
listen = listenShorthand(done);
22292239
});
22302240

2231-
afterAll(() => {
2241+
afterAll((done) => {
22322242
spy.mockRestore();
22332243

2234-
close();
2244+
close(done);
22352245
});
22362246

22372247
it('should pass arguments to the "watch" method', (done) => {
@@ -2283,10 +2293,10 @@ describe('middleware', () => {
22832293
listen = listenShorthand(done);
22842294
});
22852295

2286-
afterAll(() => {
2296+
afterAll((done) => {
22872297
del.sync(path.posix.resolve(__dirname, './outputs/write-to-disk-true'));
22882298

2289-
close();
2299+
close(done);
22902300
});
22912301

22922302
it('should find the bundle file on disk', (done) => {
@@ -2412,12 +2422,12 @@ describe('middleware', () => {
24122422
listen = listenShorthand(done);
24132423
});
24142424

2415-
afterAll(() => {
2425+
afterAll((done) => {
24162426
del.sync(
24172427
path.posix.resolve(__dirname, './outputs/write-to-disk-function-true')
24182428
);
24192429

2420-
close();
2430+
close(done);
24212431
});
24222432

24232433
it('should find the bundle file on disk', (done) => {
@@ -2465,15 +2475,15 @@ describe('middleware', () => {
24652475
listen = listenShorthand(done);
24662476
});
24672477

2468-
afterAll(() => {
2478+
afterAll((done) => {
24692479
del.sync(
24702480
path.posix.resolve(
24712481
__dirname,
24722482
'./outputs/write-to-disk-function-false'
24732483
)
24742484
);
24752485

2476-
close();
2486+
close(done);
24772487
});
24782488

24792489
it('should not find the bundle file on disk', (done) => {
@@ -2519,12 +2529,12 @@ describe('middleware', () => {
25192529
listen = listenShorthand(done);
25202530
});
25212531

2522-
afterAll(() => {
2532+
afterAll((done) => {
25232533
del.sync(
25242534
path.posix.resolve(__dirname, './outputs/write-to-disk-query-string')
25252535
);
25262536

2527-
close();
2537+
close(done);
25282538
});
25292539

25302540
it('should find the bundle file on disk with no querystring', (done) => {
@@ -2584,15 +2594,15 @@ describe('middleware', () => {
25842594
listen = listenShorthand(done);
25852595
});
25862596

2587-
afterAll(() => {
2597+
afterAll((done) => {
25882598
del.sync(
25892599
path.posix.resolve(
25902600
__dirname,
25912601
'./outputs/write-to-disk-multi-compiler/'
25922602
)
25932603
);
25942604

2595-
close();
2605+
close(done);
25962606
});
25972607

25982608
it('should find the bundle files on disk', (done) => {
@@ -2667,12 +2677,12 @@ describe('middleware', () => {
26672677
});
26682678
});
26692679

2670-
afterAll(() => {
2680+
afterAll((done) => {
26712681
del.sync(
26722682
path.posix.resolve(__dirname, './outputs/write-to-disk-with-hash/')
26732683
);
26742684

2675-
close();
2685+
close(done);
26762686
});
26772687

26782688
it('should find the bundle file on disk', (done) => {
@@ -3269,10 +3279,10 @@ describe('middleware', () => {
32693279
listen = listenShorthand(done);
32703280
});
32713281

3272-
afterAll(() => {
3282+
afterAll((done) => {
32733283
isDirectory.mockRestore();
32743284

3275-
close();
3285+
close(done);
32763286
});
32773287

32783288
it('should return the "404" code for the "GET" request to the public path', (done) => {
@@ -3581,22 +3591,22 @@ describe('middleware', () => {
35813591
listen = listenShorthand(done);
35823592
});
35833593

3584-
afterAll(() => {
3594+
afterAll((done) => {
35853595
del.sync(
35863596
path.posix.resolve(__dirname, './outputs/write-to-disk-mkdir-error')
35873597
);
35883598

35893599
mkdirSpy.mockRestore();
3600+
3601+
close(done);
35903602
});
35913603

35923604
it('should logging', (done) => {
35933605
compiler.hooks.failed.tap('FailedCatcher', () => {
35943606
instance.close(() => {
35953607
expect(getLogsPlugin.logs).toMatchSnapshot();
35963608

3597-
listen.close(() => {
3598-
done();
3599-
});
3609+
done();
36003610
});
36013611
});
36023612
});
@@ -3638,7 +3648,7 @@ describe('middleware', () => {
36383648
listen = listenShorthand(done);
36393649
});
36403650

3641-
afterAll(() => {
3651+
afterAll((done) => {
36423652
writeFileSpy.mockRestore();
36433653

36443654
del.sync(
@@ -3648,17 +3658,15 @@ describe('middleware', () => {
36483658
)
36493659
);
36503660

3651-
close();
3661+
close(done);
36523662
});
36533663

36543664
it('should logging', (done) => {
36553665
compiler.hooks.failed.tap('FailedCatcher', () => {
36563666
instance.close(() => {
36573667
expect(getLogsPlugin.logs).toMatchSnapshot();
36583668

3659-
listen.close(() => {
3660-
done();
3661-
});
3669+
done();
36623670
});
36633671
});
36643672
});

0 commit comments

Comments
 (0)