@@ -3,37 +3,29 @@ const common = require('../common');
33const assert = require ( 'assert' ) ;
44const fs = require ( 'fs' ) ;
55const cbTypeError = / ^ T y p e E r r o r : " c a l l b a c k " a r g u m e n t m u s t b e a f u n c t i o n $ / ;
6+ const callbackThrowValues = [ null , true , false , 0 , 1 , 'foo' , / f o o / , [ ] , { } ] ;
67
7- function test ( cb ) {
8+ const { sep } = require ( 'path' ) ;
9+ const warn = 'Calling an asynchronous function without callback is deprecated.' ;
10+
11+ common . refreshTmpDir ( ) ;
12+
13+ function testMakeCallback ( cb ) {
814 return function ( ) {
9- // fs.stat () calls makeCallback() on its second argument
10- fs . stat ( __filename , cb ) ;
15+ // fs.mkdtemp () calls makeCallback() on its third argument
16+ fs . mkdtemp ( ` ${ common . tmpDir } ${ sep } ` , { } , cb ) ;
1117 } ;
1218}
1319
14- // Verify the case where a callback function is provided
15- assert . doesNotThrow ( test ( common . noop ) ) ;
16-
17- process . once ( 'warning' , common . mustCall ( ( warning ) => {
18- assert . strictEqual (
19- warning . message ,
20- 'Calling an asynchronous function without callback is deprecated.'
21- ) ;
22-
23- invalidArgumentsTests ( ) ;
24- } ) ) ;
20+ common . expectWarning ( 'DeprecationWarning' , warn ) ;
2521
2622// Passing undefined/nothing calls rethrow() internally, which emits a warning
27- assert . doesNotThrow ( test ( ) ) ;
23+ assert . doesNotThrow ( testMakeCallback ( ) ) ;
2824
29- function invalidArgumentsTests ( ) {
30- assert . throws ( test ( null ) , cbTypeError ) ;
31- assert . throws ( test ( true ) , cbTypeError ) ;
32- assert . throws ( test ( false ) , cbTypeError ) ;
33- assert . throws ( test ( 1 ) , cbTypeError ) ;
34- assert . throws ( test ( 0 ) , cbTypeError ) ;
35- assert . throws ( test ( 'foo' ) , cbTypeError ) ;
36- assert . throws ( test ( / f o o / ) , cbTypeError ) ;
37- assert . throws ( test ( [ ] ) , cbTypeError ) ;
38- assert . throws ( test ( { } ) , cbTypeError ) ;
25+ function invalidCallbackThrowsTests ( ) {
26+ callbackThrowValues . forEach ( ( value ) => {
27+ assert . throws ( testMakeCallback ( value ) , cbTypeError ) ;
28+ } ) ;
3929}
30+
31+ invalidCallbackThrowsTests ( ) ;
0 commit comments