@cappa/core 0.4.2 → 0.4.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cappa/core",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "Core Playwright screenshot functionality for Cappa",
5
5
  "author": "Tim Richter",
6
6
  "repository": {
@@ -11,6 +11,9 @@
11
11
  "publishConfig": {
12
12
  "access": "public"
13
13
  },
14
+ "files": [
15
+ "dist"
16
+ ],
14
17
  "sideEffects": false,
15
18
  "main": "./dist/index.js",
16
19
  "types": "./dist/index.d.ts",
@@ -26,7 +29,7 @@
26
29
  "@blazediff/types": "^1.4.1",
27
30
  "playwright-core": "^1.56.1",
28
31
  "pngjs": "^7.0.0",
29
- "@cappa/logger": "0.0.7"
32
+ "@cappa/logger": "0.0.8"
30
33
  },
31
34
  "devDependencies": {
32
35
  "@types/node": "24.9.2",
@@ -1,23 +0,0 @@
1
-
2
- > @cappa/core@0.4.2 build /home/runner/work/cappa/cappa/packages/core
3
- > tsdown
4
-
5
- ℹ tsdown v0.15.12 powered by rolldown v1.0.0-beta.45
6
- ℹ Using tsdown config: /home/runner/work/cappa/cappa/packages/core/tsdown.config.ts
7
- (node:2443) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/runner/work/cappa/cappa/packages/core/tsdown.config.ts is not specified and it doesn't parse as CommonJS.
8
- Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
9
- To eliminate this warning, add "type": "module" to /home/runner/work/cappa/cappa/packages/core/package.json.
10
- (Use `node --trace-warnings ...` to show where the warning was created)
11
- ℹ entry: src/index.ts
12
- ℹ tsconfig: tsconfig.json
13
- ℹ Build start
14
- ℹ [CJS] dist/index.js 26.47 kB │ gzip: 6.37 kB
15
- ℹ [CJS] dist/index.js.map 47.61 kB │ gzip: 11.17 kB
16
- ℹ [CJS] 2 files, total: 74.08 kB
17
- ℹ [ESM] dist/index.mjs 24.41 kB │ gzip: 5.84 kB
18
- ℹ [ESM] dist/index.mjs.map 47.50 kB │ gzip: 11.13 kB
19
- ℹ [ESM] dist/index.d.mts 13.90 kB │ gzip: 3.89 kB
20
- ℹ [ESM] 3 files, total: 85.82 kB
21
- ℹ [CJS] dist/index.d.ts 13.90 kB │ gzip: 3.89 kB
22
- ℹ [CJS] 1 files, total: 13.90 kB
23
- ✔ Build complete in 2797ms
package/CHANGELOG.md DELETED
@@ -1,270 +0,0 @@
1
- # @cappa/core
2
-
3
- ## 0.4.2
4
-
5
- ### Patch Changes
6
-
7
- - 1fad7cc: fix: deleted screenshot handling in approve command
8
- - Updated dependencies [1fad7cc]
9
- - @cappa/logger@0.0.7
10
-
11
- ## 0.4.1
12
-
13
- ### Patch Changes
14
-
15
- - 298486b: fix: package export types
16
- - Updated dependencies [298486b]
17
- - @cappa/logger@0.0.6
18
-
19
- ## 0.4.0
20
-
21
- ### Minor Changes
22
-
23
- - 915be10: Add a `logConsoleEvents` base configuration option that controls whether Playwright console
24
- messages are logged during captures, and have the Storybook plugin respect the global setting.
25
-
26
- ### Patch Changes
27
-
28
- - Updated dependencies [1e8f301]
29
- - @cappa/logger@0.0.5
30
-
31
- ## 0.3.1
32
-
33
- ### Patch Changes
34
-
35
- - 772d0f6: Ensure approving screenshots only updates baselines when actual and expected images differ.
36
-
37
- ## 0.3.0
38
-
39
- ### Minor Changes
40
-
41
- - e0f7f08: Add an `onFail` configuration callback for failed screenshots and forward environment details to configuration functions.
42
-
43
- ## 0.2.5
44
-
45
- ### Patch Changes
46
-
47
- - faa5c05: fix: better logs
48
-
49
- ## 0.2.4
50
-
51
- ### Patch Changes
52
-
53
- - 6afa8eb: fix: less redundant logs
54
-
55
- ## 0.2.3
56
-
57
- ### Patch Changes
58
-
59
- - 4068bca: fix: correct screenshot handling logic in ScreenshotTool
60
-
61
- ## 0.2.2
62
-
63
- ### Patch Changes
64
-
65
- - 6526418: fix: actual screenshot error
66
-
67
- ## 0.2.1
68
-
69
- ### Patch Changes
70
-
71
- - 526857a: feat: add variant and play function support
72
- - Updated dependencies [526857a]
73
- - @cappa/logger@0.0.4
74
-
75
- ## 0.2.0
76
-
77
- ### Minor Changes
78
-
79
- - 5b1f66f: Add support for capturing screenshot variants and configure Storybook stories to request multiple viewport screenshots.
80
- - 88b3648: Centralize screenshot directory management in the core package and update the CLI and server to consume the shared helpers.
81
-
82
- ### Patch Changes
83
-
84
- - 87c8ab9: Document how screenshot retries work in the docs so users know how to
85
- configure and reason about the behaviour.
86
- - a1d91c6: feat: add viewport options
87
-
88
- ## 0.1.3
89
-
90
- ### Patch Changes
91
-
92
- - f6456fb: feat: add retry functionality
93
- - Updated dependencies [f6456fb]
94
- - @cappa/logger@0.0.3
95
-
96
- ## 0.1.2
97
-
98
- ### Patch Changes
99
-
100
- - a772b76: Add better logging + cleanup
101
- - Updated dependencies [a772b76]
102
- - @cappa/logger@0.0.2
103
-
104
- ## 0.1.1
105
-
106
- ### Patch Changes
107
-
108
- - d640855: Fix server public folder publish
109
-
110
- ## 0.1.0
111
-
112
- ### Minor Changes
113
-
114
- - 78c1423: Add review functionality
115
-
116
- ## 0.0.27
117
-
118
- ### Patch Changes
119
-
120
- - 8c17aac: Remove sandboxing
121
-
122
- ## 0.0.26
123
-
124
- ### Patch Changes
125
-
126
- - f232833: Increase deviceScaleFactor
127
-
128
- ## 0.0.25
129
-
130
- ### Patch Changes
131
-
132
- - e949088: Improve ui freezing styles
133
-
134
- ## 0.0.24
135
-
136
- ### Patch Changes
137
-
138
- - 4e109c5: Fix browsers path discovery
139
-
140
- ## 0.0.23
141
-
142
- ### Patch Changes
143
-
144
- - df7a7ec: Add more screenshot options
145
-
146
- ## 0.0.22
147
-
148
- ### Patch Changes
149
-
150
- - 27a570a: Always use png screenshots
151
-
152
- ## 0.0.21
153
-
154
- ### Patch Changes
155
-
156
- - e01e7c5: Add better report output
157
-
158
- ## 0.0.20
159
-
160
- ### Patch Changes
161
-
162
- - eb34ecb: Add clean option to cli
163
-
164
- ## 0.0.19
165
-
166
- ### Patch Changes
167
-
168
- - 63cf442: Use logging in storybook plugin
169
-
170
- ## 0.0.18
171
-
172
- ### Patch Changes
173
-
174
- - 3a8b89e: Fix skipped stories and report
175
-
176
- ## 0.0.17
177
-
178
- ### Patch Changes
179
-
180
- - 6d7176e: Fix error reporting
181
-
182
- ## 0.0.16
183
-
184
- ### Patch Changes
185
-
186
- - 92d164e: Fix directory creation
187
-
188
- ## 0.0.15
189
-
190
- ### Patch Changes
191
-
192
- - a41a91e: Add fullPage option
193
-
194
- ## 0.0.14
195
-
196
- ### Patch Changes
197
-
198
- - b8af138: Screenshot Creation folders
199
-
200
- ## 0.0.13
201
-
202
- ### Patch Changes
203
-
204
- - c538974: Replace playwright with playwright-core
205
-
206
- ## 0.0.12
207
-
208
- ### Patch Changes
209
-
210
- - 4e529fd: New options
211
-
212
- ## 0.0.11
213
-
214
- ### Patch Changes
215
-
216
- - 990246d: Fix
217
-
218
- ## 0.0.10
219
-
220
- ### Patch Changes
221
-
222
- - c8f7bd8: Fix concurrency
223
-
224
- ## 0.0.9
225
-
226
- ### Patch Changes
227
-
228
- - 37f2587: Fix pages
229
-
230
- ## 0.0.8
231
-
232
- ### Patch Changes
233
-
234
- - 76854a2: fix context
235
-
236
- ## 0.0.7
237
-
238
- ### Patch Changes
239
-
240
- - 3c53e57: Reuse playwright pages
241
-
242
- ## 0.0.6
243
-
244
- ### Patch Changes
245
-
246
- - 2acecef: Add skip option
247
-
248
- ## 0.0.5
249
-
250
- ### Patch Changes
251
-
252
- - a8a0d8f: Add delay option
253
-
254
- ## 0.0.4
255
-
256
- ### Patch Changes
257
-
258
- - 148b9ca: Fix dist folder
259
-
260
- ## 0.0.3
261
-
262
- ### Patch Changes
263
-
264
- - bff1e95: Fix types
265
-
266
- ## 0.0.2
267
-
268
- ### Patch Changes
269
-
270
- - b3d2806: Init
@@ -1,375 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { PNG } from "pngjs";
4
- import { afterAll, beforeAll, describe, expect, it } from "vitest";
5
- import {
6
- type CompareOptions,
7
- type CompareResult,
8
- compareImages,
9
- imagesMatch,
10
- saveDiffImage,
11
- } from "./compare";
12
-
13
- // Test utilities
14
- function createSolidColorPNG(
15
- width: number,
16
- height: number,
17
- color: [number, number, number, number] = [255, 0, 0, 255],
18
- ): Buffer {
19
- const png = new PNG({ width, height });
20
-
21
- for (let y = 0; y < height; y++) {
22
- for (let x = 0; x < width; x++) {
23
- const idx = (width * y + x) << 2;
24
- png.data[idx] = color[0]; // red
25
- png.data[idx + 1] = color[1]; // green
26
- png.data[idx + 2] = color[2]; // blue
27
- png.data[idx + 3] = color[3]; // alpha
28
- }
29
- }
30
-
31
- return PNG.sync.write(png);
32
- }
33
-
34
- function createGradientPNG(width: number, height: number): Buffer {
35
- const png = new PNG({ width, height });
36
-
37
- for (let y = 0; y < height; y++) {
38
- for (let x = 0; x < width; x++) {
39
- const idx = (width * y + x) << 2;
40
- png.data[idx] = Math.floor((x / width) * 255); // red gradient
41
- png.data[idx + 1] = Math.floor((y / height) * 255); // green gradient
42
- png.data[idx + 2] = 128; // blue constant
43
- png.data[idx + 3] = 255; // alpha
44
- }
45
- }
46
-
47
- return PNG.sync.write(png);
48
- }
49
-
50
- function createCheckerboardPNG(
51
- width: number,
52
- height: number,
53
- squareSize: number = 10,
54
- ): Buffer {
55
- const png = new PNG({ width, height });
56
-
57
- for (let y = 0; y < height; y++) {
58
- for (let x = 0; x < width; x++) {
59
- const idx = (width * y + x) << 2;
60
- const squareX = Math.floor(x / squareSize);
61
- const squareY = Math.floor(y / squareSize);
62
- const isWhite = (squareX + squareY) % 2 === 0;
63
-
64
- const color = isWhite ? 255 : 0;
65
- png.data[idx] = color; // red
66
- png.data[idx + 1] = color; // green
67
- png.data[idx + 2] = color; // blue
68
- png.data[idx + 3] = 255; // alpha
69
- }
70
- }
71
-
72
- return PNG.sync.write(png);
73
- }
74
-
75
- describe("compare", () => {
76
- const testDir = path.join(__dirname, "__test-images__");
77
-
78
- beforeAll(() => {
79
- // Create test directory
80
- if (!fs.existsSync(testDir)) {
81
- fs.mkdirSync(testDir, { recursive: true });
82
- }
83
-
84
- // Create test image files
85
- const redImage = createSolidColorPNG(100, 100, [255, 0, 0, 255]);
86
- const blueImage = createSolidColorPNG(100, 100, [0, 0, 255, 255]);
87
- const gradientImage = createGradientPNG(100, 100);
88
- const checkerImage = createCheckerboardPNG(100, 100);
89
- const smallImage = createSolidColorPNG(50, 50, [255, 0, 0, 255]);
90
-
91
- fs.writeFileSync(path.join(testDir, "red.png"), redImage);
92
- fs.writeFileSync(path.join(testDir, "blue.png"), blueImage);
93
- fs.writeFileSync(path.join(testDir, "gradient.png"), gradientImage);
94
- fs.writeFileSync(path.join(testDir, "checker.png"), checkerImage);
95
- fs.writeFileSync(path.join(testDir, "small.png"), smallImage);
96
- });
97
-
98
- afterAll(() => {
99
- // Clean up test directory
100
- if (fs.existsSync(testDir)) {
101
- fs.rmSync(testDir, { recursive: true, force: true });
102
- }
103
- });
104
-
105
- describe("compareImages", () => {
106
- it("should return 0% difference for identical images", async () => {
107
- const image = createSolidColorPNG(50, 50, [255, 0, 0, 255]);
108
-
109
- const result = await compareImages(image, image);
110
-
111
- expect(result.numDiffPixels).toBe(0);
112
- expect(result.totalPixels).toBe(2500);
113
- expect(result.percentDifference).toBe(0);
114
- expect(result.passed).toBe(true);
115
- expect(result.diffBuffer).toEqual(undefined);
116
- });
117
-
118
- it("should return 100% difference for completely different images", async () => {
119
- const redImage = createSolidColorPNG(50, 50, [255, 0, 0, 255]);
120
- const blueImage = createSolidColorPNG(50, 50, [0, 0, 255, 255]);
121
-
122
- const result = await compareImages(redImage, blueImage);
123
-
124
- expect(result.numDiffPixels).toBe(2500);
125
- expect(result.totalPixels).toBe(2500);
126
- expect(result.percentDifference).toBe(100);
127
- expect(result.passed).toBe(false);
128
- });
129
-
130
- it("should work with file paths", async () => {
131
- const redPath = path.join(testDir, "red.png");
132
- const bluePath = path.join(testDir, "blue.png");
133
-
134
- const result = await compareImages(redPath, bluePath);
135
-
136
- expect(result.numDiffPixels).toBe(10000);
137
- expect(result.totalPixels).toBe(10000);
138
- expect(result.percentDifference).toBe(100);
139
- expect(result.passed).toBe(false);
140
- });
141
-
142
- it("should work with mixed file path and buffer", async () => {
143
- const redPath = path.join(testDir, "red.png");
144
- const blueBuffer = createSolidColorPNG(100, 100, [0, 0, 255, 255]);
145
-
146
- const result = await compareImages(redPath, blueBuffer);
147
-
148
- expect(result.percentDifference).toBe(100);
149
- expect(result.passed).toBe(false);
150
- });
151
-
152
- it("should respect maxDiffPercentage parameter", async () => {
153
- const redImage = createSolidColorPNG(50, 50, [255, 0, 0, 255]);
154
- const blueImage = createSolidColorPNG(50, 50, [0, 0, 255, 255]);
155
-
156
- const result1 = await compareImages(redImage, blueImage, false, {
157
- maxDiffPercentage: 50,
158
- });
159
- const result2 = await compareImages(redImage, blueImage, false, {
160
- maxDiffPercentage: 100,
161
- });
162
-
163
- expect(result1.passed).toBe(false); // 100% > 50%
164
- expect(result2.passed).toBe(true); // 100% < 100%
165
- });
166
-
167
- it("should apply threshold option correctly", async () => {
168
- // Create two slightly different images
169
- const image1 = createSolidColorPNG(50, 50, [100, 100, 100, 255]);
170
- const image2 = createSolidColorPNG(50, 50, [105, 105, 105, 255]); // Slightly lighter
171
-
172
- const strictResult = await compareImages(image1, image2, false, {
173
- threshold: 0.01,
174
- });
175
- const lenientResult = await compareImages(image1, image2, false, {
176
- threshold: 0.5,
177
- });
178
-
179
- expect(strictResult.numDiffPixels).toBeGreaterThan(
180
- lenientResult.numDiffPixels,
181
- );
182
- });
183
-
184
- it("should throw error for mismatched dimensions", async () => {
185
- const largeImage = createSolidColorPNG(100, 100, [255, 0, 0, 255]);
186
- const smallImage = createSolidColorPNG(50, 50, [255, 0, 0, 255]);
187
-
188
- const result = await compareImages(largeImage, smallImage);
189
-
190
- expect(result.differentSizes).toBe(true);
191
- expect(result.numDiffPixels).toBe(0);
192
- expect(result.totalPixels).toBe(0);
193
- expect(result.percentDifference).toBe(0);
194
- expect(result.passed).toBe(false);
195
- });
196
-
197
- it("should handle custom compare options", async () => {
198
- const image1 = createCheckerboardPNG(50, 50, 5);
199
- const image2 = createCheckerboardPNG(50, 50, 6); // Slightly different pattern
200
-
201
- const options: CompareOptions = {
202
- threshold: 0.2,
203
- includeAA: true,
204
- alpha: 0.2,
205
- aaColor: [0, 255, 0],
206
- diffColor: [255, 0, 255],
207
- diffColorAlt: [0, 255, 255],
208
- };
209
-
210
- const result = await compareImages(image1, image2, false, options);
211
-
212
- expect(result).toBeDefined();
213
- expect(result.diffBuffer).toEqual(undefined);
214
- });
215
-
216
- it("should handle identical file paths", async () => {
217
- const redPath = path.join(testDir, "red.png");
218
-
219
- const result = await compareImages(redPath, redPath);
220
-
221
- expect(result.numDiffPixels).toBe(0);
222
- expect(result.percentDifference).toBe(0);
223
- expect(result.passed).toBe(true);
224
- });
225
- });
226
-
227
- describe("imagesMatch", () => {
228
- it("should return true for identical images", async () => {
229
- const image = createSolidColorPNG(50, 50, [255, 0, 0, 255]);
230
-
231
- const matches = await imagesMatch(image, image);
232
-
233
- expect(matches).toBe(true);
234
- });
235
-
236
- it("should return false for completely different images", async () => {
237
- const redImage = createSolidColorPNG(50, 50, [255, 0, 0, 255]);
238
- const blueImage = createSolidColorPNG(50, 50, [0, 0, 255, 255]);
239
-
240
- const matches = await imagesMatch(redImage, blueImage);
241
-
242
- expect(matches).toBe(false);
243
- });
244
-
245
- it("should respect maxDifferencePercent", async () => {
246
- const redImage = createSolidColorPNG(50, 50, [255, 0, 0, 255]);
247
- const blueImage = createSolidColorPNG(50, 50, [0, 0, 255, 255]);
248
-
249
- const strictMatch = await imagesMatch(redImage, blueImage, {
250
- maxDiffPercentage: 50,
251
- });
252
- const lenientMatch = await imagesMatch(redImage, blueImage, {
253
- maxDiffPercentage: 150,
254
- });
255
-
256
- expect(strictMatch).toBe(false);
257
- expect(lenientMatch).toBe(true);
258
- });
259
-
260
- it("should work with file paths", async () => {
261
- const redPath = path.join(testDir, "red.png");
262
- const checkerPath = path.join(testDir, "checker.png");
263
-
264
- const matches = await imagesMatch(redPath, checkerPath);
265
-
266
- expect(matches).toBe(false);
267
- });
268
-
269
- it("should pass through compare options", async () => {
270
- const image1 = createSolidColorPNG(50, 50, [100, 100, 100, 255]);
271
- const image2 = createSolidColorPNG(50, 50, [105, 105, 105, 255]);
272
-
273
- const strictMatch = await imagesMatch(image1, image2, {
274
- maxDiffPercentage: 50,
275
- threshold: 0.01,
276
- });
277
- const lenientMatch = await imagesMatch(image1, image2, {
278
- maxDiffPercentage: 50,
279
- threshold: 0.5,
280
- });
281
-
282
- // With lenient threshold, more pixels should be considered "same"
283
- expect(lenientMatch).toBe(true);
284
- expect(strictMatch).toBe(false);
285
- });
286
- });
287
-
288
- describe("saveDiffImage", () => {
289
- it("should save diff image to file", async () => {
290
- const redImage = createSolidColorPNG(50, 50, [255, 0, 0, 255]);
291
- const blueImage = createSolidColorPNG(50, 50, [0, 0, 255, 255]);
292
-
293
- const result = await compareImages(redImage, blueImage, true);
294
- const outputPath = path.join(testDir, "diff-output.png");
295
-
296
- saveDiffImage(result, outputPath);
297
-
298
- expect(fs.existsSync(outputPath)).toBe(true);
299
-
300
- // Verify the saved file is a valid PNG
301
- const savedBuffer = fs.readFileSync(outputPath);
302
- expect(() => PNG.sync.read(savedBuffer)).not.toThrow();
303
-
304
- // Clean up
305
- fs.unlinkSync(outputPath);
306
- });
307
-
308
- it("should throw error when no diff buffer available", () => {
309
- const result: CompareResult = {
310
- numDiffPixels: 0,
311
- totalPixels: 100,
312
- percentDifference: 0,
313
- passed: true,
314
- differentSizes: false,
315
- // diffBuffer is undefined
316
- };
317
-
318
- expect(() => saveDiffImage(result, "test.png")).toThrow(
319
- "No diff buffer available in comparison result",
320
- );
321
- });
322
- });
323
-
324
- describe("error handling", () => {
325
- it("should handle non-existent file paths", async () => {
326
- const nonExistentPath = path.join(testDir, "does-not-exist.png");
327
- const validImage = createSolidColorPNG(50, 50, [255, 0, 0, 255]);
328
-
329
- await expect(
330
- compareImages(nonExistentPath, validImage),
331
- ).rejects.toThrow();
332
- });
333
-
334
- it("should handle invalid image buffers", async () => {
335
- const invalidBuffer = Buffer.from("not a png");
336
- const validImage = createSolidColorPNG(50, 50, [255, 0, 0, 255]);
337
-
338
- await expect(compareImages(invalidBuffer, validImage)).rejects.toThrow();
339
- });
340
- });
341
-
342
- describe("edge cases", () => {
343
- it("should handle 1x1 pixel images", async () => {
344
- const image1 = createSolidColorPNG(1, 1, [255, 0, 0, 255]);
345
- const image2 = createSolidColorPNG(1, 1, [0, 0, 255, 255]);
346
-
347
- const result = await compareImages(image1, image2);
348
-
349
- expect(result.totalPixels).toBe(1);
350
- expect(result.numDiffPixels).toBe(1);
351
- expect(result.percentDifference).toBe(100);
352
- });
353
-
354
- it("should handle very large difference percentages", async () => {
355
- const redImage = createSolidColorPNG(10, 10, [255, 0, 0, 255]);
356
- const blueImage = createSolidColorPNG(10, 10, [0, 0, 255, 255]);
357
-
358
- const result = await compareImages(redImage, blueImage, false);
359
-
360
- expect(result.passed).toBe(false);
361
- expect(result.percentDifference).toBe(100);
362
- });
363
-
364
- it("should handle zero difference threshold", async () => {
365
- const image = createSolidColorPNG(10, 10, [255, 0, 0, 255]);
366
-
367
- const result = await compareImages(image, image, false, {
368
- maxDiffPercentage: 0,
369
- });
370
-
371
- expect(result.passed).toBe(true);
372
- expect(result.percentDifference).toBe(0);
373
- });
374
- });
375
- });