Skip to content

Commit

Permalink
chore: add separate reference files for different platforms
Browse files Browse the repository at this point in the history
Turns out, generated PDFs differ slightly from platform to platform. As the previous reference file I generated comes from macOS, it fails when E2E is ran on linux. This fixes that by introducing platform-specific reference files.

Note: without diegomura#2633, E2E will error, and without diegomura#2635, CJS E2E will still fail.
  • Loading branch information
wojtekmaj committed Feb 12, 2024
1 parent da10a9b commit 765bd78
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion e2e/node-cjs/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
const fs = require('node:fs/promises');
const os = require('node:os');
const assert = require('node:assert');
const { test } = require('node:test');
const { jsx } = require('react/jsx-runtime');
const { Document, Page, Text, renderToBuffer } = require('@react-pdf/renderer');

const platform = os.platform();

const MyDocument = () =>
jsx(Document, {
children: jsx(Page, {
Expand All @@ -28,7 +31,7 @@ function removeMovingParts(buffer) {

test('rendering a PDF', async () => {
const bufferPromise = renderToBuffer(jsx(MyDocument, {}));
const referenceBufferPromise = fs.readFile('../reference.pdf');
const referenceBufferPromise = fs.readFile(`../reference-${platform}.pdf`);

const [buffer, referenceBuffer] = await Promise.all([
bufferPromise,
Expand Down
5 changes: 4 additions & 1 deletion e2e/node-esm/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import fs from 'node:fs/promises';
import os from 'node:os';
import assert from 'node:assert';
import { test } from 'node:test';
import { jsx } from 'react/jsx-runtime';
import { Document, Page, Text, renderToBuffer } from '@react-pdf/renderer';

const platform = os.platform();

const MyDocument = () =>
jsx(Document, {
children: jsx(Page, {
Expand All @@ -28,7 +31,7 @@ function removeMovingParts(buffer) {

test('rendering a PDF', async () => {
const bufferPromise = renderToBuffer(jsx(MyDocument, {}));
const referenceBufferPromise = fs.readFile('../reference.pdf');
const referenceBufferPromise = fs.readFile(`../reference-${platform}.pdf`);

const [buffer, referenceBuffer] = await Promise.all([
bufferPromise,
Expand Down
File renamed without changes.
Binary file added e2e/reference-linux.pdf
Binary file not shown.

0 comments on commit 765bd78

Please sign in to comment.