spana-test 0.2.0 → 0.3.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/README.md +47 -12
- package/dist/accessibility-audit-RS3VIWRT.js +140 -0
- package/dist/accessibility-audit-RS3VIWRT.js.map +1 -0
- package/dist/agent/index.d.ts +8 -26
- package/dist/agent/index.js +12 -15
- package/dist/{allure-PTTVORQ6.js → allure-RNMEYTXS.js} +42 -2
- package/dist/allure-RNMEYTXS.js.map +1 -0
- package/dist/appium-server-66GVUL24.js +119 -0
- package/dist/appium-server-66GVUL24.js.map +1 -0
- package/dist/baseline-manager-5TIUCNP5.js +38 -0
- package/dist/baseline-manager-5TIUCNP5.js.map +1 -0
- package/dist/{chunk-S2XNAKSO.js → chunk-24KSKK2I.js} +536 -334
- package/dist/chunk-24KSKK2I.js.map +1 -0
- package/dist/chunk-3J4NG7JU.js +80 -0
- package/dist/chunk-3J4NG7JU.js.map +1 -0
- package/dist/{chunk-MRH7SK52.js → chunk-3TRMQCUT.js} +3 -2
- package/dist/chunk-3TRMQCUT.js.map +1 -0
- package/dist/{chunk-SFBRFB2N.js → chunk-4OHBO7LD.js} +19 -12
- package/dist/chunk-4OHBO7LD.js.map +1 -0
- package/dist/chunk-5245YBLL.js +127 -0
- package/dist/chunk-5245YBLL.js.map +1 -0
- package/dist/{chunk-S4R4OR7T.js → chunk-7IA2XG3G.js} +66 -71
- package/dist/chunk-7IA2XG3G.js.map +1 -0
- package/dist/{chunk-L7MFJF46.js → chunk-7VOWF42B.js} +29 -5
- package/dist/chunk-7VOWF42B.js.map +1 -0
- package/dist/{chunk-AEKDFFPJ.js → chunk-DSTUWLSW.js} +15 -4
- package/dist/chunk-DSTUWLSW.js.map +1 -0
- package/dist/{chunk-P7JQRLP4.js → chunk-FJAJ4YNC.js} +14 -2
- package/dist/chunk-FJAJ4YNC.js.map +1 -0
- package/dist/chunk-IHVZKQQW.js +24 -0
- package/dist/chunk-IHVZKQQW.js.map +1 -0
- package/dist/{chunk-WQ4GXUUE.js → chunk-KAKHFSVA.js} +212 -34
- package/dist/chunk-KAKHFSVA.js.map +1 -0
- package/dist/chunk-OBCFACUW.js +28 -0
- package/dist/chunk-OBCFACUW.js.map +1 -0
- package/dist/{chunk-3YR4GUGE.js → chunk-QPIE3IMG.js} +65 -70
- package/dist/chunk-QPIE3IMG.js.map +1 -0
- package/dist/{chunk-VNYF5BHX.js → chunk-X2TJP7LB.js} +1 -3
- package/dist/{chunk-YBZCOQXJ.js → chunk-YXQEPVEW.js} +127 -66
- package/dist/chunk-YXQEPVEW.js.map +1 -0
- package/dist/cli.js +40 -25
- package/dist/cli.js.map +1 -1
- package/dist/{compiler-74VGKZO6.js → compiler-X6WTFMYF.js} +15 -7
- package/dist/compiler-X6WTFMYF.js.map +1 -0
- package/dist/config-loader-QM72GKEL.js +9 -0
- package/dist/{console-XWKUTP3D.js → console-7UW7VROK.js} +71 -1
- package/dist/console-7UW7VROK.js.map +1 -0
- package/dist/{discover-KZKXHZZA.js → discover-NPNF6SWQ.js} +4 -3
- package/dist/doctor-command-C3SEQGRQ.js +71 -0
- package/dist/doctor-command-C3SEQGRQ.js.map +1 -0
- package/dist/{flow-BUC9Mf8W.d.ts → flow-CW0_j7tw.d.ts} +47 -29
- package/dist/gherkin/steps.d.ts +2 -2
- package/dist/{html-GE6Q4DCG.js → html-F3X3XPSX.js} +78 -7
- package/dist/html-F3X3XPSX.js.map +1 -0
- package/dist/index.d.ts +4 -8
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/{init-command-GVMRXIMY.js → init-command-U66XCM66.js} +19 -34
- package/dist/init-command-U66XCM66.js.map +1 -0
- package/dist/init-flow-command-PR7J5FBM.js +37 -0
- package/dist/init-flow-command-PR7J5FBM.js.map +1 -0
- package/dist/{installer-YZJ4DV3F.js → installer-W5DITECS.js} +3 -4
- package/dist/{ios-ZW6XVNLG.js → ios-3GRECXAP.js} +3 -4
- package/dist/json-JMRPUVY2.js +20 -0
- package/dist/json-JMRPUVY2.js.map +1 -0
- package/dist/machine-6H25TRTU.js +16 -0
- package/dist/{provider-A57C3MU6.js → provider-YIPU5K42.js} +2 -2
- package/dist/{runner-UXNHVVGG.js → runner-6HK62Q7B.js} +2 -2
- package/dist/screenshot-compare-JFHH2WR4.js +75 -0
- package/dist/screenshot-compare-JFHH2WR4.js.map +1 -0
- package/dist/{server-W7OA3DDN.js → server-MZERO364.js} +362 -55
- package/dist/server-MZERO364.js.map +1 -0
- package/dist/session-3UZ5WAAD.js +17 -0
- package/dist/{coordinator-BbUjvvnX.d.ts → storybook-BK2JE4ld.d.ts} +95 -31
- package/dist/{studio-command-6VHTHDUK.js → studio-command-5BUER2RH.js} +2 -2
- package/dist/{test-command-AHMOZLV4.js → test-command-2PXTHASW.js} +871 -562
- package/dist/test-command-2PXTHASW.js.map +1 -0
- package/dist/{validator-35624P7S.js → validator-HZ2A3NEI.js} +3 -6
- package/dist/validator-HZ2A3NEI.js.map +1 -0
- package/package.json +6 -1
- package/studio-dist/assets/index-C-Io44gy.js +193 -0
- package/studio-dist/assets/index-DfM9lK4p.css +1 -0
- package/studio-dist/index.html +2 -2
- package/dist/allure-PTTVORQ6.js.map +0 -1
- package/dist/chunk-3YR4GUGE.js.map +0 -1
- package/dist/chunk-AEKDFFPJ.js.map +0 -1
- package/dist/chunk-BF37W5EG.js +0 -125
- package/dist/chunk-BF37W5EG.js.map +0 -1
- package/dist/chunk-EXLUY7KT.js +0 -21
- package/dist/chunk-EXLUY7KT.js.map +0 -1
- package/dist/chunk-FNDOEMOL.js +0 -62
- package/dist/chunk-FNDOEMOL.js.map +0 -1
- package/dist/chunk-HWFDXIXR.js +0 -183
- package/dist/chunk-HWFDXIXR.js.map +0 -1
- package/dist/chunk-IJIASIX5.js +0 -314
- package/dist/chunk-IJIASIX5.js.map +0 -1
- package/dist/chunk-L7MFJF46.js.map +0 -1
- package/dist/chunk-MRH7SK52.js.map +0 -1
- package/dist/chunk-P7JQRLP4.js.map +0 -1
- package/dist/chunk-S2XNAKSO.js.map +0 -1
- package/dist/chunk-S4R4OR7T.js.map +0 -1
- package/dist/chunk-SFBRFB2N.js.map +0 -1
- package/dist/chunk-WBU34APM.js +0 -38
- package/dist/chunk-WBU34APM.js.map +0 -1
- package/dist/chunk-WQ4GXUUE.js.map +0 -1
- package/dist/chunk-YBZCOQXJ.js.map +0 -1
- package/dist/compiler-74VGKZO6.js.map +0 -1
- package/dist/config-loader-BJJ3IJJ7.js +0 -9
- package/dist/console-XWKUTP3D.js.map +0 -1
- package/dist/doctor-command-T2UX5RV5.js +0 -732
- package/dist/doctor-command-T2UX5RV5.js.map +0 -1
- package/dist/html-GE6Q4DCG.js.map +0 -1
- package/dist/init-command-GVMRXIMY.js.map +0 -1
- package/dist/init-flow-command-R76AXF4Z.js +0 -34
- package/dist/init-flow-command-R76AXF4Z.js.map +0 -1
- package/dist/json-KS67BZYU.js +0 -39
- package/dist/json-KS67BZYU.js.map +0 -1
- package/dist/server-W7OA3DDN.js.map +0 -1
- package/dist/session-TMNOKYLG.js +0 -17
- package/dist/test-command-AHMOZLV4.js.map +0 -1
- package/studio-dist/assets/index-DC6DIXfl.js +0 -188
- package/studio-dist/assets/index-DDKsnBwD.css +0 -1
- /package/dist/{chunk-VNYF5BHX.js.map → chunk-X2TJP7LB.js.map} +0 -0
- /package/dist/{config-loader-BJJ3IJJ7.js.map → config-loader-QM72GKEL.js.map} +0 -0
- /package/dist/{discover-KZKXHZZA.js.map → discover-NPNF6SWQ.js.map} +0 -0
- /package/dist/{installer-YZJ4DV3F.js.map → installer-W5DITECS.js.map} +0 -0
- /package/dist/{ios-ZW6XVNLG.js.map → ios-3GRECXAP.js.map} +0 -0
- /package/dist/{provider-A57C3MU6.js.map → machine-6H25TRTU.js.map} +0 -0
- /package/dist/{runner-UXNHVVGG.js.map → provider-YIPU5K42.js.map} +0 -0
- /package/dist/{session-TMNOKYLG.js.map → runner-6HK62Q7B.js.map} +0 -0
- /package/dist/{validator-35624P7S.js.map → session-3UZ5WAAD.js.map} +0 -0
- /package/dist/{studio-command-6VHTHDUK.js.map → studio-command-5BUER2RH.js.map} +0 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateFlowStub
|
|
3
|
+
} from "./chunk-3J4NG7JU.js";
|
|
4
|
+
import "./chunk-DGUM43GV.js";
|
|
5
|
+
|
|
6
|
+
// src/cli/init-flow-command.ts
|
|
7
|
+
import { mkdirSync, statSync, writeFileSync } from "fs";
|
|
8
|
+
import { dirname, join, resolve } from "path";
|
|
9
|
+
function toFileName(name) {
|
|
10
|
+
return name.toLowerCase().replaceAll(/[^a-z0-9]+/g, "-").replaceAll(/^-+|-+$/g, "");
|
|
11
|
+
}
|
|
12
|
+
function runInitFlowCommand(options) {
|
|
13
|
+
const fileName = toFileName(options.name);
|
|
14
|
+
const filePath = options.outputPath ? resolve(options.outputPath) : join("flows", `${fileName}.flow.ts`);
|
|
15
|
+
if (!options.force) {
|
|
16
|
+
try {
|
|
17
|
+
statSync(filePath);
|
|
18
|
+
console.log(`Flow file already exists at ${filePath}. Use --force to overwrite.`);
|
|
19
|
+
return false;
|
|
20
|
+
} catch {
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const dir = dirname(filePath);
|
|
24
|
+
mkdirSync(dir, { recursive: true });
|
|
25
|
+
const content = generateFlowStub(options.name, {
|
|
26
|
+
platforms: options.platforms,
|
|
27
|
+
tags: options.tags,
|
|
28
|
+
preset: options.preset
|
|
29
|
+
});
|
|
30
|
+
writeFileSync(filePath, content, "utf8");
|
|
31
|
+
console.log(`Created ${filePath}`);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
runInitFlowCommand
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=init-flow-command-PR7J5FBM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli/init-flow-command.ts"],"sourcesContent":["import { mkdirSync, statSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, resolve } from \"node:path\";\nimport type { FlowStubPreset } from \"./scaffolds.js\";\nimport { generateFlowStub } from \"./scaffolds.js\";\n\nexport interface InitFlowOptions {\n name: string;\n outputPath?: string;\n platforms: string[];\n tags?: string[];\n preset?: FlowStubPreset;\n force: boolean;\n}\n\nfunction toFileName(name: string): string {\n return name\n .toLowerCase()\n .replaceAll(/[^a-z0-9]+/g, \"-\")\n .replaceAll(/^-+|-+$/g, \"\");\n}\n\nexport function runInitFlowCommand(options: InitFlowOptions): boolean {\n const fileName = toFileName(options.name);\n const filePath = options.outputPath\n ? resolve(options.outputPath)\n : join(\"flows\", `${fileName}.flow.ts`);\n\n if (!options.force) {\n try {\n statSync(filePath);\n console.log(`Flow file already exists at ${filePath}. Use --force to overwrite.`);\n return false;\n } catch {\n // File doesn't exist, proceed\n }\n }\n\n const dir = dirname(filePath);\n mkdirSync(dir, { recursive: true });\n\n const content = generateFlowStub(options.name, {\n platforms: options.platforms,\n tags: options.tags,\n preset: options.preset,\n });\n\n writeFileSync(filePath, content, \"utf8\");\n console.log(`Created ${filePath}`);\n return true;\n}\n"],"mappings":";;;;;;AAAA,SAAS,WAAW,UAAU,qBAAqB;AACnD,SAAS,SAAS,MAAM,eAAe;AAavC,SAAS,WAAW,MAAsB;AACxC,SAAO,KACJ,YAAY,EACZ,WAAW,eAAe,GAAG,EAC7B,WAAW,YAAY,EAAE;AAC9B;AAEO,SAAS,mBAAmB,SAAmC;AACpE,QAAM,WAAW,WAAW,QAAQ,IAAI;AACxC,QAAM,WAAW,QAAQ,aACrB,QAAQ,QAAQ,UAAU,IAC1B,KAAK,SAAS,GAAG,QAAQ,UAAU;AAEvC,MAAI,CAAC,QAAQ,OAAO;AAClB,QAAI;AACF,eAAS,QAAQ;AACjB,cAAQ,IAAI,+BAA+B,QAAQ,6BAA6B;AAChF,aAAO;AAAA,IACT,QAAQ;AAAA,IAER;AAAA,EACF;AAEA,QAAM,MAAM,QAAQ,QAAQ;AAC5B,YAAU,KAAK,EAAE,WAAW,KAAK,CAAC;AAElC,QAAM,UAAU,iBAAiB,QAAQ,MAAM;AAAA,IAC7C,WAAW,QAAQ;AAAA,IACnB,MAAM,QAAQ;AAAA,IACd,QAAQ,QAAQ;AAAA,EAClB,CAAC;AAED,gBAAc,UAAU,SAAS,MAAM;AACvC,UAAQ,IAAI,WAAW,QAAQ,EAAE;AACjC,SAAO;AACT;","names":[]}
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildWDA,
|
|
3
3
|
buildWDAForDevice,
|
|
4
|
-
findWDAProject,
|
|
5
4
|
setupWDA,
|
|
6
5
|
setupWDAForDevice,
|
|
7
6
|
startWDA,
|
|
8
7
|
startWDAOnDevice,
|
|
9
8
|
stopWDA
|
|
10
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-QPIE3IMG.js";
|
|
10
|
+
import "./chunk-OBCFACUW.js";
|
|
11
11
|
import "./chunk-DGUM43GV.js";
|
|
12
12
|
export {
|
|
13
13
|
buildWDA,
|
|
14
14
|
buildWDAForDevice,
|
|
15
|
-
findWDAProject,
|
|
16
15
|
setupWDA,
|
|
17
16
|
setupWDAForDevice,
|
|
18
17
|
startWDA,
|
|
19
18
|
startWDAOnDevice,
|
|
20
19
|
stopWDA
|
|
21
20
|
};
|
|
22
|
-
//# sourceMappingURL=installer-
|
|
21
|
+
//# sourceMappingURL=installer-W5DITECS.js.map
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
firstIOSSimulatorWithApp,
|
|
9
9
|
hasAppInstalledOnSimulator,
|
|
10
10
|
hasAppOnPhysicalDevice,
|
|
11
|
-
hasIproxy,
|
|
12
11
|
installOnPhysicalDevice,
|
|
13
12
|
installOnSimulator,
|
|
14
13
|
installedUrlSchemesOnSimulator,
|
|
@@ -21,7 +20,8 @@ import {
|
|
|
21
20
|
resetSimulatorKeychain,
|
|
22
21
|
startIproxy,
|
|
23
22
|
terminateOnSimulator
|
|
24
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-4OHBO7LD.js";
|
|
24
|
+
import "./chunk-OBCFACUW.js";
|
|
25
25
|
import "./chunk-DGUM43GV.js";
|
|
26
26
|
export {
|
|
27
27
|
bootSimulator,
|
|
@@ -33,7 +33,6 @@ export {
|
|
|
33
33
|
firstIOSSimulatorWithApp,
|
|
34
34
|
hasAppInstalledOnSimulator,
|
|
35
35
|
hasAppOnPhysicalDevice,
|
|
36
|
-
hasIproxy,
|
|
37
36
|
installOnPhysicalDevice,
|
|
38
37
|
installOnSimulator,
|
|
39
38
|
installedUrlSchemesOnSimulator,
|
|
@@ -47,4 +46,4 @@ export {
|
|
|
47
46
|
startIproxy,
|
|
48
47
|
terminateOnSimulator
|
|
49
48
|
};
|
|
50
|
-
//# sourceMappingURL=ios-
|
|
49
|
+
//# sourceMappingURL=ios-3GRECXAP.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import "./chunk-DGUM43GV.js";
|
|
2
|
+
|
|
3
|
+
// src/report/json.ts
|
|
4
|
+
function createJsonReporter() {
|
|
5
|
+
return {
|
|
6
|
+
onFlowPass(result) {
|
|
7
|
+
console.log(JSON.stringify({ event: "flowPass", ...result }));
|
|
8
|
+
},
|
|
9
|
+
onFlowFail(result) {
|
|
10
|
+
console.log(JSON.stringify({ event: "flowFail", ...result }));
|
|
11
|
+
},
|
|
12
|
+
onRunComplete(summary) {
|
|
13
|
+
console.log(JSON.stringify({ event: "runComplete", ...summary }));
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
createJsonReporter
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=json-JMRPUVY2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/report/json.ts"],"sourcesContent":["import type { Reporter } from \"./types.js\";\n\nexport function createJsonReporter(): Reporter {\n return {\n onFlowPass(result) {\n console.log(JSON.stringify({ event: \"flowPass\", ...result }));\n },\n\n onFlowFail(result) {\n console.log(JSON.stringify({ event: \"flowFail\", ...result }));\n },\n\n onRunComplete(summary) {\n console.log(JSON.stringify({ event: \"runComplete\", ...summary }));\n },\n };\n}\n"],"mappings":";;;AAEO,SAAS,qBAA+B;AAC7C,SAAO;AAAA,IACL,WAAW,QAAQ;AACjB,cAAQ,IAAI,KAAK,UAAU,EAAE,OAAO,YAAY,GAAG,OAAO,CAAC,CAAC;AAAA,IAC9D;AAAA,IAEA,WAAW,QAAQ;AACjB,cAAQ,IAAI,KAAK,UAAU,EAAE,OAAO,YAAY,GAAG,OAAO,CAAC,CAAC;AAAA,IAC9D;AAAA,IAEA,cAAc,SAAS;AACrB,cAAQ,IAAI,KAAK,UAAU,EAAE,OAAO,eAAe,GAAG,QAAQ,CAAC,CAAC;AAAA,IAClE;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MACHINE_SCHEMA_VERSION,
|
|
3
|
+
buildDocsUrl,
|
|
4
|
+
createMachineFailure,
|
|
5
|
+
createMachineSuccess,
|
|
6
|
+
printMachinePayload
|
|
7
|
+
} from "./chunk-IHVZKQQW.js";
|
|
8
|
+
import "./chunk-DGUM43GV.js";
|
|
9
|
+
export {
|
|
10
|
+
MACHINE_SCHEMA_VERSION,
|
|
11
|
+
buildDocsUrl,
|
|
12
|
+
createMachineFailure,
|
|
13
|
+
createMachineSuccess,
|
|
14
|
+
printMachinePayload
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=machine-6H25TRTU.js.map
|
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
createCloudProviderHelper,
|
|
3
3
|
detectProvider,
|
|
4
4
|
loadCustomProvider
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-X2TJP7LB.js";
|
|
6
6
|
import "./chunk-DGUM43GV.js";
|
|
7
7
|
export {
|
|
8
8
|
createCloudProviderHelper,
|
|
9
9
|
detectProvider,
|
|
10
10
|
loadCustomProvider
|
|
11
11
|
};
|
|
12
|
-
//# sourceMappingURL=provider-
|
|
12
|
+
//# sourceMappingURL=provider-YIPU5K42.js.map
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
loadFlowFile,
|
|
7
7
|
loadStepFiles,
|
|
8
8
|
loadTestSource
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-3TRMQCUT.js";
|
|
10
10
|
import "./chunk-DGUM43GV.js";
|
|
11
11
|
export {
|
|
12
12
|
applyShard,
|
|
@@ -17,4 +17,4 @@ export {
|
|
|
17
17
|
loadStepFiles,
|
|
18
18
|
loadTestSource
|
|
19
19
|
};
|
|
20
|
-
//# sourceMappingURL=runner-
|
|
20
|
+
//# sourceMappingURL=runner-6HK62Q7B.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import "./chunk-DGUM43GV.js";
|
|
2
|
+
|
|
3
|
+
// src/core/screenshot-compare.ts
|
|
4
|
+
import { PNG } from "pngjs";
|
|
5
|
+
import pixelmatch from "pixelmatch";
|
|
6
|
+
function compareScreenshots(expected, actual, options) {
|
|
7
|
+
const threshold = options?.threshold ?? 0.2;
|
|
8
|
+
const maxDiffPixelRatio = options?.maxDiffPixelRatio ?? 0.01;
|
|
9
|
+
const expectedPng = PNG.sync.read(Buffer.from(expected));
|
|
10
|
+
const actualPng = PNG.sync.read(Buffer.from(actual));
|
|
11
|
+
if (expectedPng.width !== actualPng.width || expectedPng.height !== actualPng.height) {
|
|
12
|
+
return {
|
|
13
|
+
match: false,
|
|
14
|
+
diffPixelCount: 0,
|
|
15
|
+
diffPixelRatio: 1,
|
|
16
|
+
sizeMismatch: true
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const { width, height } = expectedPng;
|
|
20
|
+
const totalPixels = width * height;
|
|
21
|
+
const diffPng = new PNG({ width, height });
|
|
22
|
+
const diffPixelCount = pixelmatch(expectedPng.data, actualPng.data, diffPng.data, width, height, {
|
|
23
|
+
threshold
|
|
24
|
+
});
|
|
25
|
+
const diffPixelRatio = totalPixels === 0 ? 0 : diffPixelCount / totalPixels;
|
|
26
|
+
const match = diffPixelRatio <= maxDiffPixelRatio;
|
|
27
|
+
if (match) {
|
|
28
|
+
return { match: true, diffPixelCount, diffPixelRatio };
|
|
29
|
+
}
|
|
30
|
+
const diffImage = PNG.sync.write(diffPng);
|
|
31
|
+
return { match: false, diffPixelCount, diffPixelRatio, diffImage };
|
|
32
|
+
}
|
|
33
|
+
async function cropToElement(screenshot, bounds) {
|
|
34
|
+
const sharp = (await import("sharp")).default;
|
|
35
|
+
return sharp(Buffer.from(screenshot)).extract({
|
|
36
|
+
left: Math.round(bounds.x),
|
|
37
|
+
top: Math.round(bounds.y),
|
|
38
|
+
width: Math.round(bounds.width),
|
|
39
|
+
height: Math.round(bounds.height)
|
|
40
|
+
}).png().toBuffer();
|
|
41
|
+
}
|
|
42
|
+
async function applyMask(screenshot, regions) {
|
|
43
|
+
const sharp = (await import("sharp")).default;
|
|
44
|
+
if (regions.length === 0) {
|
|
45
|
+
return sharp(Buffer.from(screenshot)).png().toBuffer();
|
|
46
|
+
}
|
|
47
|
+
const overlays = await Promise.all(
|
|
48
|
+
regions.map(async (region) => {
|
|
49
|
+
const w = Math.round(region.width);
|
|
50
|
+
const h = Math.round(region.height);
|
|
51
|
+
const grayPixel = Buffer.alloc(w * h * 4);
|
|
52
|
+
for (let i = 0; i < w * h; i++) {
|
|
53
|
+
grayPixel[i * 4] = 128;
|
|
54
|
+
grayPixel[i * 4 + 1] = 128;
|
|
55
|
+
grayPixel[i * 4 + 2] = 128;
|
|
56
|
+
grayPixel[i * 4 + 3] = 255;
|
|
57
|
+
}
|
|
58
|
+
const overlayBuffer = await sharp(grayPixel, {
|
|
59
|
+
raw: { width: w, height: h, channels: 4 }
|
|
60
|
+
}).png().toBuffer();
|
|
61
|
+
return {
|
|
62
|
+
input: overlayBuffer,
|
|
63
|
+
left: Math.round(region.x),
|
|
64
|
+
top: Math.round(region.y)
|
|
65
|
+
};
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
return sharp(Buffer.from(screenshot)).composite(overlays).png().toBuffer();
|
|
69
|
+
}
|
|
70
|
+
export {
|
|
71
|
+
applyMask,
|
|
72
|
+
compareScreenshots,
|
|
73
|
+
cropToElement
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=screenshot-compare-JFHH2WR4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/screenshot-compare.ts"],"sourcesContent":["import { PNG } from \"pngjs\";\nimport pixelmatch from \"pixelmatch\";\n\nexport interface CompareOptions {\n /** Per-pixel sensitivity 0-1, default 0.2 */\n threshold?: number;\n /** Max fraction of differing pixels allowed, default 0.01 */\n maxDiffPixelRatio?: number;\n}\n\nexport interface CompareResult {\n match: boolean;\n diffPixelCount: number;\n diffPixelRatio: number;\n /** PNG buffer of diff visualization (only on mismatch) */\n diffImage?: Buffer;\n sizeMismatch?: boolean;\n}\n\n/**\n * Compare two PNG buffers pixel-by-pixel.\n * Returns sizeMismatch if dimensions differ.\n */\nexport function compareScreenshots(\n expected: Buffer | Uint8Array,\n actual: Buffer | Uint8Array,\n options?: CompareOptions,\n): CompareResult {\n const threshold = options?.threshold ?? 0.2;\n const maxDiffPixelRatio = options?.maxDiffPixelRatio ?? 0.01;\n\n const expectedPng = PNG.sync.read(Buffer.from(expected));\n const actualPng = PNG.sync.read(Buffer.from(actual));\n\n if (expectedPng.width !== actualPng.width || expectedPng.height !== actualPng.height) {\n return {\n match: false,\n diffPixelCount: 0,\n diffPixelRatio: 1,\n sizeMismatch: true,\n };\n }\n\n const { width, height } = expectedPng;\n const totalPixels = width * height;\n\n const diffPng = new PNG({ width, height });\n const diffPixelCount = pixelmatch(expectedPng.data, actualPng.data, diffPng.data, width, height, {\n threshold,\n });\n\n const diffPixelRatio = totalPixels === 0 ? 0 : diffPixelCount / totalPixels;\n const match = diffPixelRatio <= maxDiffPixelRatio;\n\n if (match) {\n return { match: true, diffPixelCount, diffPixelRatio };\n }\n\n const diffImage = PNG.sync.write(diffPng);\n return { match: false, diffPixelCount, diffPixelRatio, diffImage };\n}\n\n/**\n * Crop a screenshot PNG to element bounds using sharp.\n */\nexport async function cropToElement(\n screenshot: Buffer | Uint8Array,\n bounds: { x: number; y: number; width: number; height: number },\n): Promise<Buffer> {\n const sharp = (await import(\"sharp\")).default;\n return sharp(Buffer.from(screenshot))\n .extract({\n left: Math.round(bounds.x),\n top: Math.round(bounds.y),\n width: Math.round(bounds.width),\n height: Math.round(bounds.height),\n })\n .png()\n .toBuffer();\n}\n\n/**\n * Paint solid gray rectangles over regions to mask dynamic content.\n * Returns the original image (as PNG buffer) if regions is empty.\n */\nexport async function applyMask(\n screenshot: Buffer | Uint8Array,\n regions: Array<{ x: number; y: number; width: number; height: number }>,\n): Promise<Buffer> {\n const sharp = (await import(\"sharp\")).default;\n\n if (regions.length === 0) {\n return sharp(Buffer.from(screenshot)).png().toBuffer();\n }\n\n const overlays = await Promise.all(\n regions.map(async (region) => {\n const w = Math.round(region.width);\n const h = Math.round(region.height);\n // Create a gray rectangle as a raw buffer (RGBA)\n const grayPixel = Buffer.alloc(w * h * 4);\n for (let i = 0; i < w * h; i++) {\n grayPixel[i * 4] = 128; // R\n grayPixel[i * 4 + 1] = 128; // G\n grayPixel[i * 4 + 2] = 128; // B\n grayPixel[i * 4 + 3] = 255; // A (fully opaque)\n }\n const overlayBuffer = await sharp(grayPixel, {\n raw: { width: w, height: h, channels: 4 },\n })\n .png()\n .toBuffer();\n\n return {\n input: overlayBuffer,\n left: Math.round(region.x),\n top: Math.round(region.y),\n };\n }),\n );\n\n return sharp(Buffer.from(screenshot)).composite(overlays).png().toBuffer();\n}\n"],"mappings":";;;AAAA,SAAS,WAAW;AACpB,OAAO,gBAAgB;AAsBhB,SAAS,mBACd,UACA,QACA,SACe;AACf,QAAM,YAAY,SAAS,aAAa;AACxC,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