native-sync-manifest-script.test.ts

1.7 KB · raw

1import { execFile } from "node:child_process";2import { promisify } from "node:util";3import { describe, expect, it } from "vitest";45const execFileAsync = promisify(execFile);6const scriptPath = "scripts/generate-native-sync-manifest.mjs";78describe("native sync manifest generator", () => {9  it("generates a Chrome native messaging host manifest", async () => {10    const { stdout } = await execFileAsync(process.execPath, [11      scriptPath,12      "--browser",13      "chrome",14      "--extension-id",15      "abcdefghijklmnopabcdefghijklmnop",16      "--host-path",17      "/opt/peach/peach-sync-host",18    ]);1920    expect(JSON.parse(stdout)).toEqual({21      name: "com.peachpasswords.sync",22      description: "Peach Sync native messaging host",23      path: "/opt/peach/peach-sync-host",24      type: "stdio",25      allowed_origins: ["chrome-extension://abcdefghijklmnopabcdefghijklmnop/"],26    });27  });2829  it("generates a Firefox native messaging host manifest using the Gecko id", async () => {30    const { stdout } = await execFileAsync(process.execPath, [31      scriptPath,32      "--browser",33      "firefox",34      "--host-path",35      "/opt/peach/peach-sync-host",36    ]);3738    expect(JSON.parse(stdout)).toEqual({39      name: "com.peachpasswords.sync",40      description: "Peach Sync native messaging host",41      path: "/opt/peach/peach-sync-host",42      type: "stdio",43      allowed_extensions: ["[email protected]"],44    });45  });4647  it("requires a Chrome extension id", async () => {48    await expect(49      execFileAsync(process.execPath, [scriptPath, "--browser", "chrome"], {50        env: { ...process.env, PEACH_CHROME_EXTENSION_ID: "" },51      })52    ).rejects.toThrow("--extension-id or PEACH_CHROME_EXTENSION_ID is required for Chrome");53  });54});