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.
@@ -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,CA6DlF,CAAA"}
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(subject, info.baselinePath);
25
+ await writeSnapshot(info.baselinePath, subject);
26
26
  }
27
27
  else {
28
- await takeSnapshotByBrowser(context, subject, info.baselinePath, options);
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
- const diffBase64 = PNG.sync.write(diffImage).toString('base64');
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
- return Buffer.from(await writeSnapshot(subject, filePath), 'base64');
65
+ await writeSnapshot(filePath, subject);
66
+ return Buffer.from(subject, 'base64');
67
67
  }
68
- return takeSnapshotByBrowser(context, subject, filePath, options);
68
+ return takeSnapshotByBrowser(context, filePath, subject, options);
69
69
  }
70
- async function takeSnapshotByBrowser(context, subject, filePath, options) {
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(subject, filePath) {
77
+ async function writeSnapshot(filePath, subject) {
78
78
  await mkdirp(dirname(filePath));
79
- await file.writeFileBase64(filePath, subject);
80
- return subject;
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))
@@ -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
- writeFileBase64(filePath: string, data: string): Promise<void>;
4
+ writeFile: typeof writeFile;
4
5
  existFile(filePath: string): Promise<boolean>;
5
6
  };
6
7
  //# sourceMappingURL=file.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/server/file.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI;0BACY,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;8BAGtC,MAAM,QAAQ,MAAM;wBAG1B,MAAM;CAK1B,CAAA"}
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"}
@@ -3,9 +3,7 @@ export const file = {
3
3
  async tryReadFile(filePath) {
4
4
  return readFile(filePath).catch(() => undefined);
5
5
  },
6
- writeFileBase64(filePath, data) {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-plugin-vis",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Vitest visual testing plugin",
5
5
  "keywords": [
6
6
  "image-snapshot",
@@ -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(subject, info.baselinePath)
53
+ await writeSnapshot(info.baselinePath, subject)
54
54
  } else {
55
- await takeSnapshotByBrowser(context, subject, info.baselinePath, options)
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
- const diffBase64 = PNG.sync.write(diffImage).toString('base64')
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
- return Buffer.from(await writeSnapshot(subject, filePath), 'base64')
108
+ await writeSnapshot(filePath, subject)
109
+ return Buffer.from(subject, 'base64')
110
110
  }
111
- return takeSnapshotByBrowser(context, subject, filePath, options)
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(subject: string, filePath: string) {
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.writeFileBase64(filePath, subject)
130
- return subject
133
+ await file.writeFile(filePath, subject)
131
134
  }
132
135
 
133
136
  function alignImageSizes(baseline: PNG, result: PNG) {
@@ -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
- writeFileBase64(filePath: string, data: string) {
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())