// @vitest-environment node import path from "node:path"; import { beforeAll, describe, expect, test } from "vitest"; import { createSecurityLinter, PROTECTED_RULES } from "./security.mjs"; // The same linter `pnpm lint:security` runs: protected rules only, inline config ignored. const eslint = createSecurityLinter(path.resolve(__dirname, "..")); async function securityErrors(code: string, filePath: string): Promise { const [result] = await eslint.lintText(code, { filePath }); return result!.messages .filter(message => message.ruleId && PROTECTED_RULES.has(message.ruleId)) .map(message => message.ruleId!); } const vue = (template: string, script = "const x = \"\";") => `\n\n\n`; const COMPONENT = "app/components/Domain/Foo.vue"; const SCRIPT = "app/composables/foo.ts"; describe("raw HTML lint rules", () => { // The first lint loads the whole Nuxt config and its parsers. beforeAll(() => securityErrors(vue("
"), "app/components/Domain/Warmup.vue"), 60_000); test("flags v-html in an ordinary component", async () => { expect(await securityErrors(vue("
"), COMPONENT)).toEqual(["vue/no-v-html"]); }); test.each(["SafeMarkdown.vue", "SafeInlineHtml.vue"])("allows v-html in %s", async (file) => { expect(await securityErrors(vue(""), `app/components/global/${file}`)).toEqual([]); }); test.each([ [":innerHTML", "
", "vue/no-restricted-v-bind"], [":srcdoc", "