Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down
4 changes: 3 additions & 1 deletion src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }]],",
"});",
"",
];
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions test/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
});
Expand All @@ -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/", () => {
Expand Down