Skip to content

Commit

Permalink
Add test for configuration file with TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
yhatt committed Sep 23, 2023
1 parent c79ef5b commit 568523c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ export interface Config<Engine extends typeof Marpit = typeof Marp>
options?: ConstructorParameters<Engine>[0]
}
> {}

export const defineConfig = <Engine extends typeof Marpit = typeof Marp>(
config: Config<Engine>
) => config
1 change: 1 addition & 0 deletions test/__mocks__/cosmiconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ cosmiconfig.cosmiconfig = jest.fn((moduleName, options) => {
'.js': defaultLoadersSync['.js'],
'.mjs': defaultLoadersSync['.js'],
'.cjs': defaultLoadersSync['.js'],
'.ts': defaultLoadersSync['.ts'],
},
...(options ?? {}),
})
Expand Down
7 changes: 7 additions & 0 deletions test/_configs/typescript/marp.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from '../../../src/index'

export default defineConfig({
title: 'TypeScript configuration',
})

console.debug('A config file with .ts extension was loaded.')
24 changes: 24 additions & 0 deletions test/marp-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,30 @@ describe('Marp CLI', () => {
}
})
})

describe('with TypeScript', () => {
it('allows loading config with TypeScript', async () => {
const debug = jest.spyOn(console, 'debug').mockImplementation()
const log = jest.spyOn(console, 'log').mockImplementation()

try {
expect(
await marpCli([
'-v',
'-c',
assetFn('_configs/typescript/marp.config.ts'),
])
).toBe(0)

expect(debug).toHaveBeenCalledWith(
expect.stringContaining('loaded')
)
} finally {
debug.mockRestore()
log.mockRestore()
}
})
})
})

describe('with --preview / -p option', () => {
Expand Down

0 comments on commit 568523c

Please sign in to comment.