File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -662,6 +662,11 @@ internals.protect = function (item, state) {
662662
663663 try {
664664 await item . fn . call ( null , flags ) ;
665+ // wait for any pending ticks started by the test
666+ await new Promise ( ( next ) => {
667+
668+ setImmediate ( next ) ;
669+ } ) ;
665670 finish ( ) ;
666671 }
667672 catch ( ex ) {
Original file line number Diff line number Diff line change @@ -889,4 +889,13 @@ describe('CLI', () => {
889889 expect ( result . output ) . to . contain ( '1 of 2 tests failed' ) ;
890890 expect ( result . output ) . to . contain ( 'oops' ) ;
891891 } ) ;
892+
893+ it ( 'awaits any pending ticks started by test before starting next test' , async ( ) => {
894+
895+ const { code, output } = await RunCli ( [ 'test/cli_nexttick/test.js' ] ) ;
896+
897+ expect ( code ) . to . equal ( 1 ) ;
898+ expect ( output ) . to . contain ( 'does not crash lab' ) ;
899+ expect ( output ) . to . not . contain ( 'has another test' ) ;
900+ } ) ;
892901} ) ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ // Load modules
4+
5+ const Hoek = require ( '@hapi/hoek' ) ;
6+ const _Lab = require ( '../../test_runner' ) ;
7+
8+
9+ // Declare internals
10+
11+ const internals = { } ;
12+
13+
14+ // Test shortcuts
15+
16+ const lab = exports . lab = _Lab . script ( ) ;
17+ const describe = lab . describe ;
18+ const it = lab . it ;
19+
20+
21+ describe ( 'Test CLI' , ( ) => {
22+
23+ it ( 'does not crash lab' , async ( ) => {
24+
25+ await Hoek . wait ( 1 ) ;
26+
27+ process . nextTick ( ( ) => {
28+
29+ throw new Error ( 'fail' ) ;
30+ } ) ;
31+ } ) ;
32+
33+ it ( 'has another test' , async ( ) => { } ) ;
34+ } ) ;
You can’t perform that action at this time.
0 commit comments