Prevent unknown keys in markdownOptions (#2073)

This commit is contained in:
Ian VanSchooten 2021-12-01 08:37:54 -08:00 committed by GitHub
parent ec35fdd768
commit ee4ad43202
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View file

@ -47,6 +47,7 @@ export const AstroConfigSchema = z.object({
gfm: z.boolean().optional(), gfm: z.boolean().optional(),
render: z.any().optional().default(['@astrojs/markdown-remark', {}]), render: z.any().optional().default(['@astrojs/markdown-remark', {}]),
}) })
.strict()
.optional() .optional()
.default({}), .default({}),
buildOptions: z buildOptions: z

View file

@ -13,6 +13,12 @@ describe('Config Validation', () => {
expect(configError instanceof z.ZodError).to.equal(true); expect(configError instanceof z.ZodError).to.equal(true);
}); });
it('errors when an older markdownOptions format is used', async () => {
const configError = await validateConfig({ markdownOptions: { rehypePlugins: ["rehype-autolink-headings"] } }, process.cwd()).catch((err) => err);
expect(configError instanceof z.ZodError).to.equal(true);
expect(configError.issues[0].message).to.equal("Unrecognized key(s) in object: 'rehypePlugins'")
});
it('A validation error can be formatted correctly', async () => { it('A validation error can be formatted correctly', async () => {
const configError = await validateConfig({ buildOptions: { sitemap: 42 } }, process.cwd()).catch((err) => err); const configError = await validateConfig({ buildOptions: { sitemap: 42 } }, process.cwd()).catch((err) => err);
expect(configError instanceof z.ZodError).to.equal(true); expect(configError instanceof z.ZodError).to.equal(true);