import { existsSync, rmSync } from "node:fs"; import { readFile, stat } from "node:fs/promises"; import { execFile } from "node:child_process"; import { promisify } from "node:util"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { beforeEach, describe, expect, test } from "vitest"; const execFileAsync = promisify(execFile); const __dirname = path.dirname(fileURLToPath(import.meta.url)); const projectRoot = path.resolve(__dirname, ".."); const distDir = path.join(projectRoot, "dist"); const manifestPath = path.join(projectRoot, "src", "manifest.json"); describe("build layout", () => { beforeEach(() => { rmSync(distDir, { force: true, recursive: true }); }); test("manifest exists and targets the creator detail and market pages", async () => { const raw = await readFile(manifestPath, "utf8"); const manifest = JSON.parse(raw); expect(manifest.manifest_version).toBe(3); expect(manifest.content_scripts).toEqual( expect.arrayContaining([ expect.objectContaining({ matches: [ "https://*.xingtu.cn/ad/creator/author-homepage/*", "https://*.xingtu.cn/ad/creator/market*" ] }) ]) ); expect(manifest.content_scripts[0].js).toEqual(["content/index.global.js"]); expect(manifest.web_accessible_resources[0].resources).toEqual([ "page/hook.global.js" ]); expect(manifest.web_accessible_resources[0].matches).toEqual([ "https://*.xingtu.cn/*" ]); }); test("build emits dist/manifest.json", async () => { await execFileAsync("node", ["scripts/build.mjs"], { cwd: projectRoot }); const output = path.join(distDir, "manifest.json"); expect(existsSync(output)).toBe(true); const fileInfo = await stat(output); expect(fileInfo.isFile()).toBe(true); }); });