From 8fa3cf82a0b0b225ab5d873b7f30fc502c76151b Mon Sep 17 00:00:00 2001 From: gmegidish Date: Thu, 17 Sep 2026 15:26:35 +0200 Subject: [PATCH] fix: never auto-open the HTML report, document npm init mobilewright@latest - generated config uses reporter: [['html', { open: 'never' }]] so a failing first run doesn't serve the report and block the terminal - .gitignore also covers /mobilewright-report/ - README: npm init mobilewright@latest --- README.md | 2 +- src/project.ts | 4 +++- test/project.test.ts | 10 +++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ff66767..2b931b7 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Scaffold a [Mobilewright](https://mobilewright.dev) test project in seconds. ## Usage ```sh -npm init mobilewright +npm init mobilewright@latest ``` Also works with Yarn (`yarn create mobilewright`) and pnpm (`pnpm create mobilewright`). diff --git a/src/project.ts b/src/project.ts index fa7ca31..a4afd1d 100644 --- a/src/project.ts +++ b/src/project.ts @@ -157,7 +157,8 @@ export function createConfigContent({ language, testDir, platform, bundleId }: P ` testDir: ${literal(`./${testDir}`)},`, ` platform: ${literal(platform)},`, ...(bundleId ? [` bundleId: ${literal(bundleId)},`] : []), - " reporter: 'html',", + // open: 'never': otherwise a failing run in a terminal serves the report and blocks until Ctrl-C + " reporter: [['html', { open: 'never' }]],", "});", "", ]; @@ -200,6 +201,7 @@ export function patchGitignore(existing: string | undefined): string | undefined ["node_modules/", /^\/?node_modules\/?$/m], ["/test-results/", /^\/?test-results\/?$/m], ["/playwright-report/", /^\/?playwright-report\/?$/m], + ["/mobilewright-report/", /^\/?mobilewright-report\/?$/m], ]; const missing = entries.filter(([, pattern]) => !pattern.test(existing ?? "")).map(([entry]) => entry); if (missing.length === 0) return undefined; diff --git a/test/project.test.ts b/test/project.test.ts index d3e6d74..45d56dd 100644 --- a/test/project.test.ts +++ b/test/project.test.ts @@ -161,6 +161,10 @@ test("config: user input is escaped so it cannot break or inject code", () => { assert.match(config, /bundleId: "x'}\); require\('fs'\); \(\{a:'",/); }); +test("config: the HTML report never opens by itself, so a failing run doesn't block the terminal", () => { + assert.match(createConfigContent({ language: "ts", testDir: "tests", platform: "ios", bundleId: "" }), /reporter: \[\['html', \{ open: 'never' \}\]\],/); +}); + test("config: bundleId is omitted when left empty", () => { assert.doesNotMatch(createConfigContent({ language: "ts", testDir: "tests", platform: "ios", bundleId: "" }), /bundleId/); }); @@ -177,15 +181,15 @@ test("tsconfig: loads node types and includes the config and test directory", () }); test("gitignore: created when missing", () => { - assert.equal(patchGitignore(undefined), "# mobilewright\nnode_modules/\n/test-results/\n/playwright-report/\n"); + assert.equal(patchGitignore(undefined), "# mobilewright\nnode_modules/\n/test-results/\n/playwright-report/\n/mobilewright-report/\n"); }); test("gitignore: only missing entries are appended", () => { - assert.equal(patchGitignore("node_modules\n.env\n"), "node_modules\n.env\n\n# mobilewright\n/test-results/\n/playwright-report/\n"); + assert.equal(patchGitignore("node_modules\n.env\n"), "node_modules\n.env\n\n# mobilewright\n/test-results/\n/playwright-report/\n/mobilewright-report/\n"); }); test("gitignore: nothing to do when every entry exists", () => { - assert.equal(patchGitignore("node_modules/\ntest-results/\n/playwright-report\n"), undefined); + assert.equal(patchGitignore("node_modules/\ntest-results/\n/playwright-report\nmobilewright-report/\n"), undefined); }); test("test dir: plain projects use tests/", () => {