|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -const { spawnPromisified, skipIfSQLiteMissing } = require('../common'); |
| 3 | +const { |
| 4 | + isWindows, |
| 5 | + spawnPromisified, |
| 6 | + skipIfSQLiteMissing, |
| 7 | +} = require('../common'); |
4 | 8 | skipIfSQLiteMissing();
|
5 | 9 | const fixtures = require('../common/fixtures');
|
| 10 | +const tmpdir = require('../common/tmpdir'); |
6 | 11 | const { match, strictEqual, deepStrictEqual } = require('node:assert');
|
7 | 12 | 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'); |
10 | 15 |
|
11 | 16 | test('should handle non existing json', async () => {
|
12 | 17 | const result = await spawnPromisified(process.execPath, [
|
@@ -364,21 +369,24 @@ test('should override node.config.json when specificied', async () => {
|
364 | 369 | // Skip on windows because it doesn't support chmod changing read permissions
|
365 | 370 | // Also skip if user is root because it would have read permissions anyway
|
366 | 371 | test('should throw an error when the file is non readable', {
|
367 |
| - skip: common.isWindows || process.getuid() === 0, |
| 372 | + skip: isWindows || process.getuid() === 0, |
368 | 373 | }, 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); |
370 | 380 | const result = await spawnPromisified(process.execPath, [
|
371 | 381 | '--no-warnings',
|
372 | 382 | '--experimental-default-config-file',
|
373 | 383 | '-p', 'http.maxHeaderSize',
|
374 | 384 | ], {
|
375 |
| - cwd: fixtures.path('rc/non-readable'), |
| 385 | + cwd: tmpdir.path, |
376 | 386 | });
|
377 | 387 | match(result.stderr, /Cannot read configuration from node\.config\.json: permission denied/);
|
378 | 388 | strictEqual(result.stdout, '');
|
379 | 389 | strictEqual(result.code, 9);
|
380 |
| - chmodSync(fixtures.path('rc/non-readable/node.config.json'), |
381 |
| - constants.S_IRWXU | constants.S_IRWXG | constants.S_IRWXO); |
382 | 390 | });
|
383 | 391 |
|
384 | 392 | describe('namespace-scoped options', () => {
|
|
0 commit comments