Skip to content

Commit 17aad4c

Browse files
committed
🧪 明确验证模式开关与示例契约
1 parent 1652362 commit 17aad4c

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

docs/references/verification-methods.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ From a session the same call is one command, since `eval` already runs on an ext
7777

7878
```bash
7979
node e2e/drive.mjs open options
80-
node e2e/drive.mjs eval "const r = await chrome.runtime.sendMessage({action:'serviceWorker/popup/getPopupData', data:{tabId, url}}); return r.data.scriptList"
80+
node e2e/drive.mjs eval "const [tab] = await chrome.tabs.query({active:true,lastFocusedWindow:true}); if (!tab?.id || !tab.url) throw new Error('no active tab'); const r = await chrome.runtime.sendMessage({action:'serviceWorker/popup/getPopupData', data:{tabId:tab.id, url:tab.url}}); return r.data.scriptList"
8181
```
8282

8383
This drives the real SW → content → sandbox → callback path, behaviourally identical to the popup button, which discards the DOM event and calls the same message. It is a substitution: the verdict row names it and says the popup's own click path was not covered.

e2e/fixtures.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ const chromeArgs = [
3232
* 必须作为启动参数下发:`--headless=new` 会覆盖 Playwright 的 `headless` 选项,
3333
* 所以单独把 `headless` 设成 false(含 `--debug`/PWDEBUG)并不会开出窗口。
3434
*/
35-
export function headlessArgs(): string[] {
36-
return process.env.E2E_HEADED ? [] : ["--headless=new"];
35+
export function headlessArgs(value = process.env.E2E_HEADED): string[] {
36+
const headed = /^(1|true|yes)$/i.test(value?.trim() ?? "");
37+
return headed ? [] : ["--headless=new"];
3738
}
3839

3940
// CI(GitHub Actions)跑在非 root 用户下不会自动应用 --no-sandbox,关掉沙箱能省下每次

tests/verification-tools.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, expect, it } from "vitest";
2+
import { headlessArgs } from "../e2e/fixtures";
3+
4+
describe("headlessArgs", () => {
5+
it.each([undefined, "", "0", "false", "no"])("keeps %j headless", (value) => {
6+
expect(headlessArgs(value)).toEqual(["--headless=new"]);
7+
});
8+
9+
it.each(["1", "true", "yes"])("enables headed mode for %j", (value) => {
10+
expect(headlessArgs(value)).toEqual([]);
11+
});
12+
});

0 commit comments

Comments
 (0)