@histoire/plugin-percy 0.17.16 → 1.0.0-alpha.1
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 +1 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/package.json +14 -14
- package/src/index.ts +14 -14
- package/tsconfig.json +17 -17
package/README.md
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
You need the [Percy CLI](https://docs.percy.io/docs/cli-overview) installed to be able to send snapshots to Percy.
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
```bash
|
|
7
6
|
pnpm add -D @histoire/plugin-percy
|
|
8
7
|
```
|
|
@@ -10,8 +9,8 @@ pnpm add -D @histoire/plugin-percy
|
|
|
10
9
|
Add the plugin in histoire config:
|
|
11
10
|
|
|
12
11
|
```js
|
|
13
|
-
import { defineConfig } from 'histoire'
|
|
14
12
|
import { HstPercy } from '@histoire/plugin-percy'
|
|
13
|
+
import { defineConfig } from 'histoire'
|
|
15
14
|
|
|
16
15
|
export default defineConfig({
|
|
17
16
|
plugins: [
|
package/dist/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface PercySnapshotOptions {
|
|
|
22
22
|
userAgent: string;
|
|
23
23
|
}>;
|
|
24
24
|
}
|
|
25
|
-
export
|
|
25
|
+
export interface PagePayload {
|
|
26
26
|
file: string;
|
|
27
27
|
story: {
|
|
28
28
|
title: string;
|
|
@@ -31,7 +31,7 @@ export type PagePayload = {
|
|
|
31
31
|
id: string;
|
|
32
32
|
title: string;
|
|
33
33
|
};
|
|
34
|
-
}
|
|
34
|
+
}
|
|
35
35
|
type ContructorOption<T extends object | number> = T | ((payload: PagePayload) => T);
|
|
36
36
|
export interface PercyPluginOptions {
|
|
37
37
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { fetchPercyDOM, isPercyEnabled, postSnapshot } from '@percy/sdk-utils';
|
|
1
4
|
import { defu } from 'defu';
|
|
2
5
|
import path from 'pathe';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { createRequire } from 'node:module';
|
|
5
|
-
import { isPercyEnabled, fetchPercyDOM, postSnapshot } from '@percy/sdk-utils';
|
|
6
6
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
7
|
const require = createRequire(import.meta.url);
|
|
8
8
|
const defaultOptions = {
|
|
@@ -47,7 +47,7 @@ export function HstPercy(options = {}) {
|
|
|
47
47
|
const percyOptions = resolveOptions(finalOptions.percyOptions, payload);
|
|
48
48
|
const page = await browser.newPage();
|
|
49
49
|
await page.goto(url, pptrOptions);
|
|
50
|
-
await new Promise(
|
|
50
|
+
await new Promise(resolve => setTimeout(resolve, pptrWait));
|
|
51
51
|
if (finalOptions.beforeSnapshot) {
|
|
52
52
|
const result = await finalOptions.beforeSnapshot(page, payload);
|
|
53
53
|
if (result === false) {
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@histoire/plugin-percy",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.0-alpha.1",
|
|
4
5
|
"description": "Histoire plugin to take screenshots with Percy for visual regression testing",
|
|
5
|
-
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Guillaume Chau"
|
|
8
8
|
},
|
|
9
|
+
"license": "MIT",
|
|
9
10
|
"repository": {
|
|
10
11
|
"url": "https://github.com/Akryum/histoire.git",
|
|
11
12
|
"type": "git",
|
|
@@ -14,7 +15,6 @@
|
|
|
14
15
|
"publishConfig": {
|
|
15
16
|
"access": "public"
|
|
16
17
|
},
|
|
17
|
-
"type": "module",
|
|
18
18
|
"exports": {
|
|
19
19
|
".": "./dist/index.js",
|
|
20
20
|
"./*": "./*"
|
|
@@ -22,20 +22,20 @@
|
|
|
22
22
|
"main": "./dist/index.js",
|
|
23
23
|
"module": "./dist/index.js",
|
|
24
24
|
"types": "./dist/index.d.ts",
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"histoire": "^1.0.0-alpha.1"
|
|
27
|
+
},
|
|
25
28
|
"dependencies": {
|
|
26
|
-
"@percy/sdk-utils": "^1.
|
|
27
|
-
"defu": "^6.1.
|
|
28
|
-
"fs-extra": "^
|
|
29
|
-
"pathe": "^1.1.
|
|
30
|
-
"puppeteer": "^
|
|
29
|
+
"@percy/sdk-utils": "^1.30.4",
|
|
30
|
+
"defu": "^6.1.4",
|
|
31
|
+
"fs-extra": "^11.2.0",
|
|
32
|
+
"pathe": "^1.1.2",
|
|
33
|
+
"puppeteer": "^23.10.1"
|
|
31
34
|
},
|
|
32
35
|
"devDependencies": {
|
|
33
|
-
"@types/node": "^
|
|
34
|
-
"typescript": "
|
|
35
|
-
"histoire": "0.
|
|
36
|
-
},
|
|
37
|
-
"peerDependencies": {
|
|
38
|
-
"histoire": "^0.17.16"
|
|
36
|
+
"@types/node": "^22.10.1",
|
|
37
|
+
"typescript": "5.6.3",
|
|
38
|
+
"histoire": "1.0.0-alpha.1"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "rimraf dist && tsc -d",
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Plugin } from 'histoire'
|
|
2
|
+
import type { Page, WaitForOptions } from 'puppeteer'
|
|
3
|
+
import { createRequire } from 'node:module'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
import { fetchPercyDOM, isPercyEnabled, postSnapshot } from '@percy/sdk-utils'
|
|
2
6
|
import { defu } from 'defu'
|
|
3
7
|
import path from 'pathe'
|
|
4
|
-
import { fileURLToPath } from 'node:url'
|
|
5
|
-
import { createRequire } from 'node:module'
|
|
6
|
-
import { isPercyEnabled, fetchPercyDOM, postSnapshot } from '@percy/sdk-utils'
|
|
7
|
-
import type { JSONObject, Page, WaitForOptions } from 'puppeteer'
|
|
8
8
|
|
|
9
9
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
10
10
|
const require = createRequire(import.meta.url)
|
|
@@ -32,15 +32,15 @@ export interface PercySnapshotOptions {
|
|
|
32
32
|
}>
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export
|
|
35
|
+
export interface PagePayload {
|
|
36
36
|
file: string
|
|
37
37
|
story: { title: string }
|
|
38
38
|
variant: { id: string, title: string }
|
|
39
|
-
}
|
|
39
|
+
}
|
|
40
40
|
|
|
41
41
|
type ContructorOption<T extends object | number> =
|
|
42
42
|
| T
|
|
43
|
-
| ((payload: PagePayload) => T)
|
|
43
|
+
| ((payload: PagePayload) => T)
|
|
44
44
|
|
|
45
45
|
export interface PercyPluginOptions {
|
|
46
46
|
/**
|
|
@@ -61,9 +61,9 @@ export interface PercyPluginOptions {
|
|
|
61
61
|
* Navigation Parameter
|
|
62
62
|
*/
|
|
63
63
|
pptrOptions?: ContructorOption<
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
WaitForOptions & {
|
|
65
|
+
referer?: string
|
|
66
|
+
}
|
|
67
67
|
>
|
|
68
68
|
|
|
69
69
|
/**
|
|
@@ -85,14 +85,14 @@ const defaultOptions: PercyPluginOptions = {
|
|
|
85
85
|
pptrOptions: {},
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
function resolveOptions<T extends object | number>
|
|
88
|
+
function resolveOptions<T extends object | number>(
|
|
89
89
|
option: ContructorOption<T>,
|
|
90
90
|
payload: PagePayload,
|
|
91
91
|
): T {
|
|
92
92
|
return typeof option === 'function' ? option(payload) : option
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
export function HstPercy
|
|
95
|
+
export function HstPercy(options: PercyPluginOptions = {}): Plugin {
|
|
96
96
|
const finalOptions: PercyPluginOptions = defu(options, defaultOptions)
|
|
97
97
|
return {
|
|
98
98
|
name: '@histoire/plugin-percy',
|
|
@@ -134,7 +134,7 @@ export function HstPercy (options: PercyPluginOptions = {}): Plugin {
|
|
|
134
134
|
const page = await browser.newPage()
|
|
135
135
|
await page.goto(url, pptrOptions)
|
|
136
136
|
|
|
137
|
-
await new Promise(
|
|
137
|
+
await new Promise(resolve => setTimeout(resolve, pptrWait))
|
|
138
138
|
|
|
139
139
|
if (finalOptions.beforeSnapshot) {
|
|
140
140
|
const result = await finalOptions.beforeSnapshot(page, payload)
|
|
@@ -148,7 +148,7 @@ export function HstPercy (options: PercyPluginOptions = {}): Plugin {
|
|
|
148
148
|
const domSnapshot = await page.evaluate((opts) => {
|
|
149
149
|
// @ts-expect-error window global var
|
|
150
150
|
return window.PercyDOM.serialize(opts)
|
|
151
|
-
}, percyOptions
|
|
151
|
+
}, percyOptions)
|
|
152
152
|
await postSnapshot({
|
|
153
153
|
...percyOptions,
|
|
154
154
|
environmentInfo: ENV_INFO,
|
package/tsconfig.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"target": "ESNext",
|
|
4
|
+
// Volar
|
|
5
|
+
"jsx": "preserve",
|
|
6
|
+
"lib": [
|
|
7
|
+
"ESNext",
|
|
8
|
+
"DOM"
|
|
9
|
+
],
|
|
10
|
+
"rootDir": "src",
|
|
4
11
|
"module": "ESNext",
|
|
5
12
|
"moduleResolution": "node",
|
|
6
|
-
"outDir": "dist",
|
|
7
|
-
"rootDir": "src",
|
|
8
|
-
"allowSyntheticDefaultImports": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"removeComments": false,
|
|
11
13
|
"resolveJsonModule": true,
|
|
12
|
-
"skipLibCheck": true,
|
|
13
14
|
"types": [
|
|
14
15
|
"node"
|
|
15
16
|
],
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
],
|
|
20
|
-
"sourceMap": false,
|
|
21
|
-
"preserveWatchOutput": true,
|
|
17
|
+
"strictBindCallApply": true,
|
|
18
|
+
"strictFunctionTypes": true,
|
|
19
|
+
"alwaysStrict": true,
|
|
22
20
|
// Strict
|
|
23
21
|
"noImplicitAny": false,
|
|
24
22
|
"noImplicitThis": true,
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
"
|
|
23
|
+
"outDir": "dist",
|
|
24
|
+
"removeComments": false,
|
|
25
|
+
"sourceMap": false,
|
|
26
|
+
"allowSyntheticDefaultImports": true,
|
|
27
|
+
"esModuleInterop": true,
|
|
28
|
+
"skipLibCheck": true,
|
|
29
|
+
"preserveWatchOutput": true
|
|
30
30
|
},
|
|
31
31
|
"include": [
|
|
32
32
|
"src"
|