Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/void/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
{
"type": "object",
"patternProperties": {
"^(/|\\*)": {
"^(\\/|\\*$)": {
"type": "number",
"minimum": 0
}
Expand Down
16 changes: 16 additions & 0 deletions packages/void/test/unit/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,22 @@ describe('readConfig redirects', () => {
expect(new Set(schemaEnum)).toEqual(VALID_REDIRECT_STATUSES);
});

it('schema.json revalidate key pattern matches runtime validation', () => {
const schema = JSON.parse(readFileSync(join(import.meta.dirname, '../../schema.json'), 'utf8'));
const objectForm = schema.properties.routing.properties.revalidate.oneOf.find(
(s: { type?: string }) => s.type === 'object',
);
const keyPattern = new RegExp(Object.keys(objectForm.patternProperties)[0]);

// Runtime (config.ts) accepts a key that is exactly "*" or starts with "/".
for (const key of ['*', '/x', '/docs/*']) {
expect(keyPattern.test(key)).toBe(true);
}
for (const key of ['*foo', '**', '*/', 'foo']) {
expect(keyPattern.test(key)).toBe(false);
}
});

it('schema.json sourceDir pattern matches runtime validation', () => {
const schema = JSON.parse(readFileSync(join(import.meta.dirname, '../../schema.json'), 'utf8'));
const sourceDirPattern = new RegExp(schema.properties.sourceDir.pattern);
Expand Down