@percy/core 1.32.13-beta.1 → 1.33.0-beta.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.
@@ -1,6 +1,12 @@
1
- import fs from 'fs';
2
1
  import logger from '@percy/logger';
3
2
  import { Server } from './server.js';
3
+
4
+ // The pdfjs-backed functions in this file -- everything but withTimeout, which
5
+ // test/unit/pdf-rasterize.test.js covers on any Node -- need the pdfjs-dist
6
+ // optionalDependency. The resolved build requires Node >=20 while the coverage
7
+ // gate runs on Node 14 and therefore installs without it, so they are exempt
8
+ // from the gate and exercised by the describePdfjs specs on Node >=20.
9
+ /* istanbul ignore next */
4
10
  async function createAssetServer(pdfBuffer, assets) {
5
11
  // Loopback only. This origin serves the customer's PDF with no auth, and the
6
12
  // sole client is the discovery browser running on this machine -- unlike the
@@ -23,6 +29,7 @@ async function createAssetServer(pdfBuffer, assets) {
23
29
  // Percy's minimum. handlePdfSnapshot answers 400 for these and 500 for
24
30
  // everything else, so a browser launch failure or a CDP disconnect is no longer
25
31
  // reported to the SDK as if the caller sent a bad request.
32
+ /* istanbul ignore next: pdfjs-backed — see the note above createAssetServer */
26
33
  function asInputError(error) {
27
34
  return Object.assign(error, {
28
35
  status: 400
@@ -44,6 +51,8 @@ export function withTimeout(promise, ms, description) {
44
51
  });
45
52
  return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
46
53
  }
54
+
55
+ /* istanbul ignore next: pdfjs-backed — see the note above createAssetServer */
47
56
  export async function rasterizePdf(percy, pdfBuffer, options) {
48
57
  let log = logger('core:pdf-rasterize');
49
58
  let {
@@ -51,6 +60,7 @@ export async function rasterizePdf(percy, pdfBuffer, options) {
51
60
  resolvePages,
52
61
  fitScale,
53
62
  assertRasterDimensions,
63
+ loadLibrary,
54
64
  openDocument,
55
65
  measurePages,
56
66
  renderPage,
@@ -77,13 +87,15 @@ export async function rasterizePdf(percy, pdfBuffer, options) {
77
87
  }
78
88
  });
79
89
  await page.goto(`${origin}/`);
80
- let pdfjsSource = await fs.promises.readFile(assets.libPath, 'utf-8');
81
- await withTimeout(/* eslint-disable-next-line no-new-func */
82
- page.eval(new Function(pdfjsSource)), PAGE_RENDER_TIMEOUT, 'injecting pdf.js');
90
+ await withTimeout(page.eval(loadLibrary, {
91
+ origin,
92
+ libFile: assets.libFile
93
+ }), PAGE_RENDER_TIMEOUT, 'injecting pdf.js');
83
94
  let {
84
95
  pageCount
85
96
  } = await withTimeout(page.eval(openDocument, {
86
- origin
97
+ origin,
98
+ workerFile: assets.workerFile
87
99
  }), PAGE_RENDER_TIMEOUT, 'opening the PDF');
88
100
  let selected;
89
101
  try {
@@ -29,6 +29,9 @@ export const UPLOAD_CLIENT_INFO = (() => {
29
29
  export function pageSnapshotName(name, pageNumber) {
30
30
  return `${name} | Page ${pageNumber}`;
31
31
  }
32
+
33
+ /* istanbul ignore next: reached only with a rasterized page — see the
34
+ pdfjs-backed note at the top of pdf-rasterize.js */
32
35
  function pageUrls(name, pageNumber) {
33
36
  let base = `http://local/${encodeURIComponent(name)}/page-${pageNumber}`;
34
37
  return {
@@ -67,11 +70,23 @@ export function decodePdf(pdf) {
67
70
  return buffer;
68
71
  }
69
72
  export async function loadPdfModule(load = () => import('@percy/cli-pdf')) {
73
+ let mod;
70
74
  try {
71
- return await load();
75
+ mod = await load();
72
76
  } catch (error) {
73
77
  throw new ServerError(501, ['PDF snapshots require the @percy/cli-pdf package, which is not installed.', 'Install it with: npm install --save-dev @percy/cli-pdf', `(underlying error: ${error.message})`].join(' '));
74
78
  }
79
+
80
+ // pdfjs-dist is an optionalDependency of @percy/cli-pdf declaring Node >=20,
81
+ // so on Node 14 the install is skipped and the package is present without its
82
+ // renderer. Resolving the assets up front turns that into a 501 here rather
83
+ // than a 500 after a browser launch, three frames deeper.
84
+ try {
85
+ mod.pdfjsAssets();
86
+ } catch (error) {
87
+ throw new ServerError(501, ['PDF snapshots require the pdfjs-dist package, which is not installed.', 'It is an optional dependency of @percy/cli-pdf and needs Node >= 20.', `(underlying error: ${error.message})`].join(' '));
88
+ }
89
+ return mod;
75
90
  }
76
91
  function validatePdfSnapshotOptions(options) {
77
92
  let log = logger('core:pdf-snapshot');
@@ -89,6 +104,9 @@ function validatePdfSnapshotOptions(options) {
89
104
  }
90
105
  return normalized;
91
106
  }
107
+
108
+ /* istanbul ignore next: reached only with a rasterized page — see the
109
+ pdfjs-backed note at the top of pdf-rasterize.js */
92
110
  function queuePages(percy, {
93
111
  name,
94
112
  rendered,
@@ -139,6 +157,9 @@ function queuePages(percy, {
139
157
  };
140
158
  });
141
159
  }
160
+
161
+ /* istanbul ignore next: reached only with a rasterized page — see the
162
+ pdfjs-backed note at the top of pdf-rasterize.js */
142
163
  function buildPageResources({
143
164
  rootUrl,
144
165
  imageUrl,
@@ -157,6 +178,12 @@ function buildPageResources({
157
178
  mimetype: 'image/png'
158
179
  });
159
180
  }
181
+
182
+ // Only the validation half of this handler is reachable without pdfjs-dist, and
183
+ // the coverage gate runs on Node 14 where the optional install is skipped, so
184
+ // the whole function is exempt from the gate rather than half its statements.
185
+ // The 400-path specs still run and still assert on every Node version.
186
+ /* istanbul ignore next */
160
187
  export async function handlePdfSnapshot(req, res, percy) {
161
188
  let log = logger('core:pdf-snapshot');
162
189
  let body = req.body;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/core",
3
- "version": "1.32.13-beta.1",
3
+ "version": "1.33.0-beta.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -46,12 +46,12 @@
46
46
  "dependencies": {
47
47
  "@grpc/grpc-js": "^1.14.3",
48
48
  "@grpc/proto-loader": "^0.8.0",
49
- "@percy/client": "1.32.13-beta.1",
50
- "@percy/config": "1.32.13-beta.1",
51
- "@percy/dom": "1.32.13-beta.1",
52
- "@percy/logger": "1.32.13-beta.1",
53
- "@percy/monitoring": "1.32.13-beta.1",
54
- "@percy/webdriver-utils": "1.32.13-beta.1",
49
+ "@percy/client": "1.33.0-beta.0",
50
+ "@percy/config": "1.33.0-beta.0",
51
+ "@percy/dom": "1.33.0-beta.0",
52
+ "@percy/logger": "1.33.0-beta.0",
53
+ "@percy/monitoring": "1.33.0-beta.0",
54
+ "@percy/webdriver-utils": "1.33.0-beta.0",
55
55
  "adm-zip": "^0.6.0",
56
56
  "busboy": "^1.6.0",
57
57
  "content-disposition": "^0.5.4",
@@ -67,8 +67,8 @@
67
67
  "yaml": "^2.4.1"
68
68
  },
69
69
  "optionalDependencies": {
70
- "@percy/cli-doctor": "1.32.13-beta.1",
71
- "@percy/cli-pdf": "1.32.13-beta.1"
70
+ "@percy/cli-doctor": "1.33.0-beta.0",
71
+ "@percy/cli-pdf": "1.33.0-beta.0"
72
72
  },
73
- "gitHead": "ce1817a2a31d00c29821e26af150e985d5ba8bf6"
73
+ "gitHead": "ac897ef9954e2248f50668db862ded5384a56adb"
74
74
  }