Skip to content

Commit

Permalink
Make stable CI tests (#640)
Browse files Browse the repository at this point in the history
* Improve flaky tests about JPEG conversion

Update `imageScale` option for testing to reduce memory usage.

* Update test args for CircleCI

* Fix expected image scale for JPEG conversion tests

* Set timeout for tests about soffice

* Debug JPEG conversion

* Revert "Debug JPEG conversion"

This reverts commit 9f6c7c7.

* Disable GPU acceleration in CI tests to mitigate flakiness

* Debug JPEG conversion

* Revert "Debug JPEG conversion"

This reverts commit ca02a7f.

* Revert "Disable GPU acceleration in CI tests to mitigate flakiness"

This reverts commit 4690bb4.
  • Loading branch information
yhatt authored Jan 21, 2025
1 parent c21153a commit 4033366
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ commands:
steps:
- run:
name: Jest
command: npm run test:coverage -- --ci --reporters=default --reporters=jest-junit <<# parameters.runInBand >>-i<</ parameters.runInBand >>
command: npm run test:coverage -- --ci --reporters=default --reporters=jest-junit <<#parameters.runInBand>>-i<</parameters.runInBand>><<^parameters.runInBand>>--maxWorkers=2<</parameters.runInBand>>
environment:
JEST_JUNIT_CLASSNAME: '{filepath}'
JEST_JUNIT_OUTPUT_DIR: tmp/test-results
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
MARP_TEST_CI: 1
run: >-
npm run test:coverage -- --ci --max-workers ${{ steps.cpu-cores.outputs.count }} --reporters=default --reporters=jest-junit ||
npm run test:coverage -- --ci --bail -i --reporters=default --reporters=jest-junit --no-cache ||
npm run test:coverage -- --ci --bail -i --reporters=default --reporters=jest-junit ||
npm run test:coverage -- --ci --bail -i --reporters=default --reporters=jest-junit --no-cache ||
npm run test:coverage -- --ci --bail -i --reporters=default --reporters=jest-junit --no-cache
Expand Down
68 changes: 38 additions & 30 deletions test/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1111,27 +1111,35 @@ describe('Converter', () => {
timeoutLarge
)

it('throws an error when soffice is not found', async () => {
const err = new CLIError('Error', CLIErrorCode.NOT_FOUND_SOFFICE)
it(
'throws an error when soffice is not found',
async () => {
const err = new CLIError('Error', CLIErrorCode.NOT_FOUND_SOFFICE)

jest.spyOn(console, 'warn').mockImplementation()
jest.spyOn(sofficeFinder, 'findSOffice').mockRejectedValue(err)
jest.spyOn(console, 'warn').mockImplementation()
jest.spyOn(sofficeFinder, 'findSOffice').mockRejectedValue(err)

const cvt = converter({ pptxEditable: true })
await expect(() =>
cvt.convertFile(new File(onePath))
).rejects.toThrow(err)
})
const cvt = converter({ pptxEditable: true })
await expect(() =>
cvt.convertFile(new File(onePath))
).rejects.toThrow(err)
},
timeout
)

it('throws an error when soffice is spawned but does not generate a converted file', async () => {
jest.spyOn(console, 'warn').mockImplementation()
jest.spyOn(SOffice.prototype, 'spawn').mockResolvedValue()
it(
'throws an error when soffice is spawned but does not generate a converted file',
async () => {
jest.spyOn(console, 'warn').mockImplementation()
jest.spyOn(SOffice.prototype, 'spawn').mockResolvedValue()

const cvt = converter({ pptxEditable: true })
await expect(() =>
cvt.convertFile(new File(onePath))
).rejects.toThrow('LibreOffice could not convert PPTX internally.')
})
const cvt = converter({ pptxEditable: true })
await expect(() =>
cvt.convertFile(new File(onePath))
).rejects.toThrow('LibreOffice could not convert PPTX internally.')
},
timeout
)
})
})

Expand Down Expand Up @@ -1287,16 +1295,16 @@ describe('Converter', () => {
await instance({
output: 'b.jpg',
type: ConvertType.jpeg,
imageScale: 0.5,
imageScale: 0.25,
}).convertFile(new File(onePath))

expect(writeFileSpy.mock.calls[0][1]).toBeInstanceOf(Buffer)

const jpeg = writeFileSpy.mock.calls[0][1] as Buffer
const { width, height } = imageSize(jpeg)

expect(width).toBe(640)
expect(height).toBe(360)
expect(width).toBe(320)
expect(height).toBe(180)
},
timeoutLarge
)
Expand All @@ -1309,14 +1317,14 @@ describe('Converter', () => {
await using browserManager = new BrowserManager({
finders: ['chrome', 'edge'],
protocol: 'webDriverBiDi',
timeout,
timeout: timeoutLarge,
})

await instance({
browserManager,
output: 'b.jpg',
type: ConvertType.jpeg,
imageScale: 0.5,
imageScale: 0.25,
}).convertFile(new File(onePath))

const [lastCall] = writeFileSpy.mock.calls.slice(-1)
Expand All @@ -1325,8 +1333,8 @@ describe('Converter', () => {
const jpeg = lastCall[1] as Buffer
const { width, height } = imageSize(jpeg)

expect(width).toBe(640)
expect(height).toBe(360)
expect(width).toBe(320)
expect(height).toBe(180)

// Check JPEG quality is working
writeFileSpy.mockClear()
Expand All @@ -1335,7 +1343,7 @@ describe('Converter', () => {
browserManager,
output: 'b.jpg',
type: ConvertType.jpeg,
imageScale: 0.5,
imageScale: 0.25,
jpegQuality: 1,
}).convertFile(new File(onePath))

Expand All @@ -1353,14 +1361,14 @@ describe('Converter', () => {
async () => {
await using browserManager = new BrowserManager({
finders: ['firefox'],
timeout,
timeout: timeoutLarge,
})

await instance({
browserManager,
output: 'b.jpg',
type: ConvertType.jpeg,
imageScale: 0.5,
imageScale: 0.25,
}).convertFile(new File(onePath))

const [lastCall] = writeFileSpy.mock.calls.slice(-1)
Expand All @@ -1369,8 +1377,8 @@ describe('Converter', () => {
const jpeg = lastCall[1] as Buffer
const { width, height } = imageSize(jpeg)

expect(width).toBe(640)
expect(height).toBe(360)
expect(width).toBe(320)
expect(height).toBe(180)

// Check JPEG quality is working
writeFileSpy.mockClear()
Expand All @@ -1379,7 +1387,7 @@ describe('Converter', () => {
browserManager,
output: 'b.jpg',
type: ConvertType.jpeg,
imageScale: 0.5,
imageScale: 0.25,
jpegQuality: 1,
}).convertFile(new File(onePath))

Expand Down

0 comments on commit 4033366

Please sign in to comment.