Skip to content

Commit fe09c38

Browse files
committed
test: expand schema validation coverage for node.config.json
1 parent fcab719 commit fe09c38

5 files changed

Lines changed: 78 additions & 15 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"nodeOptions": {
3+
"import": true
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"nodeOptions": {
3+
"import": [123]
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"nodeOptions": {
3+
"max-http-header-size": "not-a-number"
4+
}
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"nodeOptions": {
3+
"addons": false,
4+
"max-http-header-size": 8192
5+
}
6+
}

test/parallel/test-config-file.js

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -676,20 +676,62 @@ describe('namespace-scoped options', () => {
676676
});
677677
});
678678

679-
test('should reject config with schema validation errors', async () => {
680-
const result = await spawnPromisified(process.execPath, [
681-
'--experimental-config-file',
682-
fixtures.path('rc/invalid-schema-type.json'),
683-
'-p', '"Hello"',
684-
]);
685-
assert.match(result.stderr, /Invalid configuration/);
686-
assert.strictEqual(result.code, 9);
687-
});
679+
describe('JSON Schema validation', () => {
680+
test('rejects boolean option with string value', async () => {
681+
const result = await spawnPromisified(process.execPath, [
682+
'--experimental-config-file',
683+
fixtures.path('rc/invalid-schema-type.json'),
684+
'-p', '"Hello"',
685+
]);
686+
assert.match(result.stderr, /Invalid configuration/);
687+
assert.strictEqual(result.code, 9);
688+
});
688689

689-
test('process.versions.ata should be defined', async () => {
690-
const result = await spawnPromisified(process.execPath, [
691-
'-p', 'process.versions.ata',
692-
]);
693-
assert.match(result.stdout, /\d+\.\d+\.\d+/);
694-
assert.strictEqual(result.code, 0);
690+
test('rejects number option with string value', async () => {
691+
const result = await spawnPromisified(process.execPath, [
692+
'--experimental-config-file',
693+
fixtures.path('rc/invalid-schema-number-as-string.json'),
694+
'-p', '"Hello"',
695+
]);
696+
assert.match(result.stderr, /Invalid configuration/);
697+
assert.strictEqual(result.code, 9);
698+
});
699+
700+
test('rejects array option with boolean value', async () => {
701+
const result = await spawnPromisified(process.execPath, [
702+
'--experimental-config-file',
703+
fixtures.path('rc/invalid-schema-array-as-bool.json'),
704+
'-p', '"Hello"',
705+
]);
706+
assert.match(result.stderr, /Invalid configuration/);
707+
assert.strictEqual(result.code, 9);
708+
});
709+
710+
test('rejects array with wrong item type', async () => {
711+
const result = await spawnPromisified(process.execPath, [
712+
'--experimental-config-file',
713+
fixtures.path('rc/invalid-schema-nested-type.json'),
714+
'-p', '"Hello"',
715+
]);
716+
assert.match(result.stderr, /Invalid configuration/);
717+
assert.strictEqual(result.code, 9);
718+
});
719+
720+
test('accepts valid config with mixed types', async () => {
721+
const result = await spawnPromisified(process.execPath, [
722+
'--experimental-config-file',
723+
fixtures.path('rc/valid-schema-all-types.json'),
724+
'-e', 'process.exit(0)',
725+
]);
726+
assert.strictEqual(result.code, 0);
727+
});
728+
729+
test('accepts empty object config', async () => {
730+
const result = await spawnPromisified(process.execPath, [
731+
'--experimental-config-file',
732+
fixtures.path('rc/empty-object.json'),
733+
'-e', 'process.exit(0)',
734+
]);
735+
assert.strictEqual(result.code, 0);
736+
});
695737
});

0 commit comments

Comments
 (0)