-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sync chrome-for-testing binary (#455)
> puppeteer/puppeteer#10131 Puppeteer has updated the default browser to Chrome and added the corresponding implementation as follows: 🧶 Added a new category `/-/binary/` for Chrome , exp: `/-/binary/chrome-for-testing/113.0.5672.63/mac-arm64/chrome-mac-arm64.zip` ----------- > puppeteer/puppeteer#10131 puppeteer 更新了默认浏览器为 chrome,新增对应实现 🧶 `/-/binary/` 新增 chrome binary 分类, 示例链接`/-/binary/chrome-for-testing/113.0.5672.63/mac-arm64/chrome-mac-arm64.zip`
- Loading branch information
Showing
4 changed files
with
108 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { SingletonProto } from '@eggjs/tegg'; | ||
import { BinaryType } from '../../enum/Binary'; | ||
import { AbstractBinary, FetchResult, BinaryItem, BinaryAdapter } from './AbstractBinary'; | ||
|
||
@SingletonProto() | ||
@BinaryAdapter(BinaryType.ChromeForTesting) | ||
export class ChromeForTestingBinary extends AbstractBinary { | ||
private dirItems?: { | ||
[key: string]: BinaryItem[]; | ||
}; | ||
|
||
async init() { | ||
this.dirItems = undefined; | ||
} | ||
|
||
async fetch(dir: string): Promise<FetchResult | undefined> { | ||
if (!this.dirItems) { | ||
this.dirItems = {}; | ||
this.dirItems['/'] = []; | ||
let chromeVersion = ''; | ||
|
||
// exports.PUPPETEER_REVISIONS = Object.freeze({ | ||
// chrome: '113.0.5672.63', | ||
// firefox: 'latest', | ||
// }); | ||
const unpkgURL = 'https://unpkg.com/puppeteer-core@latest/lib/cjs/puppeteer/revisions.js'; | ||
const text = await this.requestXml(unpkgURL); | ||
const m = /chrome:\s+\'([\d\.]+)\'\,/.exec(text); | ||
if (m) { | ||
chromeVersion = m[1]; | ||
} | ||
|
||
const platforms = [ 'linux64', 'mac-arm64', 'mac-x64', 'win32', 'win64' ]; | ||
const date = new Date().toISOString(); | ||
this.dirItems['/'].push({ | ||
name: `${chromeVersion}/`, | ||
date, | ||
size: '-', | ||
isDir: true, | ||
url: '', | ||
}); | ||
this.dirItems[`/${chromeVersion}/`] = []; | ||
|
||
for (const platform of platforms) { | ||
this.dirItems[`/${chromeVersion}/`].push({ | ||
name: `${platform}/`, | ||
date, | ||
size: '-', | ||
isDir: true, | ||
url: '', | ||
}); | ||
|
||
// https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/113.0.5672.63/mac-arm64/chrome-mac-arm64.zip | ||
const name = `chrome-${platform}.zip`; | ||
this.dirItems[`/${chromeVersion}/${platform}/`] = [ | ||
{ | ||
name, | ||
date, | ||
size: '-', | ||
isDir: false, | ||
url: `https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/${chromeVersion}/${platform}/${name}`, | ||
}, | ||
]; | ||
} | ||
} | ||
|
||
return { items: this.dirItems[dir], nextParams: null }; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import assert from 'assert'; | ||
import { app } from 'egg-mock/bootstrap'; | ||
import { ChromeForTestingBinary } from 'app/common/adapter/binary/ChromeForTestingBinary'; | ||
|
||
describe('test/common/adapter/binary/ChromeForTestingBinary.test.ts', () => { | ||
let binary: ChromeForTestingBinary; | ||
beforeEach(async () => { | ||
binary = await app.getEggObject(ChromeForTestingBinary); | ||
}); | ||
describe('fetch()', () => { | ||
it('should work for chrome binary', async () => { | ||
const result = await binary.fetch('/'); | ||
const latestVersion = result?.items?.[0].name; | ||
assert(latestVersion); | ||
|
||
const platformRes = await binary.fetch(`/${latestVersion}`); | ||
const platforms = platformRes?.items.map(item => item.name); | ||
assert(platforms); | ||
|
||
for (const platform of platforms) { | ||
const versionRes = await binary.fetch(`/${latestVersion}${platform}`); | ||
const versions = versionRes?.items.map(item => item.name); | ||
assert.equal(versions?.length, 1); | ||
assert(versionRes?.items[0].name); | ||
assert.equal(versionRes?.items[0].isDir, false); | ||
} | ||
}); | ||
}); | ||
}); |