@@ -229,3 +229,48 @@ child.exec(`${nodejs} --use-strict -p process.execArgv`,
229
229
assert . strictEqual ( err , null ) ;
230
230
} ) ) ;
231
231
} ) ;
232
+
233
+ // ESModule eval tests
234
+
235
+
236
+ // Assert that "42\n" is written to stdout on module eval.
237
+ const execOptions = '--experimental-modules --input-type module' ;
238
+ child . exec (
239
+ `${ nodejs } ${ execOptions } --eval "console.log(42)"` ,
240
+ common . mustCall ( ( err , stdout ) => {
241
+ assert . ifError ( err ) ;
242
+ assert . strictEqual ( stdout , '42\n' ) ;
243
+ } ) ) ;
244
+
245
+ // Assert that "42\n" is written to stdout with print option.
246
+ child . exec (
247
+ `${ nodejs } ${ execOptions } --print --eval "42"` ,
248
+ common . mustCall ( ( err , stdout ) => {
249
+ assert . ifError ( err ) ;
250
+ assert . strictEqual ( stdout , '42\n' ) ;
251
+ } ) ) ;
252
+
253
+ // Assert that error is written to stderr on invalid input.
254
+ child . exec (
255
+ `${ nodejs } ${ execOptions } --eval "!!!!"` ,
256
+ common . mustCall ( ( err , stdout , stderr ) => {
257
+ assert . ok ( err ) ;
258
+ assert . strictEqual ( stdout , '' ) ;
259
+ assert . ok ( stderr . indexOf ( 'SyntaxError: Unexpected end of input' ) > 0 ) ;
260
+ } ) ) ;
261
+
262
+ // Assert that require is undefined in ESM support
263
+ child . exec (
264
+ `${ nodejs } ${ execOptions } --eval "console.log(typeof require);"` ,
265
+ common . mustCall ( ( err , stdout ) => {
266
+ assert . ifError ( err ) ;
267
+ assert . strictEqual ( stdout , 'undefined\n' ) ;
268
+ } ) ) ;
269
+
270
+ // Assert that import.meta is defined in ESM
271
+ child . exec (
272
+ `${ nodejs } ${ execOptions } --eval "console.log(typeof import.meta);"` ,
273
+ common . mustCall ( ( err , stdout ) => {
274
+ assert . ifError ( err ) ;
275
+ assert . strictEqual ( stdout , 'object\n' ) ;
276
+ } ) ) ;
0 commit comments