@@ -4,6 +4,8 @@ const { spawnPromisified } = require('../common');
4
4
const fixtures = require ( '../common/fixtures' ) ;
5
5
const { match, strictEqual } = require ( 'node:assert' ) ;
6
6
const { test } = require ( 'node:test' ) ;
7
+ const { chmodSync, constants } = require ( 'node:fs' ) ;
8
+ const common = require ( '../common' ) ;
7
9
8
10
test ( 'should handle non existing json' , async ( ) => {
9
11
const result = await spawnPromisified ( process . execPath , [
@@ -304,3 +306,47 @@ test('broken value in node_options', async () => {
304
306
strictEqual ( result . stdout , '' ) ;
305
307
strictEqual ( result . code , 9 ) ;
306
308
} ) ;
309
+
310
+ test ( 'should use node.config.json as default' , async ( ) => {
311
+ const result = await spawnPromisified ( process . execPath , [
312
+ '--no-warnings' ,
313
+ '--experimental-default-config-file' ,
314
+ '-p' , 'http.maxHeaderSize' ,
315
+ ] , {
316
+ cwd : fixtures . path ( 'rc/default' ) ,
317
+ } ) ;
318
+ strictEqual ( result . stderr , '' ) ;
319
+ strictEqual ( result . stdout , '10\n' ) ;
320
+ strictEqual ( result . code , 0 ) ;
321
+ } ) ;
322
+
323
+ test ( 'should override node.config.json when specificied' , async ( ) => {
324
+ const result = await spawnPromisified ( process . execPath , [
325
+ '--no-warnings' ,
326
+ '--experimental-default-config-file' ,
327
+ '--experimental-config-file' ,
328
+ fixtures . path ( 'rc/default/override.json' ) ,
329
+ '-p' , 'http.maxHeaderSize' ,
330
+ ] , {
331
+ cwd : fixtures . path ( 'rc/default' ) ,
332
+ } ) ;
333
+ strictEqual ( result . stderr , '' ) ;
334
+ strictEqual ( result . stdout , '20\n' ) ;
335
+ strictEqual ( result . code , 0 ) ;
336
+ } ) ;
337
+ // Skip on windows because it doesn't support chmod changing read permissions
338
+ test ( 'should throw an error when the file is non readable' , { skip : common . isWindows } , async ( ) => {
339
+ chmodSync ( fixtures . path ( 'rc/non-readable/node.config.json' ) , constants . O_RDONLY ) ;
340
+ const result = await spawnPromisified ( process . execPath , [
341
+ '--no-warnings' ,
342
+ '--experimental-default-config-file' ,
343
+ '-p' , 'http.maxHeaderSize' ,
344
+ ] , {
345
+ cwd : fixtures . path ( 'rc/non-readable' ) ,
346
+ } ) ;
347
+ match ( result . stderr , / C a n n o t r e a d c o n f i g u r a t i o n f r o m n o d e \. c o n f i g \. j s o n : p e r m i s s i o n d e n i e d / ) ;
348
+ strictEqual ( result . stdout , '' ) ;
349
+ strictEqual ( result . code , 9 ) ;
350
+ chmodSync ( fixtures . path ( 'rc/non-readable/node.config.json' ) ,
351
+ constants . S_IRWXU | constants . S_IRWXG | constants . S_IRWXO ) ;
352
+ } ) ;
0 commit comments