@@ -74,3 +74,97 @@ const stat = promisify(fs.stat);
74
74
assert . strictEqual ( value , undefined ) ;
75
75
} ) ) ;
76
76
}
77
+
78
+ {
79
+ function fn ( err , val , callback ) {
80
+ callback ( err , val ) ;
81
+ }
82
+ promisify ( fn ) ( null , 42 ) . then ( common . mustCall ( ( value ) => {
83
+ assert . strictEqual ( value , 42 ) ;
84
+ } ) ) ;
85
+ }
86
+
87
+ {
88
+ function fn ( err , val , callback ) {
89
+ callback ( err , val ) ;
90
+ }
91
+ promisify ( fn ) ( new Error ( 'oops' ) , null ) . catch ( common . mustCall ( ( err ) => {
92
+ assert . strictEqual ( err . message , 'oops' ) ;
93
+ } ) ) ;
94
+ }
95
+
96
+ {
97
+ function fn ( err , val , callback ) {
98
+ callback ( err , val ) ;
99
+ }
100
+
101
+ ( async ( ) => {
102
+ const value = await promisify ( fn ) ( null , 42 ) ;
103
+ assert . strictEqual ( value , 42 ) ;
104
+ } ) ( ) ;
105
+ }
106
+
107
+ {
108
+ const o = { } ;
109
+ const fn = promisify ( function ( cb ) {
110
+
111
+ cb ( null , this === o ) ;
112
+ } ) ;
113
+
114
+ o . fn = fn ;
115
+
116
+ o . fn ( ) . then ( common . mustCall ( function ( val ) {
117
+ assert ( val ) ;
118
+ } ) ) ;
119
+ }
120
+
121
+ {
122
+ const err = new Error ( 'Should not have called the callback with the error.' ) ;
123
+ const stack = err . stack ;
124
+
125
+ const fn = promisify ( function ( cb ) {
126
+ cb ( null ) ;
127
+ cb ( err ) ;
128
+ } ) ;
129
+
130
+ ( async ( ) => {
131
+ await fn ( ) ;
132
+ await Promise . resolve ( ) ;
133
+ return assert . strictEqual ( stack , err . stack ) ;
134
+ } ) ( ) ;
135
+ }
136
+
137
+ {
138
+ function c ( ) { }
139
+ const a = promisify ( function ( ) { } ) ;
140
+ const b = promisify ( a ) ;
141
+ assert . notStrictEqual ( c , a ) ;
142
+ assert . strictEqual ( a , b ) ;
143
+ }
144
+
145
+ {
146
+ let errToThrow ;
147
+ const thrower = promisify ( function ( a , b , c , cb ) {
148
+ errToThrow = new Error ( ) ;
149
+ throw errToThrow ;
150
+ } ) ;
151
+ thrower ( 1 , 2 , 3 )
152
+ . then ( assert . fail )
153
+ . then ( assert . fail , ( e ) => assert . strictEqual ( e , errToThrow ) ) ;
154
+ }
155
+
156
+ {
157
+ const err = new Error ( ) ;
158
+
159
+ const a = promisify ( ( cb ) => cb ( err ) ) ( ) ;
160
+ const b = promisify ( ( ) => { throw err ; } ) ( ) ;
161
+
162
+ Promise . all ( [
163
+ a . then ( assert . fail , function ( e ) {
164
+ assert . strictEqual ( err , e ) ;
165
+ } ) ,
166
+ b . then ( assert . fail , function ( e ) {
167
+ assert . strictEqual ( err , e ) ;
168
+ } )
169
+ ] ) ;
170
+ }
0 commit comments