@histoire/plugin-screenshot 0.15.7 → 0.15.9
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 +22 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +9 -2
- package/package.json +3 -3
- package/src/index.ts +14 -2
package/README.md
CHANGED
|
@@ -18,3 +18,25 @@ export default defineConfig({
|
|
|
18
18
|
],
|
|
19
19
|
})
|
|
20
20
|
```
|
|
21
|
+
|
|
22
|
+
## Setting Up Chrome Linux Sandbox
|
|
23
|
+
|
|
24
|
+
If you get an error like No usable sandbox! or Running as root without --no-sandbox is not supported, you need to properly set up sandboxing on your Linux instance.
|
|
25
|
+
Alternatively, if you completely trust the content, you can disable sandboxing (strongly discouraged):
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
ref. https://github.com/sindresorhus/capture-website#faq
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
import { defineConfig } from 'histoire'
|
|
32
|
+
import { HstScreenshot } from '@histoire/plugin-screenshot'
|
|
33
|
+
|
|
34
|
+
export default defineConfig({
|
|
35
|
+
plugins: [
|
|
36
|
+
HstScreenshot({
|
|
37
|
+
launchOptionsArgs: ['--no-sandbox', '--disable-setuid-sandbox'],
|
|
38
|
+
}),
|
|
39
|
+
],
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,10 @@ export interface ScreenshotPluginOptions {
|
|
|
31
31
|
* Presets for each screenshot.
|
|
32
32
|
*/
|
|
33
33
|
presets?: ScreenshotPresets[];
|
|
34
|
+
/**
|
|
35
|
+
* Args for puppeteer
|
|
36
|
+
*/
|
|
37
|
+
launchOptionsArgs?: string[];
|
|
34
38
|
}
|
|
35
39
|
export declare function HstScreenshot(options?: ScreenshotPluginOptions): Plugin;
|
|
36
40
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -33,12 +33,19 @@ export function HstScreenshot(options = {}) {
|
|
|
33
33
|
}
|
|
34
34
|
console.log('Rendering screenshot for', file, 'title:', story.title, 'variant:', variant.id, 'title:', variant.title);
|
|
35
35
|
for (const preset of finalOptions.presets) {
|
|
36
|
-
|
|
36
|
+
const launchOptions = finalOptions.launchOptionsArgs
|
|
37
|
+
? {
|
|
38
|
+
args: finalOptions.launchOptionsArgs,
|
|
39
|
+
}
|
|
40
|
+
: {};
|
|
41
|
+
const captureWebsiteFileOptions = {
|
|
37
42
|
overwrite: true,
|
|
38
43
|
width: preset.width,
|
|
39
44
|
height: preset.height,
|
|
40
45
|
fullPage: true,
|
|
41
|
-
|
|
46
|
+
launchOptions,
|
|
47
|
+
};
|
|
48
|
+
await captureWebsite.file(url, path.join(finalOptions.saveFolder, `${story.id}-${variant.id}-${preset.width}x${preset.height}.png`), captureWebsiteFileOptions);
|
|
42
49
|
}
|
|
43
50
|
});
|
|
44
51
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@histoire/plugin-screenshot",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.9",
|
|
4
4
|
"description": "Histoire plugin to take screenshots for visual regression testing",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/node": "^17.0.32",
|
|
33
33
|
"typescript": "^4.9.5",
|
|
34
|
-
"histoire": "0.15.
|
|
34
|
+
"histoire": "0.15.9"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"histoire": "^0.15.
|
|
37
|
+
"histoire": "^0.15.8"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "rimraf dist && tsc -d",
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import path from 'pathe'
|
|
|
2
2
|
import fs from 'fs-extra'
|
|
3
3
|
import type { Plugin } from 'histoire'
|
|
4
4
|
import { defu } from 'defu'
|
|
5
|
+
import type { FileOptions } from 'capture-website'
|
|
5
6
|
|
|
6
7
|
interface ScreenshotPresets {
|
|
7
8
|
/**
|
|
@@ -27,6 +28,10 @@ export interface ScreenshotPluginOptions {
|
|
|
27
28
|
* Presets for each screenshot.
|
|
28
29
|
*/
|
|
29
30
|
presets?: ScreenshotPresets[]
|
|
31
|
+
/**
|
|
32
|
+
* Args for puppeteer
|
|
33
|
+
*/
|
|
34
|
+
launchOptionsArgs?: string[]
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
const defaultOptions: ScreenshotPluginOptions = {
|
|
@@ -64,12 +69,19 @@ export function HstScreenshot (options: ScreenshotPluginOptions = {}): Plugin {
|
|
|
64
69
|
}
|
|
65
70
|
console.log('Rendering screenshot for', file, 'title:', story.title, 'variant:', variant.id, 'title:', variant.title)
|
|
66
71
|
for (const preset of finalOptions.presets) {
|
|
67
|
-
|
|
72
|
+
const launchOptions = finalOptions.launchOptionsArgs
|
|
73
|
+
? {
|
|
74
|
+
args: finalOptions.launchOptionsArgs,
|
|
75
|
+
}
|
|
76
|
+
: {}
|
|
77
|
+
const captureWebsiteFileOptions: FileOptions = {
|
|
68
78
|
overwrite: true,
|
|
69
79
|
width: preset.width,
|
|
70
80
|
height: preset.height,
|
|
71
81
|
fullPage: true,
|
|
72
|
-
|
|
82
|
+
launchOptions,
|
|
83
|
+
}
|
|
84
|
+
await captureWebsite.file(url, path.join(finalOptions.saveFolder, `${story.id}-${variant.id}-${preset.width}x${preset.height}.png`), captureWebsiteFileOptions)
|
|
73
85
|
}
|
|
74
86
|
})
|
|
75
87
|
},
|