|
| 1 | +import * as marpCliModule from '@marp-team/marp-cli' |
1 | 2 | import { commands, env, window, workspace } from 'vscode' |
2 | 3 | import * as marpCli from '../marp-cli' |
3 | 4 | import * as option from '../option' |
@@ -317,6 +318,65 @@ describe('#doExport', () => { |
317 | 318 | }) |
318 | 319 | }) |
319 | 320 |
|
| 321 | + describe('when CLI was thrown CLIError with BROWSER_NOT_FOUND error code', () => { |
| 322 | + it.each` |
| 323 | + browser | platform | expected |
| 324 | + ${'auto'} | ${'win32'} | ${['Google Chrome', 'Microsoft Edge', 'Firefox']} |
| 325 | + ${'auto'} | ${'darwin'} | ${['Google Chrome', 'Microsoft Edge', 'Firefox']} |
| 326 | + ${'auto'} | ${'linux'} | ${['Google Chrome', 'Chromium', 'Microsoft Edge', 'Firefox']} |
| 327 | + ${'chrome'} | ${'win32'} | ${['Google Chrome']} |
| 328 | + ${'chrome'} | ${'darwin'} | ${['Google Chrome']} |
| 329 | + ${'chrome'} | ${'linux'} | ${['Google Chrome', 'Chromium']} |
| 330 | + ${'edge'} | ${'win32'} | ${['Microsoft Edge']} |
| 331 | + ${'edge'} | ${'darwin'} | ${['Microsoft Edge']} |
| 332 | + ${'edge'} | ${'linux'} | ${['Microsoft Edge']} |
| 333 | + ${'firefox'} | ${'win32'} | ${['Firefox']} |
| 334 | + ${'firefox'} | ${'darwin'} | ${['Firefox']} |
| 335 | + ${'firefox'} | ${'linux'} | ${['Firefox']} |
| 336 | + `( |
| 337 | + 'throws MarpCLIError with the message contains $expected to suggest browsers when running on $platform with browser option as $browser', |
| 338 | + async ({ browser, platform, expected }) => { |
| 339 | + expect.assertions(expected.length + 1) |
| 340 | + setConfiguration({ 'markdown.marp.browser': browser }) |
| 341 | + |
| 342 | + const { platform: originalPlatform } = process |
| 343 | + |
| 344 | + try { |
| 345 | + Object.defineProperty(process, 'platform', { value: platform }) |
| 346 | + |
| 347 | + const runMarpCLI = jest |
| 348 | + .spyOn(marpCli, 'default') |
| 349 | + .mockImplementation(async (_, __, opts) => { |
| 350 | + opts?.onCLIError?.({ |
| 351 | + error: new marpCliModule.CLIError( |
| 352 | + 'mocked error', |
| 353 | + marpCliModule.CLIErrorCode.NOT_FOUND_BROWSER, |
| 354 | + ), |
| 355 | + codes: marpCliModule.CLIErrorCode, |
| 356 | + }) |
| 357 | + }) |
| 358 | + |
| 359 | + try { |
| 360 | + await exportModule.doExport(saveURI(), document) |
| 361 | + expect(window.showErrorMessage).toHaveBeenCalledTimes(1) |
| 362 | + |
| 363 | + for (const fragment of expected) { |
| 364 | + expect(window.showErrorMessage).toHaveBeenCalledWith( |
| 365 | + expect.stringContaining(fragment), |
| 366 | + ) |
| 367 | + } |
| 368 | + } finally { |
| 369 | + runMarpCLI.mockRestore() |
| 370 | + } |
| 371 | + } finally { |
| 372 | + Object.defineProperty(process, 'platform', { |
| 373 | + value: originalPlatform, |
| 374 | + }) |
| 375 | + } |
| 376 | + }, |
| 377 | + ) |
| 378 | + }) |
| 379 | + |
320 | 380 | describe('when the save path has non-file scheme', () => { |
321 | 381 | it('exports the document into temporally path and copy it to the save path', async () => { |
322 | 382 | const marpCliMock = jest.spyOn(marpCli, 'default').mockImplementation() |
|
0 commit comments