@shyden-labs/playwright-devices 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,3 @@
1
+ Copyright 2026 Shyden Labs
2
+
3
+ This product is licensed under the Apache License, Version 2.0; see LICENSE.
package/README.md CHANGED
@@ -1,3 +1,81 @@
1
- # Temporary Holding Version
1
+ # Playwright Devices
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Research into running one unchanged Playwright test on real phones, their simulators and
4
+ emulators, and desktop browsers, with real input.
5
+
6
+ **Progress:** [Playwright Devices progress page](https://claude.ai/artifact/A7uCrNS5QTmstQ3SCGU2ES),
7
+ updated at the end of every work session.
8
+
9
+ This repository started from the Shyden Labs repo template: CI and repository settings were
10
+ in place from day one (shyden-labs/repo-template#149).
11
+
12
+ ## What is here
13
+
14
+ | File | What it does |
15
+ | --- | --- |
16
+ | `.github/workflows/ci.yml` | On every pull request and every push to `develop`: install, `node scripts/audit.ts` (`npm audit`: any known vulnerability fails, except one with a dated exception in that script), typecheck, lint, format check and unit tests (`build-and-test`), then coverage as one overall threshold over the TypeScript under `scripts/` (`coverage`). Its first step fails unless the default branch is `develop`. |
17
+ | `.github/dependabot.yml` | Version updates for npm, GitHub Actions and the Node pin, each targeting `develop`. |
18
+ | `docker/node/Dockerfile` | CI's one exact Node version (`FROM node:<major>.<minor>.<patch>`, then `USER node` so it never runs as root), bumped by Dependabot as a pull request of its own (shyden-labs/repo-template#143). |
19
+ | `scripts/npm-ci.ts` | Every workflow installs through it: `npm ci` that fails on any warning npm prints, naming each line (shyden-labs/repo-template#140). |
20
+ | `.github/workflows/sonarcloud.yml`, `scripts/sonar-verdict.ts`, `docs/sonarcloud.md` | A reusable SonarCloud scan whose quality gate blocks the pull request. |
21
+ | `.github/workflows/publish.yml` | Publishes the package to npm when a release is published, through npm trusted publishing (no stored token), after Shyden approves the `npm` environment (shyden-labs/playwright-devices#16). |
22
+ | `.github/workflows/check-release-cut.yml`, `scripts/release-cut.ts`, `docs/release-cut.md` | Proves each pull request into `main` lands exactly a release cut CI tested. |
23
+ | `scripts/branch-rules-setup.ts` | Sets the `develop` (squash only) and `main` (merge commit only) rulesets, head-branch deletion, rebase merging off and opens the `dev` environment to every branch (any branch may deploy to dev), and reads each back. |
24
+ | `scripts/board-*.ts`, `scripts/file-story.ts`, `.github/ISSUE_TEMPLATE/story.yml`, `docs/project-board.md` | The project board: filing stories, Estimate and Priority fields, the next ticket, progress, and orphaned In Progress tickets. |
25
+ | `tests/unit/supply-chain.test.ts` | Actions pinned to SHAs, Dependabot covering every ecosystem and targeting `develop`, Node read from the Dockerfile. |
26
+ | `tests/unit/licences.test.ts`, `tests/unit/licences.ts` | Every package in `package-lock.json` has a licence the global rule accepts: permissive if shipped, LGPL or MPL also allowed for build and test tools, GPL, AGPL, SSPL and unknown refused (shyden-labs/repo-template#169). |
27
+ | `tsconfig.json`, `eslint.config.js`, `.prettierrc.json`, `.githooks/pre-push`, `docs/static-checks.md` | Strict typecheck, lint and format, in CI and before every push. |
28
+ | `package.json` `overrides` | `minimatch` held at 11.0.3, past its ReDoS advisory GHSA-g3hv-75wg-m249, until eslint and typescript-eslint accept minimatch 11 themselves; then remove it (shyden-labs/repo-template#154). |
29
+ | `LICENSE`, `NOTICE` | Apache-2.0, the ASF's text verbatim in `LICENSE`; the copyright line in `NOTICE`, as the ASF advises (shyden-labs/repo-template#147). |
30
+
31
+ ## Desktop browsers
32
+
33
+ `src/desktop/browsers.ts` (`@shyden-labs/playwright-devices/desktop` once installed, below) gives every project the same desktop browsers as Playwright projects (shyden-labs/playwright-devices#17): `chromium`, `chrome` (Google Chrome, the `chrome` channel), `firefox`, `webkit` and `msedge` (Microsoft Edge, the `msedge` channel). Each is a real desktop browser: no phone emulation, no touch. A project imports it into its `playwright.config.ts`:
34
+
35
+ ```ts
36
+ import { defineConfig } from '@playwright/test';
37
+ import { desktopProjects } from '@shyden-labs/playwright-devices/desktop';
38
+
39
+ export default defineConfig({
40
+ forbidOnly: true,
41
+ retries: 0,
42
+ reporter: [['list'], ['json', { outputFile: 'test-results/desktop-report.json' }]],
43
+ projects: desktopProjects(), // or a declared few, e.g. desktopProjects(['chromium', 'chrome', 'msedge'])
44
+ });
45
+ ```
46
+
47
+ `playwright.desktop.config.ts` is this sample, run by CI's `desktop-e2e` job on all five browsers. The same names form the desktop group of the one-suite checks: `desktopGroup()` (or `desktopGroup(['chromium', 'chrome', 'msedge'])` for a declared few) is the `groups` value `checkOneSuite` takes, and on the CLI it is `--group desktop=chromium,chrome,firefox,webkit,msedge`. An unknown or repeated browser name is refused, naming it. A browser that cannot start fails the run, naming it and why (Playwright's launch error), and is never dropped from the group: the checks report it as having run no tests. Install the browsers with `npx playwright install --with-deps chromium chrome firefox webkit msedge`.
48
+
49
+ ## Installing it in a project
50
+
51
+ The one-suite checks (shyden-labs/playwright-devices#16) and the desktop browsers are published to npm as `@shyden-labs/playwright-devices`, compiled to JavaScript with their types.
52
+
53
+ 1. `npm install --save-dev --save-exact @shyden-labs/playwright-devices`. It needs `@playwright/test` 1.65.1 or later in the project, and runs no install script.
54
+ 2. Count each test's assertions per target with the reporter, next to the JSON reporter: `reporter: [['json'], ['@shyden-labs/playwright-devices/assertion-counter', { outputFile: '<target>-assertions.json', unnamedTarget: '<target>' }]]` (`unnamedTarget` names a run whose project has no name, such as a device run).
55
+ 3. Check the runs: `npx one-suite --group phones=<targets> --group desktop=<targets> --list <list.json>[=<target>] --report <report.json>[=<target>] --assertions <assertions.json>`. It prints one total per target and every problem, and exits 1 on any problem.
56
+ 4. In code: `import { checkOneSuite, testsByTarget } from '@shyden-labs/playwright-devices'`, and `desktopProjects` and `desktopGroup` from `@shyden-labs/playwright-devices/desktop`.
57
+
58
+ ### Publishing a version
59
+
60
+ 1. Raise `version` in `package.json` on a branch, and merge it through `develop` and a release cut into `main`.
61
+ 2. Publish a GitHub release on `main` tagged `v<version>`. `.github/workflows/publish.yml` checks the tag matches, builds, and publishes to npm once Shyden approves the `npm` environment. It uses npm trusted publishing, so no npm token is stored, and npm attaches provenance.
62
+
63
+ ## The rules
64
+
65
+ 1. **Pin actions to full commit SHAs**, with a trailing `# vX.Y.Z` comment so a Dependabot bump is reviewable.
66
+ 2. **Dependabot covers every ecosystem and `github-actions`, targeting `develop`.**
67
+ 3. **`develop` is the default branch**, because GitHub opens Dependabot security fixes against the default branch only.
68
+ 4. **Warnings are build failures**: a vite or node warning fails the unit run.
69
+ 5. **A unit test runs in under 1 s and starts no process and opens no connection** (`tests/setup/unit-refusal.ts`).
70
+ 6. **Comments and docs cite issues in full**, as `owner/repo#N`, never a bare `#N` (`tests/unit/issue-refs.test.ts`; shyden-labs/repo-template#146). A repository made from this template copies every file, so a template reference such as `shyden-labs/repo-template#115` keeps pointing at the template's issue, and the new repository cites its own issues the same way. Test titles and messages are strings and are left as they are.
71
+
72
+ ## Using it
73
+
74
+ 1. `gh repo create <name> --public --template shyden-labs/repo-template`. A repo carrying game, art or learning content adds its own content licence.
75
+ 2. Create `develop` and make it the default branch before Dependabot first runs. CI fails until this is done.
76
+ 3. Set up SonarCloud as `docs/sonarcloud.md` describes (CI fails until `SONAR_TOKEN` is set). Then, as the operator, set the branch rules: `node scripts/branch-rules-setup.ts <owner/repo> build-and-test coverage "sonarcloud / sonarcloud"`, and add any check the project adds later.
77
+ 4. Add the ecosystems your repo uses to `.github/dependabot.yml`, and enable Dependabot alerts and security updates.
78
+ 5. `npm ci && npm run test:unit`.
79
+ 6. Set up the project board as `docs/project-board.md` describes.
80
+ 7. The template's dev-deploy stub was removed: this package hosts nothing, so there is no dev environment to deploy to (shyden-labs/playwright-devices#9).
81
+ 8. Turn on SonarCloud as `docs/sonarcloud.md` describes.
@@ -0,0 +1,5 @@
1
+ export interface Proc {
2
+ argv: string[];
3
+ exit(code: number): void;
4
+ }
5
+ export declare function runIfEntry(moduleUrl: string, main: (args: string[]) => number | Promise<number>, proc?: Proc): Promise<void>;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Runs a script's `main` when that script is the program node started, and
3
+ * does nothing when a test imports it. Every script's entry goes through here,
4
+ * so the started-or-imported branch is tested once, in-process, and each
5
+ * script's own last line always runs (issue shyden-labs/repo-template#32).
6
+ *
7
+ * await runIfEntry(import.meta.url, main);
8
+ *
9
+ * The call is awaited at the top of the module, so an error thrown by `main`
10
+ * rejects the module and node prints it and exits 1.
11
+ */
12
+ import { existsSync, realpathSync } from 'node:fs';
13
+ import { pathToFileURL } from 'node:url';
14
+ export async function runIfEntry(moduleUrl, main, proc = process) {
15
+ const program = proc.argv[1];
16
+ if (program === undefined)
17
+ return;
18
+ // An installed bin starts through a symlink (node_modules/.bin/<name>): node gives the link as
19
+ // argv[1] but the real file as import.meta.url, so the link is resolved before comparing.
20
+ const started = existsSync(program) ? realpathSync(program) : program;
21
+ if (moduleUrl !== pathToFileURL(started).href)
22
+ return;
23
+ // An async main (one that reads over HTTP) is waited for; its rejection is left to node, which prints it and exits 1.
24
+ proc.exit(await main(proc.argv.slice(2)));
25
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The shared desktop-browser setup (shyden-labs/playwright-devices#17): the same desktop browsers,
3
+ * set up the same way, for every project's Playwright config. Each is a real desktop browser
4
+ * (Playwright's desktop descriptors: no phone emulation, no touch); Chrome and Edge are the
5
+ * installed browsers through their channels. A project may declare a few of them; the same names
6
+ * are the desktop group of the one-suite checks (shyden-labs/playwright-devices#16).
7
+ */
8
+ import { type PlaywrightTestProject } from '@playwright/test';
9
+ export declare const DESKTOP_BROWSERS: readonly ["chromium", "chrome", "firefox", "webkit", "msedge"];
10
+ export type DesktopBrowser = (typeof DESKTOP_BROWSERS)[number];
11
+ /** Playwright projects for the chosen desktop browsers (all five by default), in the order given. */
12
+ export declare function desktopProjects(browsers?: readonly string[]): PlaywrightTestProject[];
13
+ /** The desktop group for `checkOneSuite`'s `groups`: the chosen browsers' project names. */
14
+ export declare function desktopGroup(browsers?: readonly string[]): {
15
+ desktop: string[];
16
+ };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The shared desktop-browser setup (shyden-labs/playwright-devices#17): the same desktop browsers,
3
+ * set up the same way, for every project's Playwright config. Each is a real desktop browser
4
+ * (Playwright's desktop descriptors: no phone emulation, no touch); Chrome and Edge are the
5
+ * installed browsers through their channels. A project may declare a few of them; the same names
6
+ * are the desktop group of the one-suite checks (shyden-labs/playwright-devices#16).
7
+ */
8
+ import { devices } from '@playwright/test';
9
+ export const DESKTOP_BROWSERS = ['chromium', 'chrome', 'firefox', 'webkit', 'msedge'];
10
+ const USE = {
11
+ chromium: { ...devices['Desktop Chrome'] },
12
+ chrome: { ...devices['Desktop Chrome'], channel: 'chrome' },
13
+ firefox: { ...devices['Desktop Firefox'] },
14
+ webkit: { ...devices['Desktop Safari'] },
15
+ msedge: { ...devices['Desktop Edge'], channel: 'msedge' },
16
+ };
17
+ function isDesktopBrowser(name) {
18
+ return DESKTOP_BROWSERS.includes(name);
19
+ }
20
+ /** The chosen browsers, checked: known, each once, at least one. */
21
+ function chosen(browsers) {
22
+ if (browsers.length === 0)
23
+ throw new Error('choose at least one desktop browser');
24
+ const seen = new Set();
25
+ return browsers.map((name) => {
26
+ if (!isDesktopBrowser(name))
27
+ throw new Error(`unknown desktop browser "${name}"; known: ${DESKTOP_BROWSERS.join(', ')}`);
28
+ if (seen.has(name))
29
+ throw new Error(`desktop browser "${name}" is named twice`);
30
+ seen.add(name);
31
+ return name;
32
+ });
33
+ }
34
+ /** Playwright projects for the chosen desktop browsers (all five by default), in the order given. */
35
+ export function desktopProjects(browsers = DESKTOP_BROWSERS) {
36
+ return chosen(browsers).map((name) => ({ name, use: USE[name] }));
37
+ }
38
+ /** The desktop group for `checkOneSuite`'s `groups`: the chosen browsers' project names. */
39
+ export function desktopGroup(browsers = DESKTOP_BROWSERS) {
40
+ return { desktop: chosen(browsers) };
41
+ }
@@ -0,0 +1,18 @@
1
+ import type { Reporter, TestCase, TestResult, TestStep } from '@playwright/test/reporter';
2
+ export interface AssertionCounterOptions {
3
+ outputFile: string;
4
+ unnamedTarget: string;
5
+ }
6
+ export type WriteFile = (file: string, body: string) => void;
7
+ export declare class AssertionCounter implements Reporter {
8
+ private readonly counts;
9
+ private readonly options;
10
+ private readonly write;
11
+ constructor(options: AssertionCounterOptions, write?: WriteFile);
12
+ private entry;
13
+ onTestEnd(test: TestCase): void;
14
+ onStepEnd(test: TestCase, _result: TestResult, step: TestStep): void;
15
+ onEnd(): void;
16
+ printsToStdio(): boolean;
17
+ }
18
+ export default AssertionCounter;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * A Playwright reporter counting the `expect` assertions each test ran, per target, failed ones
3
+ * included (shyden-labs/playwright-devices#16 AC 5). Playwright's JSON report does not record
4
+ * expect steps, so a test that checks less on one target than another would otherwise pass unseen.
5
+ *
6
+ * reporter: [['@shyden-labs/playwright-devices/assertion-counter', { outputFile: 'assertions.json', unnamedTarget: 'ios-webkit' }]]
7
+ *
8
+ * The file maps each target to each test's count: { "<target>": { "<file> › <title path>": n } }.
9
+ * `unnamedTarget` names a run whose project has no name (a device run).
10
+ */
11
+ import { writeFileSync } from 'node:fs';
12
+ export class AssertionCounter {
13
+ counts = new Map();
14
+ options;
15
+ write;
16
+ constructor(options, write = writeFileSync) {
17
+ if (typeof options.outputFile !== 'string' || options.outputFile === '')
18
+ throw new Error('AssertionCounter needs an outputFile option');
19
+ this.options = options;
20
+ this.write = write;
21
+ }
22
+ entry(test) {
23
+ const [, project = '', ...path] = test.titlePath();
24
+ const name = project === '' ? this.options.unnamedTarget : project;
25
+ const target = this.counts.get(name) ?? new Map();
26
+ this.counts.set(name, target);
27
+ return { target, id: path.join(' › ') };
28
+ }
29
+ onTestEnd(test) {
30
+ const { target, id } = this.entry(test);
31
+ target.set(id, target.get(id) ?? 0);
32
+ }
33
+ onStepEnd(test, _result, step) {
34
+ if (step.category !== 'expect')
35
+ return;
36
+ const { target, id } = this.entry(test);
37
+ target.set(id, (target.get(id) ?? 0) + 1);
38
+ }
39
+ onEnd() {
40
+ const json = Object.fromEntries([...this.counts].map(([target, tests]) => [target, Object.fromEntries(tests)]));
41
+ this.write(this.options.outputFile, `${JSON.stringify(json, null, 2)}\n`);
42
+ }
43
+ printsToStdio() {
44
+ return false;
45
+ }
46
+ }
47
+ export default AssertionCounter;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * The shared one-suite checks (shyden-labs/playwright-devices#16): every target in a group runs the
3
+ * same tests, the full list read from the spec files, with nothing skipped, failed or flaky, and a
4
+ * test that belongs to one group only says so with a tag and a reason. Every problem is listed, one
5
+ * line each; the checks never stop at the first.
6
+ *
7
+ * Input is Playwright's own output: `--list --reporter=json` reports give what each target should
8
+ * run, and JSON reports give what it ran. Phones and desktop browsers run separately, so each may be
9
+ * its own report; a report with no project names (a device run) is named by the caller.
10
+ */
11
+ import type { JSONReport, JSONReportTest } from '@playwright/test/reporter';
12
+ export interface ReportedTest {
13
+ /** The file and the whole title path, e.g. "journey.spec.ts › outer › reads". */
14
+ id: string;
15
+ tags: string[];
16
+ annotations: {
17
+ type: string;
18
+ description?: string;
19
+ }[];
20
+ status: JSONReportTest['status'];
21
+ }
22
+ export interface TargetTests {
23
+ tests: ReportedTest[];
24
+ }
25
+ export interface OneSuiteInput {
26
+ /** What each target should run, from `playwright test --list --reporter=json`. */
27
+ listed: Map<string, TargetTests>;
28
+ /** What each target ran, from its JSON report. */
29
+ ran: Map<string, TargetTests>;
30
+ /** Each group's targets, e.g. { phones: ['ios-webkit'], desktop: ['chromium', 'firefox'] }. */
31
+ groups: Record<string, string[]>;
32
+ /** Each target's expect count per test, from the AssertionCounter reporter; checked when given. */
33
+ assertions?: Record<string, Record<string, number>>;
34
+ }
35
+ export interface OneSuiteResult {
36
+ /** One line per target, on pass and on fail. */
37
+ totals: string[];
38
+ problems: string[];
39
+ }
40
+ /** Every test in a report, by target: its project name, or `unnamedTarget` for a project with none. */
41
+ export declare function testsByTarget(report: JSONReport, unnamedTarget: string): Map<string, TargetTests>;
42
+ export declare function checkOneSuite({ listed, ran, groups, assertions }: OneSuiteInput): OneSuiteResult;
@@ -0,0 +1,138 @@
1
+ /** Every test in a report, by target: its project name, or `unnamedTarget` for a project with none. */
2
+ export function testsByTarget(report, unnamedTarget) {
3
+ const targets = new Map();
4
+ const visit = (suite, path) => {
5
+ for (const spec of suite.specs) {
6
+ for (const test of spec.tests) {
7
+ const target = test.projectName === '' ? unnamedTarget : test.projectName;
8
+ const entry = targets.get(target) ?? { tests: [] };
9
+ entry.tests.push({ id: [...path, spec.title].join(' › '), tags: spec.tags, annotations: test.annotations, status: test.status });
10
+ targets.set(target, entry);
11
+ }
12
+ }
13
+ for (const child of suite.suites ?? [])
14
+ visit(child, [...path, child.title]);
15
+ };
16
+ for (const file of report.suites)
17
+ visit(file, [file.file]);
18
+ return targets;
19
+ }
20
+ const ids = (target) => new Set(target?.tests.map((t) => t.id));
21
+ /** What one target ran against what was listed for it: missing, extra, skipped, failed and flaky tests. */
22
+ function runProblems(target, expected, run) {
23
+ const problems = [];
24
+ const listedIds = ids(expected);
25
+ const ranIds = ids(run);
26
+ for (const id of listedIds)
27
+ if (!ranIds.has(id))
28
+ problems.push(`${target} did not run "${id}" (listed for it)`);
29
+ const byStatus = {
30
+ skipped: (id) => `${target} skipped "${id}"`,
31
+ unexpected: (id) => `${target} failed "${id}"`,
32
+ flaky: (id) => `${target} was flaky on "${id}" (it needed a retry)`,
33
+ };
34
+ for (const test of run.tests) {
35
+ const reportStatus = byStatus[test.status];
36
+ if (!listedIds.has(test.id))
37
+ problems.push(`${target} ran "${test.id}", which is not listed for it`);
38
+ else if (reportStatus !== undefined)
39
+ problems.push(reportStatus(test.id));
40
+ }
41
+ return problems;
42
+ }
43
+ /** The targets of one group: listed alike, each with a total, each run held to its list. */
44
+ function groupProblems(group, targets, listed, ran, totals) {
45
+ const problems = [];
46
+ const withList = targets.filter((t) => listed.has(t));
47
+ const sets = withList.map((t) => [...ids(listed.get(t))].sort((x, y) => x.localeCompare(y)).join('\n'));
48
+ if (new Set(sets).size > 1) {
49
+ const listedTotals = withList.map((t) => `${t} ${String(ids(listed.get(t)).size)}`).join(', ');
50
+ problems.push(`the ${group} group is listed different tests: ${listedTotals}`);
51
+ }
52
+ for (const target of targets) {
53
+ const expected = listed.get(target);
54
+ if (expected === undefined) {
55
+ problems.push(`${target} has no listed tests: pass its --list report`);
56
+ continue;
57
+ }
58
+ const run = ran.get(target);
59
+ totals.push(`${target}: ${String(run?.tests.length ?? 0)} tests`);
60
+ if (run === undefined || run.tests.length === 0)
61
+ problems.push(`${target} ran no tests (it is in the ${group} group)`);
62
+ else
63
+ problems.push(...runProblems(target, expected, run));
64
+ }
65
+ return problems;
66
+ }
67
+ export function checkOneSuite({ listed, ran, groups, assertions }) {
68
+ const totals = [];
69
+ const declared = new Set(Object.values(groups).flat());
70
+ const problems = [...new Set([...listed.keys(), ...ran.keys()])]
71
+ .filter((t) => !declared.has(t))
72
+ .map((t) => `${t} is in no declared group`);
73
+ for (const [group, targets] of Object.entries(groups))
74
+ problems.push(...groupProblems(group, targets, listed, ran, totals));
75
+ problems.push(...groupOnlyProblems(listed, groups));
76
+ if (assertions !== undefined)
77
+ problems.push(...assertionProblems(listed, groups, assertions));
78
+ return { totals, problems };
79
+ }
80
+ /** Each listed test must have counted the same number of assertions on every target in its group. */
81
+ function assertionProblems(listed, groups, assertions) {
82
+ const problems = [];
83
+ for (const [group, targets] of Object.entries(groups)) {
84
+ const testIds = new Set(targets.flatMap((target) => [...ids(listed.get(target))]));
85
+ for (const id of testIds) {
86
+ const counted = [];
87
+ for (const target of targets.filter((t) => ids(listed.get(t)).has(id))) {
88
+ const count = assertions[target]?.[id];
89
+ if (count === undefined)
90
+ problems.push(`${target} counted no assertions for "${id}": pass its --assertions file`);
91
+ else
92
+ counted.push([target, count]);
93
+ }
94
+ if (new Set(counted.map(([, count]) => count)).size > 1) {
95
+ const each = counted.map(([target, count]) => `${target} ${String(count)}`).join(', ');
96
+ problems.push(`assertions in "${id}" differ in the ${group} group: ${each}`);
97
+ }
98
+ }
99
+ }
100
+ return problems;
101
+ }
102
+ /** Each listed test with the groups it is listed for. */
103
+ function testsWithGroups(listed, groups) {
104
+ const byId = new Map();
105
+ for (const [group, targets] of Object.entries(groups)) {
106
+ for (const test of targets.flatMap((target) => listed.get(target)?.tests ?? [])) {
107
+ const entry = byId.get(test.id) ?? { test, groups: new Set() };
108
+ entry.groups.add(group);
109
+ byId.set(test.id, entry);
110
+ }
111
+ }
112
+ return byId;
113
+ }
114
+ /** One test's group-only problems. */
115
+ function groupOnlyProblemsOf(id, test, inGroups, all) {
116
+ const tagged = all.filter((group) => test.tags.includes(`@${group}`));
117
+ if (tagged.length === 0) {
118
+ if (inGroups.size === all.length)
119
+ return [];
120
+ return [...inGroups].map((group) => `"${id}" runs in the ${group} group only but has no @${group} tag with a group-only reason`);
121
+ }
122
+ const reason = test.annotations.find((a) => a.type === 'group-only')?.description?.trim() ?? '';
123
+ return tagged.flatMap((group) => [
124
+ ...(reason === '' ? [`"${id}" is tagged @${group} but gives no group-only reason (annotation type "group-only")`] : []),
125
+ ...all
126
+ .filter((other) => other !== group && inGroups.has(other))
127
+ .map((other) => `"${id}" is tagged @${group} but is also listed for the ${other} group`),
128
+ ]);
129
+ }
130
+ /**
131
+ * A test listed for one group's targets and none of another's must carry that group's tag
132
+ * (`@<group>`) and a one-line reason (annotation type "group-only"); a tagged test must not be
133
+ * listed for any other group.
134
+ */
135
+ function groupOnlyProblems(listed, groups) {
136
+ const all = Object.keys(groups);
137
+ return [...testsWithGroups(listed, groups)].flatMap(([id, { test, groups: inGroups }]) => groupOnlyProblemsOf(id, test, inGroups, all));
138
+ }
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ export interface NamedFile {
3
+ file: string;
4
+ /** The target for a project with no name; empty when the file's projects are named. */
5
+ target: string;
6
+ }
7
+ export interface Args {
8
+ lists: NamedFile[];
9
+ reports: NamedFile[];
10
+ assertions: string[];
11
+ groups: Record<string, string[]>;
12
+ }
13
+ export interface Io {
14
+ read: (file: string) => string;
15
+ log: (line: string) => void;
16
+ error: (line: string) => void;
17
+ }
18
+ export declare function parseArgs(argv: string[]): Args;
19
+ export declare const defaultIo: Io;
20
+ export declare function main(argv: string[], io?: Io): number;
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The one-suite checks from the command line (shyden-labs/playwright-devices#16 AC 7):
4
+ *
5
+ * one-suite --group phones=ios-webkit,android-cdp --group desktop=chromium,firefox,webkit,msedge \
6
+ * --list desktop-list.json --list ios-list.json=ios-webkit --list android-list.json=android-cdp \
7
+ * --report desktop.json --report ios.json=ios-webkit --report android.json=android-cdp \
8
+ * [--assertions desktop-assertions.json --assertions ios-assertions.json ...]
9
+ *
10
+ * `--list` takes `playwright test --list --reporter=json` output and `--report` a JSON report; a
11
+ * `=target` suffix names a file whose project has no name (a device run). Prints one total per
12
+ * target, then every problem, and exits 1 on any problem.
13
+ */
14
+ import { readFileSync } from 'node:fs';
15
+ import { runIfEntry } from "../../scripts/cli.js";
16
+ import { checkOneSuite, testsByTarget } from "./check.js";
17
+ const USAGE = 'usage: one-suite --group <name>=<target>,... --list <file>[=<target>] --report <file>[=<target>] [--assertions <file>]';
18
+ const FLAGS = new Set(['--list', '--report', '--assertions', '--group']);
19
+ /** Adds one flag's value to the arguments read so far. */
20
+ function addArg(args, flag, value) {
21
+ const [left = '', right = ''] = value.split('=');
22
+ if (flag === '--group') {
23
+ const targets = right.split(',').filter((t) => t !== '');
24
+ if (left === '' || targets.length === 0)
25
+ throw new Error(`--group needs name=target,target: "${value}"`);
26
+ args.groups[left] = targets;
27
+ }
28
+ else if (flag === '--assertions')
29
+ args.assertions.push(value);
30
+ else
31
+ (flag === '--list' ? args.lists : args.reports).push({ file: left, target: right });
32
+ }
33
+ export function parseArgs(argv) {
34
+ const args = { lists: [], reports: [], assertions: [], groups: {} };
35
+ for (let i = 0; i < argv.length; i += 2) {
36
+ const flag = String(argv[i]);
37
+ const value = argv[i + 1];
38
+ if (!FLAGS.has(flag))
39
+ throw new Error(`unknown argument "${flag}"`);
40
+ if (value === undefined)
41
+ throw new Error(`${flag} needs a value`);
42
+ addArg(args, flag, value);
43
+ }
44
+ if (Object.keys(args.groups).length === 0 || args.lists.length === 0 || args.reports.length === 0)
45
+ throw new Error(USAGE);
46
+ return args;
47
+ }
48
+ export const defaultIo = { read: (file) => readFileSync(file, 'utf8'), log: console.log, error: console.error };
49
+ const messageOf = (error) => (error instanceof Error ? error.message : String(error));
50
+ function readJson(io, file) {
51
+ try {
52
+ return JSON.parse(io.read(file));
53
+ }
54
+ catch (error) {
55
+ throw new Error(`cannot read ${file}: ${messageOf(error)}`, { cause: error });
56
+ }
57
+ }
58
+ function targetsOf(io, files) {
59
+ return new Map(files.flatMap(({ file, target }) => [...testsByTarget(readJson(io, file), target)]));
60
+ }
61
+ export function main(argv, io = defaultIo) {
62
+ try {
63
+ const args = parseArgs(argv);
64
+ const listed = targetsOf(io, args.lists);
65
+ const ran = targetsOf(io, args.reports);
66
+ const assertions = args.assertions.length === 0
67
+ ? undefined
68
+ : Object.assign({}, ...args.assertions.map((file) => readJson(io, file)));
69
+ const { totals, problems } = checkOneSuite({ listed, ran, groups: args.groups, ...(assertions === undefined ? {} : { assertions }) });
70
+ for (const line of totals)
71
+ io.log(`one-suite: ${line}`);
72
+ for (const line of problems)
73
+ io.error(`one-suite: ${line}`);
74
+ return problems.length === 0 ? 0 : 1;
75
+ }
76
+ catch (error) {
77
+ io.error(`one-suite: ${messageOf(error)}`);
78
+ return 1;
79
+ }
80
+ }
81
+ await runIfEntry(import.meta.url, main);
package/package.json CHANGED
@@ -1,6 +1,67 @@
1
1
  {
2
2
  "name": "@shyden-labs/playwright-devices",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Shared Playwright checks that one test suite ran unchanged on every phone, tablet and desktop browser, and the shared desktop browser projects.",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/shyden-labs/playwright-devices.git"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "type": "module",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/src/one-suite/check.d.ts",
17
+ "default": "./dist/src/one-suite/check.js"
18
+ },
19
+ "./assertion-counter": {
20
+ "types": "./dist/src/one-suite/assertion-counter.d.ts",
21
+ "default": "./dist/src/one-suite/assertion-counter.js"
22
+ },
23
+ "./desktop": {
24
+ "types": "./dist/src/desktop/browsers.d.ts",
25
+ "default": "./dist/src/desktop/browsers.js"
26
+ }
27
+ },
28
+ "bin": {
29
+ "one-suite": "dist/src/one-suite/cli.js"
30
+ },
31
+ "files": [
32
+ "dist/",
33
+ "NOTICE"
34
+ ],
35
+ "engines": {
36
+ "node": "^24.16.0 || >=26.3.0"
37
+ },
38
+ "scripts": {
39
+ "test:unit": "vitest run --config vitest.unit.config.ts",
40
+ "test:coverage": "vitest run --config vitest.unit.config.ts --coverage.enabled",
41
+ "typecheck": "tsc --noEmit -p .",
42
+ "lint": "eslint --max-warnings 0 .",
43
+ "format": "prettier --write .",
44
+ "format:check": "prettier --check .",
45
+ "build": "tsc -p tsconfig.build.json"
46
+ },
47
+ "peerDependencies": {
48
+ "@playwright/test": "^1.65.1"
49
+ },
50
+ "devDependencies": {
51
+ "@eslint/js": "10.0.1",
52
+ "@playwright/test": "1.65.1",
53
+ "@types/node": "26.6.6",
54
+ "@vitest/coverage-v8": "5.1.0",
55
+ "eslint": "10.15.0",
56
+ "prettier": "3.10.1",
57
+ "typescript": "6.0.3",
58
+ "typescript-eslint": "8.72.2",
59
+ "vitest": "5.1.0"
60
+ },
61
+ "allowScripts": {
62
+ "fsevents": false
63
+ },
64
+ "overrides": {
65
+ "minimatch": "11.0.3"
66
+ }
67
+ }