vitest-plugin-vis 1.0.3 → 1.0.4
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/esm/server/commands/match_image_snapshot.d.ts.map +1 -1
- package/esm/server/commands/match_image_snapshot.js +13 -10
- package/esm/server/file.d.ts +2 -1
- package/esm/server/file.d.ts.map +1 -1
- package/esm/server/file.js +1 -3
- package/package.json +1 -1
- package/src/server/commands/match_image_snapshot.ts +13 -10
- package/src/server/file.ts +1 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/server/commands/match_image_snapshot.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAyB,MAAM,aAAa,CAAA;AAIxE,OAAO,KAAK,EACX,2BAA2B,EAC3B,sBAAsB,EACtB,2BAA2B,EAC3B,MAAM,uBAAuB,CAAA;AAM9B,MAAM,WAAW,yBAAyB;IACzC,kBAAkB,EAAE,CACnB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS,KAC3C,OAAO,CAAC,IAAI,CAAC,CAAA;CAClB;AAED,MAAM,WAAW,yBAChB,SAAQ,2BAA2B,EAClC,sBAAsB,EACtB,2BAA2B;IAC5B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACnC;AAED,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAC9C;IAAC,MAAM,EAAE,MAAM;IAAE,OAAO,EAAE,MAAM;IAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS;CAAC,
|
|
1
|
+
{"version":3,"file":"match_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/server/commands/match_image_snapshot.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAyB,MAAM,aAAa,CAAA;AAIxE,OAAO,KAAK,EACX,2BAA2B,EAC3B,sBAAsB,EACtB,2BAA2B,EAC3B,MAAM,uBAAuB,CAAA;AAM9B,MAAM,WAAW,yBAAyB;IACzC,kBAAkB,EAAE,CACnB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS,KAC3C,OAAO,CAAC,IAAI,CAAC,CAAA;CAClB;AAED,MAAM,WAAW,yBAChB,SAAQ,2BAA2B,EAClC,sBAAsB,EACtB,2BAA2B;IAC5B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACnC;AAED,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAC9C;IAAC,MAAM,EAAE,MAAM;IAAE,OAAO,EAAE,MAAM;IAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS;CAAC,CA4DlF,CAAA"}
|
|
@@ -22,10 +22,10 @@ export const matchImageSnapshot = async (context, taskId, subject, options) => {
|
|
|
22
22
|
const baselineBuffer = await file.tryReadFile(info.baselinePath);
|
|
23
23
|
if (!baselineBuffer) {
|
|
24
24
|
if (isBase64String(subject)) {
|
|
25
|
-
await writeSnapshot(
|
|
25
|
+
await writeSnapshot(info.baselinePath, subject);
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
-
await takeSnapshotByBrowser(context,
|
|
28
|
+
await takeSnapshotByBrowser(context, info.baselinePath, subject, options);
|
|
29
29
|
}
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
@@ -45,8 +45,7 @@ export const matchImageSnapshot = async (context, taskId, subject, options) => {
|
|
|
45
45
|
Expected: ${resolve(context.project.runner.root, info.baselinePath)}
|
|
46
46
|
Actual: ${resolve(context.project.runner.root, info.resultPath)}`);
|
|
47
47
|
}
|
|
48
|
-
|
|
49
|
-
await writeSnapshot(diffBase64, info.diffPath);
|
|
48
|
+
await writeSnapshotBuffer(info.diffPath, diffImage.data);
|
|
50
49
|
throw new Error(dedent `Snapshot \`${taskId}\` mismatched
|
|
51
50
|
|
|
52
51
|
${options?.failureThreshold
|
|
@@ -63,21 +62,25 @@ export const matchImageSnapshot = async (context, taskId, subject, options) => {
|
|
|
63
62
|
};
|
|
64
63
|
async function takeSnapshot(context, subject, filePath, options) {
|
|
65
64
|
if (isBase64String(subject)) {
|
|
66
|
-
|
|
65
|
+
await writeSnapshot(filePath, subject);
|
|
66
|
+
return Buffer.from(subject, 'base64');
|
|
67
67
|
}
|
|
68
|
-
return takeSnapshotByBrowser(context,
|
|
68
|
+
return takeSnapshotByBrowser(context, filePath, subject, options);
|
|
69
69
|
}
|
|
70
|
-
async function takeSnapshotByBrowser(context,
|
|
70
|
+
async function takeSnapshotByBrowser(context, filePath, subject, options) {
|
|
71
71
|
await mkdirp(dirname(filePath));
|
|
72
72
|
const browser = browserApi(context);
|
|
73
73
|
return browser.takeScreenshot(filePath, subject, {
|
|
74
74
|
timeout: options?.timeout,
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
|
-
async function writeSnapshot(
|
|
77
|
+
async function writeSnapshot(filePath, subject) {
|
|
78
78
|
await mkdirp(dirname(filePath));
|
|
79
|
-
await file.
|
|
80
|
-
|
|
79
|
+
await file.writeFile(filePath, subject, { encoding: 'base64' });
|
|
80
|
+
}
|
|
81
|
+
async function writeSnapshotBuffer(filePath, subject) {
|
|
82
|
+
await mkdirp(dirname(filePath));
|
|
83
|
+
await file.writeFile(filePath, subject);
|
|
81
84
|
}
|
|
82
85
|
function alignImageSizes(baseline, result) {
|
|
83
86
|
if (isSameSize(baseline, result))
|
package/esm/server/file.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
1
2
|
export declare const file: {
|
|
2
3
|
tryReadFile(filePath: string): Promise<Buffer | undefined>;
|
|
3
|
-
|
|
4
|
+
writeFile: typeof writeFile;
|
|
4
5
|
existFile(filePath: string): Promise<boolean>;
|
|
5
6
|
};
|
|
6
7
|
//# sourceMappingURL=file.d.ts.map
|
package/esm/server/file.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/server/file.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/server/file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAE5D,eAAO,MAAM,IAAI;0BACY,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;;wBAI5C,MAAM;CAK1B,CAAA"}
|
package/esm/server/file.js
CHANGED
|
@@ -3,9 +3,7 @@ export const file = {
|
|
|
3
3
|
async tryReadFile(filePath) {
|
|
4
4
|
return readFile(filePath).catch(() => undefined);
|
|
5
5
|
},
|
|
6
|
-
|
|
7
|
-
return writeFile(filePath, data, { encoding: 'base64' });
|
|
8
|
-
},
|
|
6
|
+
writeFile,
|
|
9
7
|
existFile(filePath) {
|
|
10
8
|
return stat(filePath)
|
|
11
9
|
.then((s) => s.isFile())
|
package/package.json
CHANGED
|
@@ -50,9 +50,9 @@ export const matchImageSnapshot: BrowserCommand<
|
|
|
50
50
|
const baselineBuffer = await file.tryReadFile(info.baselinePath)
|
|
51
51
|
if (!baselineBuffer) {
|
|
52
52
|
if (isBase64String(subject)) {
|
|
53
|
-
await writeSnapshot(
|
|
53
|
+
await writeSnapshot(info.baselinePath, subject)
|
|
54
54
|
} else {
|
|
55
|
-
await takeSnapshotByBrowser(context,
|
|
55
|
+
await takeSnapshotByBrowser(context, info.baselinePath, subject, options)
|
|
56
56
|
}
|
|
57
57
|
return
|
|
58
58
|
}
|
|
@@ -77,8 +77,7 @@ export const matchImageSnapshot: BrowserCommand<
|
|
|
77
77
|
)
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
await writeSnapshot(diffBase64, info.diffPath)
|
|
80
|
+
await writeSnapshotBuffer(info.diffPath, diffImage.data)
|
|
82
81
|
|
|
83
82
|
throw new Error(
|
|
84
83
|
dedent`Snapshot \`${taskId}\` mismatched
|
|
@@ -106,15 +105,16 @@ async function takeSnapshot(
|
|
|
106
105
|
options: ImageSnapshotTimeoutOptions | undefined,
|
|
107
106
|
) {
|
|
108
107
|
if (isBase64String(subject)) {
|
|
109
|
-
|
|
108
|
+
await writeSnapshot(filePath, subject)
|
|
109
|
+
return Buffer.from(subject, 'base64')
|
|
110
110
|
}
|
|
111
|
-
return takeSnapshotByBrowser(context,
|
|
111
|
+
return takeSnapshotByBrowser(context, filePath, subject, options)
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
async function takeSnapshotByBrowser(
|
|
115
115
|
context: BrowserCommandContext,
|
|
116
|
-
subject: string,
|
|
117
116
|
filePath: string,
|
|
117
|
+
subject: string,
|
|
118
118
|
options: ImageSnapshotTimeoutOptions | undefined,
|
|
119
119
|
) {
|
|
120
120
|
await mkdirp(dirname(filePath))
|
|
@@ -124,10 +124,13 @@ async function takeSnapshotByBrowser(
|
|
|
124
124
|
})
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
async function writeSnapshot(
|
|
127
|
+
async function writeSnapshot(filePath: string, subject: string) {
|
|
128
|
+
await mkdirp(dirname(filePath))
|
|
129
|
+
await file.writeFile(filePath, subject, { encoding: 'base64' })
|
|
130
|
+
}
|
|
131
|
+
async function writeSnapshotBuffer(filePath: string, subject: Buffer) {
|
|
128
132
|
await mkdirp(dirname(filePath))
|
|
129
|
-
await file.
|
|
130
|
-
return subject
|
|
133
|
+
await file.writeFile(filePath, subject)
|
|
131
134
|
}
|
|
132
135
|
|
|
133
136
|
function alignImageSizes(baseline: PNG, result: PNG) {
|
package/src/server/file.ts
CHANGED
|
@@ -4,9 +4,7 @@ export const file = {
|
|
|
4
4
|
async tryReadFile(filePath: string): Promise<Buffer | undefined> {
|
|
5
5
|
return readFile(filePath).catch(() => undefined)
|
|
6
6
|
},
|
|
7
|
-
|
|
8
|
-
return writeFile(filePath, data, { encoding: 'base64' })
|
|
9
|
-
},
|
|
7
|
+
writeFile,
|
|
10
8
|
existFile(filePath: string) {
|
|
11
9
|
return stat(filePath)
|
|
12
10
|
.then((s) => s.isFile())
|