@pixeyedev/playwright 0.4.4 → 0.4.6
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 +21 -0
- package/dist/browser.iife.js +4 -4
- package/dist/fixture.js +2 -1
- package/dist/reporter.d.ts +21 -2
- package/dist/reporter.js +48 -13
- package/dist/screenshot.d.ts +1 -0
- package/dist/screenshot.js +1 -0
- package/package.json +3 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pixeye (pixeye.dev)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/browser.iife.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";var __pixeye=(()=>{var c=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var
|
|
1
|
+
"use strict";var __pixeye=(()=>{var c=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var g=(e,t)=>{for(var o in t)c(e,o,{get:t[o],enumerable:!0})},b=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of f(t))!h.call(e,i)&&i!==o&&c(e,i,{get:()=>t[i],enumerable:!(n=p(t,i))||n.enumerable});return e};var S=e=>b(c({},"__esModule",{value:!0}),e);var T={};g(T,{scanRegions:()=>l,stabilize:()=>m,waitForReady:()=>y});var x=[{selector:"[data-pixeye-mask]",type:"mask"},{selector:"[data-pixeye-ignore]",type:"ignore"},{selector:"[data-pixeye-dynamic]",type:"dynamic"},{selector:'[data-visual-test="blackout"]',type:"mask"},{selector:'[data-visual-test="removed"]',type:"ignore"},{selector:'[data-visual-test="transparent"]',type:"mask"},{selector:"[data-percy-ignore]",type:"ignore"},{selector:"[data-percy-mask]",type:"mask"},{selector:'[data-chromatic="ignore"]',type:"ignore"}],l=()=>{let e=[],t=new Set;for(let{selector:o,type:n}of x){let i=document.querySelectorAll(o);for(let a of i){if(t.has(a))continue;t.add(a);let r=a.getBoundingClientRect();r.width===0||r.height===0||e.push({type:n,selector:o,bounds:{x:Math.max(0,Math.round(r.x)),y:Math.max(0,Math.round(r.y)),width:Math.round(r.width),height:Math.round(r.height)}})}}return e};var d="__pixeye_stabilize",s=e=>{let t=document.getElementById(d);t||(t=document.createElement("style"),t.id=d,document.head.appendChild(t)),t.textContent+=e+`
|
|
2
2
|
`},w=()=>{s(`
|
|
3
3
|
* {
|
|
4
4
|
-webkit-font-smoothing: antialiased !important;
|
|
5
5
|
-moz-osx-font-smoothing: grayscale !important;
|
|
6
6
|
}
|
|
7
|
-
`)},E=()=>{s(`
|
|
7
|
+
`)},E=()=>{if(s(`
|
|
8
8
|
*, *::before, *::after {
|
|
9
9
|
animation-duration: 0s !important;
|
|
10
10
|
animation-delay: 0s !important;
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
transition-delay: 0s !important;
|
|
13
13
|
scroll-behavior: auto !important;
|
|
14
14
|
}
|
|
15
|
-
`)},
|
|
15
|
+
`),typeof document.getAnimations=="function")for(let e of document.getAnimations())try{e.finish()}catch{e.cancel()}for(let e of document.querySelectorAll("svg")){let t=e;if(typeof t.pauseAnimations=="function")try{t.pauseAnimations(),t.setCurrentTime(0)}catch{}}},A=()=>{s(`
|
|
16
16
|
* { caret-color: transparent !important; }
|
|
17
17
|
::-webkit-scrollbar { display: none !important; }
|
|
18
18
|
* { scrollbar-width: none !important; }
|
|
19
|
-
`),document.querySelectorAll("[contenteditable], textarea, input").forEach(e=>{e.setAttribute("spellcheck","false")})},v=()=>{document.querySelectorAll("img").forEach(e=>{let t=e.getBoundingClientRect(),o=Math.round(t.width),n=Math.round(t.height);(o!==t.width||n!==t.height)&&(e.style.width=`${o}px`,e.style.height=`${n}px`)})},
|
|
19
|
+
`),document.querySelectorAll("[contenteditable], textarea, input").forEach(e=>{e.setAttribute("spellcheck","false")})},v=()=>{document.querySelectorAll("img").forEach(e=>{let t=e.getBoundingClientRect(),o=Math.round(t.width),n=Math.round(t.height);(o!==t.width||n!==t.height)&&(e.style.width=`${o}px`,e.style.height=`${n}px`)})},R=()=>{document.querySelectorAll("*").forEach(e=>{let t=getComputedStyle(e);(t.position==="sticky"||t.position==="fixed")&&(e.style.position="absolute")})},m=(e={})=>{e.colorScheme&&(document.documentElement.style.colorScheme=e.colorScheme),e.fontAntialiasing!==!1&&w(),e.disableAnimations!==!1&&E(),e.hideNonDeterministic!==!1&&A(),e.roundImageSizes!==!1&&v(),e.stabilizeStickyFixed!==!1&&R(),e.css&&s(e.css)};var u=async(e,t,o)=>{let n=Date.now();for(;!e();){if(Date.now()-n>o)throw new Error(`[pixeye] waitForReady timed out waiting for: ${t}`);await new Promise(i=>setTimeout(i,100))}},y=async(e={})=>{let t=e.timeout??1e4,o=async()=>{await document.fonts.ready;let i=Array.from(document.querySelectorAll("img"));await Promise.all(i.filter(a=>!a.complete).map(a=>new Promise(r=>{a.addEventListener("load",()=>r(),{once:!0}),a.addEventListener("error",()=>r(),{once:!0})}))),await u(()=>!document.querySelector('[aria-busy="true"]'),'aria-busy="true" elements to clear',t),await u(()=>!document.querySelector("[data-pixeye-loading]"),"data-pixeye-loading elements to disappear",t)},n=new Promise((i,a)=>{setTimeout(()=>a(new Error(`[pixeye] waitForReady timed out after ${t}ms`)),t)});await Promise.race([o(),n])};return S(T);})();
|
|
20
20
|
if(typeof window!=="undefined")window.__pixeye=__pixeye;
|
package/dist/fixture.js
CHANGED
|
@@ -23,7 +23,8 @@ export const test = base.extend({
|
|
|
23
23
|
setContext({
|
|
24
24
|
outputDir,
|
|
25
25
|
testFile,
|
|
26
|
-
testName: testInfo.title
|
|
26
|
+
testName: testInfo.title,
|
|
27
|
+
testId: testInfo.testId
|
|
27
28
|
});
|
|
28
29
|
const pixeyeApi = {
|
|
29
30
|
screenshot: (target, name, options) => screenshot(target, name, options)
|
package/dist/reporter.d.ts
CHANGED
|
@@ -3,19 +3,38 @@ interface ReporterOptions {
|
|
|
3
3
|
token?: string;
|
|
4
4
|
server?: string;
|
|
5
5
|
uploadConcurrency?: number;
|
|
6
|
+
/**
|
|
7
|
+
* Fail the test run (non-zero exit) when the upload is rejected for a
|
|
8
|
+
* CUSTOMER misconfiguration (bad token, lapsed plan/quota, permissions) so a
|
|
9
|
+
* run can't pass green with zero screenshots uploaded. Default `true`. Our
|
|
10
|
+
* transient faults (5xx/network) never fail the run regardless. Opt out with
|
|
11
|
+
* `failOnError: false` or `PIXEYE_FAIL_ON_ERROR=false`.
|
|
12
|
+
*/
|
|
13
|
+
failOnError?: boolean;
|
|
6
14
|
}
|
|
7
15
|
declare const detectShard: (config: FullConfig) => {
|
|
8
16
|
index: number;
|
|
9
17
|
total: number;
|
|
10
18
|
};
|
|
19
|
+
/** The tests that failed after their retries, by the id the sidecar carries
|
|
20
|
+
* (`testInfo.testId` = `TestCase.id`, unique across files, describes and
|
|
21
|
+
* projects); a flaky test's last files are from the attempt that passed. */
|
|
22
|
+
export declare const failedTestIds: (suite: Suite | null) => Set<string>;
|
|
23
|
+
/** The server reads `testStatus` and keeps such a shot out of the review
|
|
24
|
+
* and out of the baselines (`failed` diff status). */
|
|
25
|
+
export declare const markFailedTests: (metadata: Record<string, unknown> | undefined, failed: Set<string>) => Record<string, unknown> | undefined;
|
|
11
26
|
declare class PixeyeReporter implements Reporter {
|
|
12
27
|
private options;
|
|
13
28
|
private shard;
|
|
14
29
|
private skipUpload;
|
|
30
|
+
private failOnError;
|
|
31
|
+
private suite;
|
|
15
32
|
constructor(options?: ReporterOptions);
|
|
16
|
-
onBegin(config: FullConfig,
|
|
33
|
+
onBegin(config: FullConfig, suite: Suite): void;
|
|
17
34
|
onTestEnd(_test: TestCase, _result: TestResult): void;
|
|
18
|
-
onEnd(_result: FullResult): Promise<
|
|
35
|
+
onEnd(_result: FullResult): Promise<{
|
|
36
|
+
status: FullResult['status'];
|
|
37
|
+
} | undefined>;
|
|
19
38
|
}
|
|
20
39
|
export default PixeyeReporter;
|
|
21
40
|
export { detectShard };
|
package/dist/reporter.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { detectCIEnvironment, discoverScreenshots, PixeyeClient,
|
|
3
|
+
import { detectCIEnvironment, discoverScreenshots, isUploadMisconfig, PixeyeClient, renderUploadFailureBanner, resolveFailOnError, runParallel, swapImageExtension, uploadErrorSummary } from '@pixeyedev/core';
|
|
4
|
+
import { CONTENT_TYPE_BY_FORMAT } from '@pixeyedev/shared';
|
|
4
5
|
import { getContext } from './screenshot.js';
|
|
5
6
|
const DEFAULT_UPLOAD_CONCURRENCY = 32;
|
|
6
7
|
const detectShard = (config) => {
|
|
@@ -23,14 +24,29 @@ const detectShard = (config) => {
|
|
|
23
24
|
const detectRunner = () => {
|
|
24
25
|
return 'playwright';
|
|
25
26
|
};
|
|
27
|
+
/** The tests that failed after their retries, by the id the sidecar carries
|
|
28
|
+
* (`testInfo.testId` = `TestCase.id`, unique across files, describes and
|
|
29
|
+
* projects); a flaky test's last files are from the attempt that passed. */
|
|
30
|
+
export const failedTestIds = (suite) => new Set((suite ? suite.allTests() : [])
|
|
31
|
+
.filter(test => test.outcome() === 'unexpected')
|
|
32
|
+
.map(test => test.id));
|
|
33
|
+
/** The server reads `testStatus` and keeps such a shot out of the review
|
|
34
|
+
* and out of the baselines (`failed` diff status). */
|
|
35
|
+
export const markFailedTests = (metadata, failed) => metadata && typeof metadata.testId === 'string' && failed.has(metadata.testId)
|
|
36
|
+
? { ...metadata, testStatus: 'failed' }
|
|
37
|
+
: metadata;
|
|
26
38
|
class PixeyeReporter {
|
|
27
39
|
options;
|
|
28
40
|
shard = { index: 0, total: 1 };
|
|
29
41
|
skipUpload = false;
|
|
42
|
+
failOnError;
|
|
43
|
+
suite = null;
|
|
30
44
|
constructor(options = {}) {
|
|
31
45
|
this.options = options;
|
|
46
|
+
this.failOnError = resolveFailOnError(options.failOnError, process.env.PIXEYE_FAIL_ON_ERROR);
|
|
32
47
|
}
|
|
33
|
-
onBegin(config,
|
|
48
|
+
onBegin(config, suite) {
|
|
49
|
+
this.suite = suite;
|
|
34
50
|
const token = this.options.token ?? process.env.PIXEYE_TOKEN;
|
|
35
51
|
if (!token) {
|
|
36
52
|
console.warn('[pixeye] No PIXEYE_TOKEN found. Skipping upload. Screenshots will still be captured.');
|
|
@@ -59,8 +75,11 @@ class PixeyeReporter {
|
|
|
59
75
|
try {
|
|
60
76
|
files = await discoverScreenshots(outputDir);
|
|
61
77
|
}
|
|
62
|
-
catch {
|
|
63
|
-
|
|
78
|
+
catch (err) {
|
|
79
|
+
// A missing directory yields an empty list, so a THROW here is always a
|
|
80
|
+
// file we could not read — say which, instead of "no screenshots".
|
|
81
|
+
console.error(`[pixeye] Could not read screenshots in ${outputDir}.`);
|
|
82
|
+
console.error(`[pixeye] ${err.message}`);
|
|
64
83
|
return;
|
|
65
84
|
}
|
|
66
85
|
if (files.length === 0) {
|
|
@@ -79,7 +98,9 @@ class PixeyeReporter {
|
|
|
79
98
|
const concurrency = this.options.uploadConcurrency ?? DEFAULT_UPLOAD_CONCURRENCY;
|
|
80
99
|
try {
|
|
81
100
|
const client = new PixeyeClient({ serverUrl: server, token });
|
|
82
|
-
// 1. Create build
|
|
101
|
+
// 1. Create build. A run with a failed test is partial: the shots it
|
|
102
|
+
// never reached are not removed, and keep their baseline.
|
|
103
|
+
const failed = failedTestIds(this.suite);
|
|
83
104
|
const prNumber = process.env.PIXEYE_PR ? parseInt(process.env.PIXEYE_PR, 10) : ci?.prNumber;
|
|
84
105
|
const buildResponse = await client.createBuild({
|
|
85
106
|
projectToken: token,
|
|
@@ -87,13 +108,16 @@ class PixeyeReporter {
|
|
|
87
108
|
branch,
|
|
88
109
|
prNumber: prNumber && !isNaN(prNumber) ? prNumber : undefined,
|
|
89
110
|
shardCount: this.shard.total,
|
|
111
|
+
partial: failed.size > 0,
|
|
90
112
|
runner,
|
|
91
113
|
baseBranch: ci?.baseBranch
|
|
92
114
|
});
|
|
93
115
|
const buildId = buildResponse.build.id;
|
|
94
116
|
// 2. Presign upload URLs
|
|
95
117
|
const hashes = files.map(f => f.fileHash);
|
|
96
|
-
|
|
118
|
+
// Only non-PNG needs declaring: the server defaults to png. Filtering
|
|
119
|
+
// on 'webp' alone stored a sniffed jpeg under a .png key.
|
|
120
|
+
const formats = Object.fromEntries(files.filter(f => f.format !== 'png').map(f => [f.fileHash, f.format]));
|
|
97
121
|
const presign = await client.presignUpload({
|
|
98
122
|
buildId,
|
|
99
123
|
hashes,
|
|
@@ -115,7 +139,7 @@ class PixeyeReporter {
|
|
|
115
139
|
return;
|
|
116
140
|
}
|
|
117
141
|
const buffer = await readFile(file.filePath);
|
|
118
|
-
const contentType = file.format
|
|
142
|
+
const contentType = CONTENT_TYPE_BY_FORMAT[file.format];
|
|
119
143
|
await client.uploadFile(url, buffer, contentType);
|
|
120
144
|
uploaded++;
|
|
121
145
|
});
|
|
@@ -123,7 +147,7 @@ class PixeyeReporter {
|
|
|
123
147
|
// 4. Read metadata sidecars and build manifest
|
|
124
148
|
const manifest = await Promise.all(files.map(async (f) => {
|
|
125
149
|
// Try to read companion .meta.json
|
|
126
|
-
const metaPath = f.filePath
|
|
150
|
+
const metaPath = swapImageExtension(f.filePath, '.meta.json');
|
|
127
151
|
let metadata;
|
|
128
152
|
try {
|
|
129
153
|
const metaContent = await readFile(metaPath, 'utf-8');
|
|
@@ -138,7 +162,7 @@ class PixeyeReporter {
|
|
|
138
162
|
format: f.format,
|
|
139
163
|
width: f.width,
|
|
140
164
|
height: f.height,
|
|
141
|
-
metadata
|
|
165
|
+
metadata: markFailedTests(metadata, failed)
|
|
142
166
|
};
|
|
143
167
|
}));
|
|
144
168
|
// 5. Submit shard
|
|
@@ -150,12 +174,23 @@ class PixeyeReporter {
|
|
|
150
174
|
console.log(`[pixeye] ${files.length} screenshots (${uploaded} new, ${presign.existing.length} cached) — ${server}/builds/${buildId}`);
|
|
151
175
|
}
|
|
152
176
|
catch (err) {
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
|
|
177
|
+
// P0-2: a CUSTOMER misconfiguration (bad token, lapsed plan/quota,
|
|
178
|
+
// permissions) must NOT pass silently — surface a loud banner and fail
|
|
179
|
+
// the run by default so a green CI can't hide zero uploaded screenshots.
|
|
180
|
+
// Our transient faults (5xx/network/R2) only warn — never break their CI.
|
|
181
|
+
if (isUploadMisconfig(err)) {
|
|
182
|
+
console.error(renderUploadFailureBanner(err, { willFail: this.failOnError }));
|
|
183
|
+
if (this.failOnError) {
|
|
184
|
+
// Playwright IGNORES `process.exitCode` — its runner calls
|
|
185
|
+
// `process.exit(status === 'passed' ? 0 : 1)`, overriding it. The ONLY
|
|
186
|
+
// reporter-side lever is returning a status from onEnd, which the
|
|
187
|
+
// multiplexer applies (`result.status = outResult.status`). Return
|
|
188
|
+
// 'failed' so a passing run with a rejected upload still exits non-zero.
|
|
189
|
+
return { status: 'failed' };
|
|
190
|
+
}
|
|
156
191
|
}
|
|
157
192
|
else {
|
|
158
|
-
console.warn(`[pixeye] Upload failed: ${err
|
|
193
|
+
console.warn(`[pixeye] Upload failed (transient — CI not failed): ${uploadErrorSummary(err)}`);
|
|
159
194
|
}
|
|
160
195
|
}
|
|
161
196
|
}
|
package/dist/screenshot.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export interface ScreenshotContext {
|
|
|
27
27
|
outputDir: string;
|
|
28
28
|
testFile: string;
|
|
29
29
|
testName: string;
|
|
30
|
+
testId?: string;
|
|
30
31
|
}
|
|
31
32
|
export declare const setContext: (ctx: ScreenshotContext) => void;
|
|
32
33
|
export declare const getContext: () => ScreenshotContext | null;
|
package/dist/screenshot.js
CHANGED
|
@@ -200,6 +200,7 @@ export const screenshot = async (target, name, options = {}) => {
|
|
|
200
200
|
colorScheme: options.colorScheme,
|
|
201
201
|
testFile,
|
|
202
202
|
testName,
|
|
203
|
+
testId: _context?.testId,
|
|
203
204
|
threshold: options.threshold,
|
|
204
205
|
regions: allRegions.length > 0 ? allRegions : undefined,
|
|
205
206
|
componentBounds
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixeyedev/playwright",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
|
+
"license": "MIT",
|
|
4
5
|
"private": false,
|
|
5
6
|
"type": "module",
|
|
6
7
|
"files": [
|
|
@@ -27,6 +28,7 @@
|
|
|
27
28
|
},
|
|
28
29
|
"scripts": {
|
|
29
30
|
"build": "tsc && cp ../browser/dist/browser.iife.js dist/browser.iife.js",
|
|
31
|
+
"prepack": "rm -rf dist && npm run build",
|
|
30
32
|
"typecheck": "tsc --noEmit",
|
|
31
33
|
"test": "vitest run",
|
|
32
34
|
"lint": "echo 'ok'",
|