46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
// @vitest-environment node
|
|||
|
|
import { execFileSync } from "node:child_process";
|
||
|
|
import { describe, expect, it } from "vitest";
|
||
|
|
|
||
|
|
// args에서 플래그만 지워도 Playwright 기본값이 sandbox를 끌 수 있다.
|
||
|
|
// 실제 설정을 새 프로세스로 읽어 환경변수 캐시와 개발자 환경에 영향받지 않는다.
|
||
|
|
function launchOptions(optIn?: string) {
|
||
|
|
const env: NodeJS.ProcessEnv = {
|
||
|
|
...process.env,
|
||
|
|
CHROME_PATH: "/usr/bin/google-chrome",
|
||
|
|
};
|
||
|
|
delete env.PLAYWRIGHT_NO_SANDBOX;
|
||
|
|
if (optIn !== undefined) env.PLAYWRIGHT_NO_SANDBOX = optIn;
|
||
|
|
return JSON.parse(
|
||
|
|
execFileSync(
|
||
|
|
process.execPath,
|
||
|
|
[
|
||
|
|
"--experimental-strip-types",
|
||
|
|
"--input-type=module",
|
||
|
|
"-e",
|
||
|
|
"import config from './playwright.config.ts'; console.log(JSON.stringify(config.use.launchOptions));",
|
||
|
|
],
|
||
|
|
{ encoding: "utf8", env },
|
||
|
|
),
|
||
|
|
) as {
|
||
|
|
chromiumSandbox?: boolean;
|
||
|
|
args?: string[];
|
||
|
|
executablePath?: string;
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
describe("브라우저 sandbox 기본 정책", () => {
|
||
|
|
it.each([undefined, "", "0", "false"])(
|
||
|
|
"opt-in=%s이면 sandbox를 켠다",
|
||
|
|
(value) => {
|
||
|
|
const options = launchOptions(value);
|
||
|
|
expect.soft(options.chromiumSandbox).toBe(true);
|
||
|
|
expect.soft(options.args ?? []).not.toContain("--no-sandbox");
|
||
|
|
expect(options.executablePath).toBe("/usr/bin/google-chrome");
|
||
|
|
},
|
||
|
|
);
|
||
|
|
it("명시적인 PLAYWRIGHT_NO_SANDBOX=1에서만 sandbox를 끈다", () => {
|
||
|
|
expect(launchOptions("1").chromiumSandbox).toBe(false);
|
||
|
|
});
|
||
|
|
});
|