Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade @pdfme/generator to 5.0.0 #2413

1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default {
'<rootDir>/scripts/__mocks__/@dicebear/collection.ts',
'\\.svg\\?react$': '<rootDir>/scripts/__mocks__/fileMock.js',
'\\.svg$': '<rootDir>/scripts/__mocks__/fileMock.js',
'^@pdfme/generator$': '<rootDir>/scripts/__mocks__/@pdfme/generator.ts'
},
moduleFileExtensions: [
'web.js',
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@mui/x-charts": "^7.22.1",
"@mui/x-data-grid": "^7.22.1",
"@mui/x-date-pickers": "^7.22.1",
"@pdfme/generator": "^4.5.2",
"@pdfme/generator": "^5.0.0",
"@reduxjs/toolkit": "^2.3.0",
"@vitejs/plugin-react": "^4.3.2",
"babel-plugin-transform-import-meta": "^2.2.1",
Expand Down
13 changes: 13 additions & 0 deletions scripts/__mocks__/@pdfme/generator.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { generate } from './generator';

describe('Testing mock generate util', () => {
test('should return a Promise', async () => {
const result = generate({ template: {}, inputs: [] });
expect(result).toBeInstanceOf(Promise);
});

test('should resolve to a Uint8Array', async () => {
const result = generate({ template: {}, inputs: [] });
expect(result).toBeInstanceOf(Uint8Array);
});
});
18 changes: 18 additions & 0 deletions scripts/__mocks__/@pdfme/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Template } from '@pdfme/common';

export const generate = async ({
template,
inputs,
}: {
template: Template;
inputs: Record<string, string>[];
}): Promise<Uint8Array> => {
// Generate mock PDF-like header bytes
const pdfHeader = [0x25, 0x50, 0x44, 0x46]; // %PDF
// Add some random content based on input size
const contentSize = Math.min(template.schemas.length, inputs.length) * 10;
const mockContent = Array.from({ length: contentSize }, () =>
Math.floor(Math.random() * 256),
);
return Promise.resolve(new Uint8Array([...pdfHeader, ...mockContent]));
};
Loading