Skip to content

Commit d8df486

Browse files
committed
test: expand schema validation coverage for node.config.json
1 parent 5bdb5f5 commit d8df486

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
@@ -606,20 +606,62 @@ describe('namespace-scoped options', () => {
606606
});
607607
});
608608

609-
test('should reject config with schema validation errors', async () => {
610-
const result = await spawnPromisified(process.execPath, [
611-
'--experimental-config-file',
612-
fixtures.path('rc/invalid-schema-type.json'),
613-
'-p', '"Hello"',
614-
]);
615-
assert.match(result.stderr, /Invalid configuration/);
616-
assert.strictEqual(result.code, 9);
617-
});
609+
describe('JSON Schema validation', () => {
610+
test('rejects boolean option with string value', async () => {
611+
const result = await spawnPromisified(process.execPath, [
612+
'--experimental-config-file',
613+
fixtures.path('rc/invalid-schema-type.json'),
614+
'-p', '"Hello"',
615+
]);
616+
assert.match(result.stderr, /Invalid configuration/);
617+
assert.strictEqual(result.code, 9);
618+
});
618619

619-
test('process.versions.ata should be defined', async () => {
620-
const result = await spawnPromisified(process.execPath, [
621-
'-p', 'process.versions.ata',
622-
]);
623-
assert.match(result.stdout, /\d+\.\d+\.\d+/);
624-
assert.strictEqual(result.code, 0);
620+
test('rejects number option with string value', async () => {
621+
const result = await spawnPromisified(process.execPath, [
622+
'--experimental-config-file',
623+
fixtures.path('rc/invalid-schema-number-as-string.json'),
624+
'-p', '"Hello"',
625+
]);
626+
assert.match(result.stderr, /Invalid configuration/);
627+
assert.strictEqual(result.code, 9);
628+
});
629+
630+
test('rejects array option with boolean value', async () => {
631+
const result = await spawnPromisified(process.execPath, [
632+
'--experimental-config-file',
633+
fixtures.path('rc/invalid-schema-array-as-bool.json'),
634+
'-p', '"Hello"',
635+
]);
636+
assert.match(result.stderr, /Invalid configuration/);
637+
assert.strictEqual(result.code, 9);
638+
});
639+
640+
test('rejects array with wrong item type', async () => {
641+
const result = await spawnPromisified(process.execPath, [
642+
'--experimental-config-file',
643+
fixtures.path('rc/invalid-schema-nested-type.json'),
644+
'-p', '"Hello"',
645+
]);
646+
assert.match(result.stderr, /Invalid configuration/);
647+
assert.strictEqual(result.code, 9);
648+
});
649+
650+
test('accepts valid config with mixed types', async () => {
651+
const result = await spawnPromisified(process.execPath, [
652+
'--experimental-config-file',
653+
fixtures.path('rc/valid-schema-all-types.json'),
654+
'-e', 'process.exit(0)',
655+
]);
656+
assert.strictEqual(result.code, 0);
657+
});
658+
659+
test('accepts empty object config', async () => {
660+
const result = await spawnPromisified(process.execPath, [
661+
'--experimental-config-file',
662+
fixtures.path('rc/empty-object.json'),
663+
'-e', 'process.exit(0)',
664+
]);
665+
assert.strictEqual(result.code, 0);
666+
});
625667
});

0 commit comments

Comments
 (0)