@poveste/plugin-screenshot 0.10.0 → 0.12.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 CHANGED
@@ -19,6 +19,30 @@ export default defineConfig({
19
19
  })
20
20
  ```
21
21
 
22
+ ## Where the screenshots go
23
+
24
+ By default the plugin writes one PNG per variant per responsive preset into `.poveste/screenshots`, inside your project:
25
+
26
+ ```
27
+ .poveste/screenshots/<story-id>-<variant-id>-<width>x<height>.png
28
+ ```
29
+
30
+ **Add that folder to your `.gitignore`.** It is build output, it is regenerated on every run, and one binary per variant adds up quickly — a book of any size will otherwise fill a commit the first time somebody runs `git add -A`.
31
+
32
+ ```gitignore
33
+ .poveste/
34
+ ```
35
+
36
+ Ignoring the whole `.poveste/` directory covers the built book as well. Set `saveFolder` if you would rather keep the screenshots somewhere else — a path you compare baselines from, for instance:
37
+
38
+ ```js
39
+ HstScreenshot({
40
+ saveFolder: 'tests/screenshots',
41
+ })
42
+ ```
43
+
44
+ That folder is yours to decide about: baselines you intend to commit belong in tracked storage, and the default does not.
45
+
22
46
  ## Setting Up Chrome Linux Sandbox
23
47
 
24
48
  If you get `No usable sandbox!` or `Running as root without --no-sandbox is not
package/dist/index.d.ts CHANGED
@@ -36,5 +36,14 @@ export interface ScreenshotPluginOptions {
36
36
  */
37
37
  launchOptionsArgs?: string[];
38
38
  }
39
+ /**
40
+ * The file one capture is written to.
41
+ *
42
+ * A variant with no explicit `id` is given `${story.id}-${n}`, so naming the
43
+ * file `${story.id}-${variant.id}` repeated the story id in full. The story id
44
+ * still has to be there for the named case: `default` and `one` are only unique
45
+ * within their own story.
46
+ */
47
+ export declare function screenshotFileName(storyId: string, variantId: string, width: number, height: number): string;
39
48
  export declare function HstScreenshot(options?: ScreenshotPluginOptions): Plugin;
40
49
  export {};
package/dist/index.js CHANGED
@@ -5,6 +5,19 @@ const defaultOptions = {
5
5
  saveFolder: '.poveste/screenshots',
6
6
  presets: [],
7
7
  };
8
+ /**
9
+ * The file one capture is written to.
10
+ *
11
+ * A variant with no explicit `id` is given `${story.id}-${n}`, so naming the
12
+ * file `${story.id}-${variant.id}` repeated the story id in full. The story id
13
+ * still has to be there for the named case: `default` and `one` are only unique
14
+ * within their own story.
15
+ */
16
+ export function screenshotFileName(storyId, variantId, width, height) {
17
+ const prefix = `${storyId}-`;
18
+ const variant = variantId.startsWith(prefix) ? variantId.slice(prefix.length) : variantId;
19
+ return `${storyId}-${variant}-${width}x${height}.png`;
20
+ }
8
21
  export function HstScreenshot(options = {}) {
9
22
  const finalOptions = defu(options, defaultOptions);
10
23
  if (!finalOptions.presets.length) {
@@ -45,7 +58,7 @@ export function HstScreenshot(options = {}) {
45
58
  fullPage: true,
46
59
  launchOptions,
47
60
  };
48
- await captureWebsite.file(url, path.join(finalOptions.saveFolder, `${story.id}-${variant.id}-${preset.width}x${preset.height}.png`), captureWebsiteFileOptions);
61
+ await captureWebsite.file(url, path.join(finalOptions.saveFolder, screenshotFileName(story.id, variant.id, preset.width, preset.height)), captureWebsiteFileOptions);
49
62
  }
50
63
  });
51
64
  },
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@poveste/plugin-screenshot",
3
3
  "type": "module",
4
- "version": "0.10.0",
4
+ "version": "0.12.0",
5
5
  "description": "Poveste plugin to take screenshots for visual regression testing",
6
6
  "author": {
7
- "name": "Sorin Gitlan"
7
+ "name": "Sorin Gitlan",
8
+ "url": "https://x.com/50rayn"
8
9
  },
9
10
  "license": "MIT",
10
11
  "homepage": "https://poveste.dev",
@@ -46,7 +47,7 @@
46
47
  "node": "^22.22.2 || ^24.15.0 || >=26.0.0"
47
48
  },
48
49
  "peerDependencies": {
49
- "poveste": "^0.10.0"
50
+ "poveste": "^0.12.0"
50
51
  },
51
52
  "dependencies": {
52
53
  "capture-website": "^4.2.0",
@@ -56,11 +57,14 @@
56
57
  },
57
58
  "devDependencies": {
58
59
  "@types/node": "^22.10.1",
60
+ "poveste": "0.12.0",
59
61
  "typescript": "5.6.3",
60
- "poveste": "0.10.0"
62
+ "vitest": "^4.1.10"
61
63
  },
62
64
  "scripts": {
63
65
  "build": "rimraf dist && tsc -d",
64
- "watch": "tsc -d -w --sourceMap"
66
+ "watch": "tsc -d -w --sourceMap",
67
+ "test": "vitest run",
68
+ "test:dev": "vitest"
65
69
  }
66
70
  }