import { describe, expect, test } from "vitest"; import manifest from "../src/manifest.json"; import { createManifest } from "../scripts/manifest.mjs"; describe("manifest", () => { test("injects the content script on the www Xingtu market page", () => { expect(manifest.content_scripts?.[0]?.matches).toEqual( expect.arrayContaining([ expect.stringMatching(/^https:\/\/(\*\.|www\.)?xingtu\.cn\/ad\/creator\/market\*$/) ]) ); expect(manifest.content_scripts?.[0]?.run_at).toBe("document_start"); }); test("declares the downloads and auth permissions plus background worker", () => { expect(manifest.permissions).toEqual( expect.arrayContaining(["downloads", "identity", "storage"]) ); expect(manifest.key).toBe( "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0CaZJxcX97TbRXCR08L10t9EZFV31+wPnUgDf21j2f0qYaWdblzWXfVkeU9jGb2Hr2Etpp7F/XuBa6pcipUXkzMMBkJ42KOkciAwbuzTBoAtGB8o9aoWigtax+gGfSz+T3BjqxKBJtXqeqbIAKCDIlxRKIrY+KcY1Z+mD5BKcBHKsUDQPlHsrjc1g0wIBD5doz9LoOk1Wso6gK5cSeOp9lw5YHcu4TImR4yqxGiL6pZwnpciuX/g7qjWBZXn5gf0YBlDsBDDTt5upbP3NguUKgO2qA9M77LyeUwXl3aqbIxYi/VwsQ2t5w9PGWtnOUQQDWUcEg/9dfTb89esZXKATwIDAQAB" ); expect(manifest.host_permissions).toEqual( expect.arrayContaining([ "http://*/*", "https://login-api.intelligrow.cn/*", "http://127.0.0.1:4319/*", "https://*/*" ]) ); expect(manifest.background?.service_worker).toBe("background/index.js"); expect(manifest.action?.default_popup).toBe("popup/index.html"); }); test("builds a release manifest with narrowed host permissions", () => { const releaseManifest = createManifest({ target: "release" }); expect(releaseManifest.permissions).toEqual( expect.arrayContaining(["downloads", "identity", "storage"]) ); expect(releaseManifest.host_permissions).toEqual([ "https://xingtu.cn/ad/creator/market*", "https://*.xingtu.cn/ad/creator/market*", "https://login-api.intelligrow.cn/*", "https://talent-search.intelligrow.cn/*", "http://192.168.31.21:8083/*" ]); expect(releaseManifest.host_permissions).not.toEqual( expect.arrayContaining(["http://*/*", "https://*/*", "http://127.0.0.1:4319/*"]) ); }); test("builds a release manifest with extension icons", () => { const releaseManifest = createManifest({ target: "release" }); expect(releaseManifest.icons).toEqual({ "16": "assets/icons/icon-16.png", "32": "assets/icons/icon-32.png", "48": "assets/icons/icon-48.png", "128": "assets/icons/icon-128.png" }); expect(releaseManifest.key).toBe(manifest.key); expect(releaseManifest.action?.default_icon).toEqual({ "16": "assets/icons/icon-16.png", "32": "assets/icons/icon-32.png" }); }); });