Skip to content

Commit 100c6da

Browse files
lpincanodejs-github-bot
authored andcommitted
test: save the config file in a temporary directory
Allow the test to be run in parallel. Refs: #58799 (comment) PR-URL: #58799 Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Pietro Marchini <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Edy Silva <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]> Reviewed-By: Stefan Stojanovic <[email protected]>
1 parent cd685fe commit 100c6da

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

test/fixtures/rc/non-readable/node.config.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/parallel/test-config-file.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
'use strict';
22

3-
const { spawnPromisified, skipIfSQLiteMissing } = require('../common');
3+
const {
4+
isWindows,
5+
spawnPromisified,
6+
skipIfSQLiteMissing,
7+
} = require('../common');
48
skipIfSQLiteMissing();
59
const fixtures = require('../common/fixtures');
10+
const tmpdir = require('../common/tmpdir');
611
const { match, strictEqual, deepStrictEqual } = require('node:assert');
712
const { test, it, describe } = require('node:test');
8-
const { chmodSync, constants } = require('node:fs');
9-
const common = require('../common');
13+
const { chmodSync, writeFileSync, constants } = require('node:fs');
14+
const { join } = require('node:path');
1015

1116
test('should handle non existing json', async () => {
1217
const result = await spawnPromisified(process.execPath, [
@@ -364,21 +369,24 @@ test('should override node.config.json when specificied', async () => {
364369
// Skip on windows because it doesn't support chmod changing read permissions
365370
// Also skip if user is root because it would have read permissions anyway
366371
test('should throw an error when the file is non readable', {
367-
skip: common.isWindows || process.getuid() === 0,
372+
skip: isWindows || process.getuid() === 0,
368373
}, async () => {
369-
chmodSync(fixtures.path('rc/non-readable/node.config.json'), constants.O_RDONLY);
374+
tmpdir.refresh();
375+
const dest = join(tmpdir.path, 'node.config.json');
376+
writeFileSync(dest, JSON.stringify({
377+
nodeOptions: { 'max-http-header-size': 10 }
378+
}));
379+
chmodSync(dest, constants.O_RDONLY);
370380
const result = await spawnPromisified(process.execPath, [
371381
'--no-warnings',
372382
'--experimental-default-config-file',
373383
'-p', 'http.maxHeaderSize',
374384
], {
375-
cwd: fixtures.path('rc/non-readable'),
385+
cwd: tmpdir.path,
376386
});
377387
match(result.stderr, /Cannot read configuration from node\.config\.json: permission denied/);
378388
strictEqual(result.stdout, '');
379389
strictEqual(result.code, 9);
380-
chmodSync(fixtures.path('rc/non-readable/node.config.json'),
381-
constants.S_IRWXU | constants.S_IRWXG | constants.S_IRWXO);
382390
});
383391

384392
describe('namespace-scoped options', () => {

0 commit comments

Comments
 (0)