Skip to content

Commit

Permalink
Add basic test for pptxEditable converter option
Browse files Browse the repository at this point in the history
  • Loading branch information
yhatt committed Jan 10, 2025
1 parent b2cea7b commit 9312e61
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ commands:
type: steps
default: []
steps:
- run:
name: Set up LibreOffice
command: sudo apt-get install -y libreoffice-common

- restore_cache:
keys:
- v3-dependencies-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package-lock.json" }}-{{ .Branch }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
npm ci
npx patch-package
- name: Set up LibreOffice
run: sudo apt-get install -y libreoffice-common

# Retry tests up to 3 times due to flaky tests on Windows CI
# https://stackoverflow.com/a/59365905
- name: Jest
Expand Down
48 changes: 48 additions & 0 deletions test/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,54 @@ describe('Converter', () => {
timeout
)
})

describe('with pptxEditable option', () => {
beforeEach(() => {
// Don't mock writeFile to use actually saved tmp file for conversion
writeFileSpy.mockRestore()
})

it(
'converts markdown file into PDF -> PPTX through soffice',
async () => {
const cvt = converter({ pptxEditable: true })
const editablePptxSpy = jest.spyOn(
cvt as any,
'convertFileToEditablePPTX'
)
const unlink = jest.spyOn(fs.promises, 'unlink')
const fileSave = jest
.spyOn(File.prototype, 'save')
.mockImplementation()
const fileTmp = jest.spyOn(File.prototype, 'saveTmpFile')
const warn = jest.spyOn(console, 'warn').mockImplementation()

await cvt.convertFile(new File(onePath))
expect(editablePptxSpy).toHaveBeenCalled()
expect(warn).toHaveBeenCalledWith(
expect.stringContaining(
'Converting to editable PPTX is experimental feature'
)
)
expect(fileTmp).toHaveBeenCalledWith(
expect.objectContaining({ extension: '.pdf' })
)
expect(unlink).toHaveBeenCalledWith(
expect.stringContaining(os.tmpdir())
)
expect(fileSave).toHaveBeenCalled()

const savedFile = fileSave.mock.instances[0] as unknown as File
expect(savedFile).toBeInstanceOf(File)
expect(savedFile.path).toBe('test.pptx')

// ZIP PK header for Office Open XML
expect(savedFile.buffer?.toString('ascii', 0, 2)).toBe('PK')
expect(savedFile.buffer?.toString('hex', 2, 4)).toBe('0304')
},
timeoutLarge
)
})
})

describe('when convert type is PNG', () => {
Expand Down
14 changes: 14 additions & 0 deletions test/marp-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,20 @@ describe('Marp CLI', () => {
})
})

describe('with --pptx-editable options', () => {
it('prefers PPTX than HTML if not specified conversion type', async () => {
const cmd = [onePath, '--pptx-editable']
expect((await conversion(...cmd)).options.type).toBe(ConvertType.pptx)

// This option is actually not for defining conversion type so other
// options to set conversion type are always prioritized.
const cmdPptx = [onePath, '--pptx-editable', '--pdf']
expect((await conversion(...cmdPptx)).options.type).toBe(
ConvertType.pdf
)
})
})

describe('with PUPPETEER_TIMEOUT env', () => {
beforeEach(() => {
process.env.PUPPETEER_TIMEOUT = '12345'
Expand Down

0 comments on commit 9312e61

Please sign in to comment.