Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support chrome-headless-shell (#10739)
- Loading branch information
1 parent
e12b558
commit 416843b
Showing
10 changed files
with
413 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
packages/browsers/src/browser-data/chrome-headless-shell.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* Copyright 2023 Google Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import path from 'path'; | ||
|
||
import {BrowserPlatform} from './types.js'; | ||
|
||
function folder(platform: BrowserPlatform): string { | ||
switch (platform) { | ||
case BrowserPlatform.LINUX: | ||
return 'linux64'; | ||
case BrowserPlatform.MAC_ARM: | ||
return 'mac-arm64'; | ||
case BrowserPlatform.MAC: | ||
return 'mac-x64'; | ||
case BrowserPlatform.WIN32: | ||
return 'win32'; | ||
case BrowserPlatform.WIN64: | ||
return 'win64'; | ||
} | ||
} | ||
|
||
export function resolveDownloadUrl( | ||
platform: BrowserPlatform, | ||
buildId: string, | ||
baseUrl = 'https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing' | ||
): string { | ||
return `${baseUrl}/${resolveDownloadPath(platform, buildId).join('/')}`; | ||
} | ||
|
||
export function resolveDownloadPath( | ||
platform: BrowserPlatform, | ||
buildId: string | ||
): string[] { | ||
return [ | ||
buildId, | ||
folder(platform), | ||
`chrome-headless-shell-${folder(platform)}.zip`, | ||
]; | ||
} | ||
|
||
export function relativeExecutablePath( | ||
platform: BrowserPlatform, | ||
_buildId: string | ||
): string { | ||
switch (platform) { | ||
case BrowserPlatform.MAC: | ||
case BrowserPlatform.MAC_ARM: | ||
return path.join( | ||
'chrome-headless-shell-' + folder(platform), | ||
'chrome-headless-shell' | ||
); | ||
case BrowserPlatform.LINUX: | ||
return path.join( | ||
'chrome-headless-shell-linux64', | ||
'chrome-headless-shell' | ||
); | ||
case BrowserPlatform.WIN32: | ||
case BrowserPlatform.WIN64: | ||
return path.join( | ||
'chrome-headless-shell-' + folder(platform), | ||
'chrome-headless-shell.exe' | ||
); | ||
} | ||
} | ||
|
||
export {resolveBuildId} from './chrome.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
packages/browsers/test/src/chrome-headless-shell/chrome-headless-shell-data.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* Copyright 2023 Google Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import assert from 'assert'; | ||
import path from 'path'; | ||
|
||
import {BrowserPlatform} from '../../../lib/cjs/browser-data/browser-data.js'; | ||
import { | ||
resolveDownloadUrl, | ||
relativeExecutablePath, | ||
resolveBuildId, | ||
} from '../../../lib/cjs/browser-data/chrome-headless-shell.js'; | ||
|
||
describe('chrome-headless-shell', () => { | ||
it('should resolve download URLs', () => { | ||
assert.strictEqual( | ||
resolveDownloadUrl(BrowserPlatform.LINUX, '118.0.5950.0'), | ||
'https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/118.0.5950.0/linux64/chrome-headless-shell-linux64.zip' | ||
); | ||
assert.strictEqual( | ||
resolveDownloadUrl(BrowserPlatform.MAC, '118.0.5950.0'), | ||
'https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/118.0.5950.0/mac-x64/chrome-headless-shell-mac-x64.zip' | ||
); | ||
assert.strictEqual( | ||
resolveDownloadUrl(BrowserPlatform.MAC_ARM, '118.0.5950.0'), | ||
'https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/118.0.5950.0/mac-arm64/chrome-headless-shell-mac-arm64.zip' | ||
); | ||
assert.strictEqual( | ||
resolveDownloadUrl(BrowserPlatform.WIN32, '118.0.5950.0'), | ||
'https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/118.0.5950.0/win32/chrome-headless-shell-win32.zip' | ||
); | ||
assert.strictEqual( | ||
resolveDownloadUrl(BrowserPlatform.WIN64, '118.0.5950.0'), | ||
'https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/118.0.5950.0/win64/chrome-headless-shell-win64.zip' | ||
); | ||
}); | ||
|
||
it('should resolve milestones', async () => { | ||
assert.strictEqual(await resolveBuildId('118'), '118.0.5950.0'); | ||
}); | ||
|
||
it('should resolve build prefix', async () => { | ||
assert.strictEqual(await resolveBuildId('118.0.5950'), '118.0.5950.0'); | ||
}); | ||
|
||
it('should resolve executable paths', () => { | ||
assert.strictEqual( | ||
relativeExecutablePath(BrowserPlatform.LINUX, '12372323'), | ||
path.join('chrome-headless-shell-linux64', 'chrome-headless-shell') | ||
); | ||
assert.strictEqual( | ||
relativeExecutablePath(BrowserPlatform.MAC, '12372323'), | ||
path.join('chrome-headless-shell-mac-x64/', 'chrome-headless-shell') | ||
); | ||
assert.strictEqual( | ||
relativeExecutablePath(BrowserPlatform.MAC_ARM, '12372323'), | ||
path.join('chrome-headless-shell-mac-arm64', 'chrome-headless-shell') | ||
); | ||
assert.strictEqual( | ||
relativeExecutablePath(BrowserPlatform.WIN32, '12372323'), | ||
path.join('chrome-headless-shell-win32', 'chrome-headless-shell.exe') | ||
); | ||
assert.strictEqual( | ||
relativeExecutablePath(BrowserPlatform.WIN64, '12372323'), | ||
path.join('chrome-headless-shell-win64', 'chrome-headless-shell.exe') | ||
); | ||
}); | ||
}); |
91 changes: 91 additions & 0 deletions
91
packages/browsers/test/src/chrome-headless-shell/cli.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* Copyright 2023 Google Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import assert from 'assert'; | ||
import fs from 'fs'; | ||
import os from 'os'; | ||
import path from 'path'; | ||
|
||
import {CLI} from '../../../lib/cjs/CLI.js'; | ||
import { | ||
createMockedReadlineInterface, | ||
setupTestServer, | ||
getServerUrl, | ||
} from '../utils.js'; | ||
import {testChromeHeadlessShellBuildId} from '../versions.js'; | ||
|
||
describe('chrome-headless-shell CLI', function () { | ||
this.timeout(90000); | ||
|
||
setupTestServer(); | ||
|
||
let tmpDir = '/tmp/puppeteer-browsers-test'; | ||
|
||
beforeEach(() => { | ||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'puppeteer-browsers-test')); | ||
}); | ||
|
||
afterEach(async () => { | ||
await new CLI(tmpDir, createMockedReadlineInterface('yes')).run([ | ||
'npx', | ||
'@puppeteer/browsers', | ||
'clear', | ||
`--path=${tmpDir}`, | ||
`--base-url=${getServerUrl()}`, | ||
]); | ||
}); | ||
|
||
it('should download chrome-headless-shell binaries', async () => { | ||
await new CLI(tmpDir).run([ | ||
'npx', | ||
'@puppeteer/browsers', | ||
'install', | ||
`chrome-headless-shell@${testChromeHeadlessShellBuildId}`, | ||
`--path=${tmpDir}`, | ||
'--platform=linux', | ||
`--base-url=${getServerUrl()}`, | ||
]); | ||
assert.ok( | ||
fs.existsSync( | ||
path.join( | ||
tmpDir, | ||
'chrome-headless-shell', | ||
`linux-${testChromeHeadlessShellBuildId}`, | ||
'chrome-headless-shell-linux64', | ||
'chrome-headless-shell' | ||
) | ||
) | ||
); | ||
|
||
await new CLI(tmpDir, createMockedReadlineInterface('no')).run([ | ||
'npx', | ||
'@puppeteer/browsers', | ||
'clear', | ||
`--path=${tmpDir}`, | ||
]); | ||
assert.ok( | ||
fs.existsSync( | ||
path.join( | ||
tmpDir, | ||
'chrome-headless-shell', | ||
`linux-${testChromeHeadlessShellBuildId}`, | ||
'chrome-headless-shell-linux64', | ||
'chrome-headless-shell' | ||
) | ||
) | ||
); | ||
}); | ||
}); |
Oops, something went wrong.