Skip to content

Commit

Permalink
Remove tests for classic implementations, and rewrote the test suited…
Browse files Browse the repository at this point in the history
… to new browser
  • Loading branch information
yhatt committed Sep 26, 2024
1 parent c2e7560 commit 23a983c
Show file tree
Hide file tree
Showing 9 changed files with 443 additions and 668 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = {
coverageProvider: 'v8',
coverageThreshold: { global: { lines: 95 } },
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
prettierPath: null,
setupFiles: ['./jest.setup.js'],
transform: {
...jsWithBabel.transform,
Expand Down
25 changes: 18 additions & 7 deletions src/browser/browsers/chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import type {
} from 'puppeteer-core'
import { CLIErrorCode, error, isError } from '../../error'
import { isInsideContainer } from '../../utils/container'
import { isWSL, resolveWindowsEnv } from '../../utils/wsl'
import {
isWSL,
resolveWindowsEnv,
resolveWSLPathToGuestSync,
} from '../../utils/wsl'
import { Browser } from '../browser'
import type { BrowserKind, BrowserProtocol, BrowserOptions } from '../browser'
import { isSnapBrowser } from '../finders/utils'
Expand Down Expand Up @@ -48,10 +52,9 @@ export class ChromeBrowser extends Browser {
userDataDir: await this.createPuppeteerDataDir(),
...opts,
args: await this.puppeteerArgs(opts.args ?? []),
ignoreDefaultArgs:
typeof opts.ignoreDefaultArgs === 'boolean'
? opts.ignoreDefaultArgs
: [...ignoreDefaultArgsSet],
ignoreDefaultArgs: opts.ignoreDefaultArgs === true || [
...ignoreDefaultArgsSet,
],
})

const tryLaunch = async (
Expand Down Expand Up @@ -116,19 +119,27 @@ export class ChromeBrowser extends Browser {
}

private async createPuppeteerDataDir() {
let requiredResolveWSLPath = false

const dataDir = await (async () => {
// In WSL environment, Marp CLI may use Chrome on Windows. If Chrome has
// located in host OS (Windows), we have to specify Windows path.
if (await this.browserInWSLHost()) {
if (wslTmp === undefined) wslTmp = await resolveWindowsEnv('TMP')
if (wslTmp !== undefined)
if (wslTmp !== undefined) {
requiredResolveWSLPath = true
return path.win32.resolve(wslTmp, this._dataDirName)
}
}
return path.resolve(os.tmpdir(), this._dataDirName)
})()

// Ensure the data directory is created
await fs.promises.mkdir(dataDir, { recursive: true })
await fs.promises.mkdir(
requiredResolveWSLPath ? resolveWSLPathToGuestSync(dataDir) : dataDir,
{ recursive: true }
)

return dataDir
}
}
2 changes: 1 addition & 1 deletion src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { EventEmitter } from 'node:events'
import { nanoid } from 'nanoid'
import type { Page, Browser, Target } from 'puppeteer-core'
import TypedEmitter from 'typed-emitter'
import { BrowserManager } from './browser/manager'
import { ConvertType, mimeTypes } from './converter'
import { error } from './error'
import { File, FileType } from './file'
import { BrowserManager } from './browser/manager'
import { debugPreview } from './utils/debug'

const emptyPageURI = `data:text/html;base64,PHRpdGxlPk1hcnAgQ0xJPC90aXRsZT4` // <title>Marp CLI</title>
Expand Down
Loading

0 comments on commit 23a983c

Please sign in to comment.