@@ -62,37 +62,64 @@ assert.strictEqual(typeof fs.R_OK, 'number');
6262assert . strictEqual ( typeof fs . W_OK , 'number' ) ;
6363assert . strictEqual ( typeof fs . X_OK , 'number' ) ;
6464
65+ const throwNextTick = ( e ) => { process . nextTick ( ( ) => { throw e ; } ) ; } ;
66+
6567fs . access ( __filename , common . mustCall ( assert . ifError ) ) ;
68+ fs . promises . access ( __filename )
69+ . then ( common . mustCall ( ) )
70+ . catch ( throwNextTick ) ;
6671fs . access ( __filename , fs . R_OK , common . mustCall ( assert . ifError ) ) ;
72+ fs . promises . access ( __filename , fs . R_OK )
73+ . then ( common . mustCall ( ) )
74+ . catch ( throwNextTick ) ;
6775fs . access ( readOnlyFile , fs . F_OK | fs . R_OK , common . mustCall ( assert . ifError ) ) ;
76+ fs . promises . access ( readOnlyFile , fs . F_OK | fs . R_OK )
77+ . then ( common . mustCall ( ) )
78+ . catch ( throwNextTick ) ;
6879
69- fs . access ( doesNotExist , common . mustCall ( ( err ) => {
70- assert . notStrictEqual ( err , null , 'error should exist' ) ;
71- assert . strictEqual ( err . code , 'ENOENT' ) ;
72- assert . strictEqual ( err . path , doesNotExist ) ;
73- } ) ) ;
74-
75- fs . access ( readOnlyFile , fs . W_OK , common . mustCall ( function ( err ) {
76- assert . strictEqual ( this , undefined ) ;
77- if ( hasWriteAccessForReadonlyFile ) {
78- assert . ifError ( err ) ;
79- } else {
80- assert . notStrictEqual ( err , null , 'error should exist' ) ;
81- assert . strictEqual ( err . path , readOnlyFile ) ;
82- }
83- } ) ) ;
80+ {
81+ const expectedError = ( err ) => {
82+ assert . notStrictEqual ( err , null ) ;
83+ assert . strictEqual ( err . code , 'ENOENT' ) ;
84+ assert . strictEqual ( err . path , doesNotExist ) ;
85+ } ;
86+ fs . access ( doesNotExist , common . mustCall ( expectedError ) ) ;
87+ fs . promises . access ( doesNotExist )
88+ . then ( common . mustNotCall ( ) , common . mustCall ( expectedError ) )
89+ . catch ( throwNextTick ) ;
90+ }
8491
85- common . expectsError (
86- ( ) => {
87- fs . access ( 100 , fs . F_OK , common . mustNotCall ( ) ) ;
88- } ,
89- {
90- code : 'ERR_INVALID_ARG_TYPE' ,
91- type : TypeError ,
92- message : 'The " path" argument must be one of type string, Buffer, or URL.' +
93- ' Received type number'
92+ {
93+ function expectedError ( err ) {
94+ assert . strictEqual ( this , undefined ) ;
95+ if ( hasWriteAccessForReadonlyFile ) {
96+ assert . ifError ( err ) ;
97+ } else {
98+ assert . notStrictEqual ( err , null ) ;
99+ assert . strictEqual ( err . path , readOnlyFile ) ;
100+ }
94101 }
95- ) ;
102+ fs . access ( readOnlyFile , fs . W_OK , common . mustCall ( expectedError ) ) ;
103+ fs . promises . access ( readOnlyFile , fs . W_OK )
104+ . then ( common . mustNotCall ( ) , common . mustCall ( expectedError ) )
105+ . catch ( throwNextTick ) ;
106+ }
107+
108+ {
109+ const expectedError = ( err ) => {
110+ assert . strictEqual ( err . code , 'ERR_INVALID_ARG_TYPE' ) ;
111+ assert . ok ( err instanceof TypeError ) ;
112+ return true ;
113+ } ;
114+ assert . throws (
115+ ( ) => { fs . access ( 100 , fs . F_OK , common . mustNotCall ( ) ) ; } ,
116+ expectedError
117+ ) ;
118+
119+ fs . promises . access ( 100 , fs . F_OK )
120+ . then ( common . mustNotCall ( ) , common . mustCall ( expectedError ) )
121+ . catch ( throwNextTick ) ;
122+ }
96123
97124common . expectsError (
98125 ( ) => {
0 commit comments