test: fix pdf-export mocks/assertions for the setDefaultTimeout API change
The ASPA/silent-failure-audit fix to renderer.ts (page.pdf() has no 'timeout' option in real Playwright; moved to page.setDefaultTimeout() before the call) was only typechecked at the time, never run against the test suite -- the mocks didn't implement setDefaultTimeout and two assertions still expected the old timeout-in-pdf()-options shape. Caught by the new build-verify CI workflow on its first real run. 215/215 tests pass now.
This commit is contained in:
parent
b11eed9cf6
commit
140d730b60
@ -9,6 +9,7 @@ import type { Pool } from 'pg'
|
|||||||
// Mock Playwright for renderer tests
|
// Mock Playwright for renderer tests
|
||||||
vi.mock('playwright', () => {
|
vi.mock('playwright', () => {
|
||||||
const mockPage = {
|
const mockPage = {
|
||||||
|
setDefaultTimeout: vi.fn(),
|
||||||
setContent: vi.fn().mockResolvedValue(undefined),
|
setContent: vi.fn().mockResolvedValue(undefined),
|
||||||
pdf: vi.fn().mockResolvedValue(Buffer.from('pdf binary content')),
|
pdf: vi.fn().mockResolvedValue(Buffer.from('pdf binary content')),
|
||||||
close: vi.fn().mockResolvedValue(undefined),
|
close: vi.fn().mockResolvedValue(undefined),
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import type { PDFTemplateData } from '../types'
|
|||||||
// Mock Playwright
|
// Mock Playwright
|
||||||
vi.mock('playwright', () => {
|
vi.mock('playwright', () => {
|
||||||
const mockPage = {
|
const mockPage = {
|
||||||
|
setDefaultTimeout: vi.fn(),
|
||||||
setContent: vi.fn().mockResolvedValue(undefined),
|
setContent: vi.fn().mockResolvedValue(undefined),
|
||||||
pdf: vi.fn().mockResolvedValue(Buffer.from('mock pdf content')),
|
pdf: vi.fn().mockResolvedValue(Buffer.from('mock pdf content')),
|
||||||
close: vi.fn().mockResolvedValue(undefined),
|
close: vi.fn().mockResolvedValue(undefined),
|
||||||
@ -85,11 +86,13 @@ describe('PDFRenderer', () => {
|
|||||||
const mockBrowser = await (chromium.launch as any)()
|
const mockBrowser = await (chromium.launch as any)()
|
||||||
const mockPage = await mockBrowser.newPage()
|
const mockPage = await mockBrowser.newPage()
|
||||||
|
|
||||||
|
// Playwright's page.pdf() has no `timeout` option -- the timeout is set via
|
||||||
|
// page.setDefaultTimeout() before the call instead (see renderer.ts).
|
||||||
expect(mockPage.pdf).toHaveBeenCalledWith({
|
expect(mockPage.pdf).toHaveBeenCalledWith({
|
||||||
format: 'A4',
|
format: 'A4',
|
||||||
margin: { top: '0', right: '0', bottom: '0', left: '0' },
|
margin: { top: '0', right: '0', bottom: '0', left: '0' },
|
||||||
timeout: 30000,
|
|
||||||
})
|
})
|
||||||
|
expect(mockPage.setDefaultTimeout).toHaveBeenCalledWith(30000)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should respect custom timeout', async () => {
|
it('should respect custom timeout', async () => {
|
||||||
@ -102,11 +105,7 @@ describe('PDFRenderer', () => {
|
|||||||
const mockBrowser = await (chromium.launch as any)()
|
const mockBrowser = await (chromium.launch as any)()
|
||||||
const mockPage = await mockBrowser.newPage()
|
const mockPage = await mockBrowser.newPage()
|
||||||
|
|
||||||
expect(mockPage.pdf).toHaveBeenCalledWith(
|
expect(mockPage.setDefaultTimeout).toHaveBeenCalledWith(customTimeout)
|
||||||
expect.objectContaining({
|
|
||||||
timeout: customTimeout,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should close page after rendering', async () => {
|
it('should close page after rendering', async () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user