Skip to content

Commit

Permalink
Update how to test marp-cli.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
yhatt committed Sep 27, 2024
1 parent 77b9565 commit 745ca7f
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions test/marp-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,30 +243,29 @@ describe('Marp CLI', () => {
}

describe('with DEBUG env', () => {
let originalEnv: Record<string, string | undefined>

beforeEach(() => (originalEnv = { ...process.env }))
afterEach(() => (process.env = { ...originalEnv }))

it('shows enabling debug logging and set pattern', async () => {
process.env.DEBUG = 'debug-pattern,debug-pattern:*'

const warn = jest.spyOn(console, 'warn').mockImplementation()
const log = jest.spyOn(console, 'log').mockImplementation()

try {
expect(await marpCli(['-v'])).toBe(0)
expect(warn).toHaveBeenCalledWith(
expect.stringContaining('Debug logging is enabled')
)
expect(warn).toHaveBeenCalledWith(
expect.stringContaining(
'Filter pattern: debug-pattern,debug-pattern:*'
const warn = jest.spyOn(console, 'warn').mockImplementation()
const log = jest.spyOn(console, 'log').mockImplementation()

try {
expect(await marpCli(['-v'])).toBe(0)
expect(warn).toHaveBeenCalledWith(
expect.stringContaining('Debug logging is enabled')
)
)
expect(warn).toHaveBeenCalledWith(
expect.stringContaining(
'Filter pattern: debug-pattern,debug-pattern:*'
)
)
} finally {
warn.mockRestore()
log.mockRestore()
}
} finally {
warn.mockRestore()
log.mockRestore()
delete process.env.DEBUG
}
})
})
Expand Down Expand Up @@ -1363,20 +1362,23 @@ describe('Marp CLI', () => {
})

describe('with PUPPETEER_TIMEOUT env', () => {
let originalEnv: Record<string, string | undefined>
beforeEach(() => {
process.env.PUPPETEER_TIMEOUT = '12345'
})

beforeEach(() => (originalEnv = { ...process.env }))
afterEach(() => (process.env = { ...originalEnv }))
afterEach(() => {
delete process.env.PUPPETEER_TIMEOUT
})

it('follows specified timeout in conversion that is using Puppeteer', async () => {
process.env.PUPPETEER_TIMEOUT = '12345'
expect(
(await conversion(onePath, '--pdf')).options.browserManager.timeout
).toBe(12345)
})

it('does not follows specified timeout if the env value is not valid number', async () => {
process.env.PUPPETEER_TIMEOUT = 'invalid'

expect(
(await conversion(onePath, '--pdf')).options.browserManager.timeout
).toBeUndefined()
Expand Down

0 comments on commit 745ca7f

Please sign in to comment.