From ec957ba010d2432467f6176ab6e917cd5b7e2258 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Mon, 23 Jun 2025 11:17:02 +0200 Subject: [PATCH 1/2] test: deflake test-config-file Port 9229 may already be used by another process. Use a random available one. --- test/parallel/test-config-file.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/parallel/test-config-file.js b/test/parallel/test-config-file.js index 57824d16e4ca9a..8bd494acde5ffa 100644 --- a/test/parallel/test-config-file.js +++ b/test/parallel/test-config-file.js @@ -239,6 +239,7 @@ test('--inspect=true should be parsed correctly', { skip: !process.features.insp '--no-warnings', '--experimental-config-file', fixtures.path('rc/inspect-true.json'), + '--inspect-port', '0', '-p', 'require("node:inspector").url()', ]); match(result.stderr, /^Debugger listening on (ws:\/\/[^\s]+)/); From 8bfd35b4d8a0b7bc2e1b9ccb5436b88a2e1c8bf2 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Mon, 23 Jun 2025 11:57:31 +0200 Subject: [PATCH 2/2] test: save the config file in a temporary directory Allow the test to be run in parallel. Refs: https://github.com/nodejs/node/pull/58799#issuecomment-2995684216 --- .../fixtures/rc/non-readable/node.config.json | 5 ---- test/parallel/test-config-file.js | 24 ++++++++++++------- 2 files changed, 16 insertions(+), 13 deletions(-) delete mode 100755 test/fixtures/rc/non-readable/node.config.json diff --git a/test/fixtures/rc/non-readable/node.config.json b/test/fixtures/rc/non-readable/node.config.json deleted file mode 100755 index 21e2b85fbda8fc..00000000000000 --- a/test/fixtures/rc/non-readable/node.config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "nodeOptions": { - "max-http-header-size": 10 - } -} diff --git a/test/parallel/test-config-file.js b/test/parallel/test-config-file.js index 8bd494acde5ffa..75d0922630cd3a 100644 --- a/test/parallel/test-config-file.js +++ b/test/parallel/test-config-file.js @@ -1,12 +1,17 @@ 'use strict'; -const { spawnPromisified, skipIfSQLiteMissing } = require('../common'); +const { + isWindows, + spawnPromisified, + skipIfSQLiteMissing, +} = require('../common'); skipIfSQLiteMissing(); const fixtures = require('../common/fixtures'); +const tmpdir = require('../common/tmpdir'); const { match, strictEqual, deepStrictEqual } = require('node:assert'); const { test, it, describe } = require('node:test'); -const { chmodSync, constants } = require('node:fs'); -const common = require('../common'); +const { chmodSync, writeFileSync, constants } = require('node:fs'); +const { join } = require('node:path'); test('should handle non existing json', async () => { const result = await spawnPromisified(process.execPath, [ @@ -364,21 +369,24 @@ test('should override node.config.json when specificied', async () => { // Skip on windows because it doesn't support chmod changing read permissions // Also skip if user is root because it would have read permissions anyway test('should throw an error when the file is non readable', { - skip: common.isWindows || process.getuid() === 0, + skip: isWindows || process.getuid() === 0, }, async () => { - chmodSync(fixtures.path('rc/non-readable/node.config.json'), constants.O_RDONLY); + tmpdir.refresh(); + const dest = join(tmpdir.path, 'node.config.json'); + writeFileSync(dest, JSON.stringify({ + nodeOptions: { 'max-http-header-size': 10 } + })); + chmodSync(dest, constants.O_RDONLY); const result = await spawnPromisified(process.execPath, [ '--no-warnings', '--experimental-default-config-file', '-p', 'http.maxHeaderSize', ], { - cwd: fixtures.path('rc/non-readable'), + cwd: tmpdir.path, }); match(result.stderr, /Cannot read configuration from node\.config\.json: permission denied/); strictEqual(result.stdout, ''); strictEqual(result.code, 9); - chmodSync(fixtures.path('rc/non-readable/node.config.json'), - constants.S_IRWXU | constants.S_IRWXG | constants.S_IRWXO); }); describe('namespace-scoped options', () => {