-
Notifications
You must be signed in to change notification settings - Fork 9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With this PR, @puppeteer/browsers starts maintaining a local mapping from an alias to the locally installed version. This allows using aliases such as `canary`/`latest` when launching the browser. Note that the launch command would only consult metadata files and won't attempt to re-check aliases by contacting the server.
- Loading branch information
Showing
9 changed files
with
203 additions
and
15 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
17 changes: 17 additions & 0 deletions
17
docs/browsers-api/browsers.installedbrowser.readmetadata.md
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,17 @@ | ||
--- | ||
sidebar_label: InstalledBrowser.readMetadata | ||
--- | ||
|
||
# InstalledBrowser.readMetadata() method | ||
|
||
#### Signature: | ||
|
||
```typescript | ||
class InstalledBrowser { | ||
readMetadata(): Metadata; | ||
} | ||
``` | ||
|
||
**Returns:** | ||
|
||
Metadata |
23 changes: 23 additions & 0 deletions
23
docs/browsers-api/browsers.installedbrowser.writemetadata.md
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,23 @@ | ||
--- | ||
sidebar_label: InstalledBrowser.writeMetadata | ||
--- | ||
|
||
# InstalledBrowser.writeMetadata() method | ||
|
||
#### Signature: | ||
|
||
```typescript | ||
class InstalledBrowser { | ||
writeMetadata(metadata: Metadata): void; | ||
} | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --------- | -------- | ----------- | | ||
| metadata | Metadata | | | ||
|
||
**Returns:** | ||
|
||
void |
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
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,58 @@ | ||
/** | ||
* @license | ||
* Copyright 2024 Google Inc. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import assert from 'assert'; | ||
import fs from 'fs'; | ||
import os from 'os'; | ||
import path from 'path'; | ||
|
||
import {Browser, Cache} from '../../lib/cjs/main.js'; | ||
|
||
describe('Cache', () => { | ||
let tmpDir = '/tmp/puppeteer-browsers-test'; | ||
let cache: Cache; | ||
|
||
beforeEach(() => { | ||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'puppeteer-browsers-test')); | ||
cache = new Cache(tmpDir); | ||
}); | ||
|
||
afterEach(() => { | ||
cache.clear(); | ||
}); | ||
|
||
it('return empty metadata if .metadata file does not exist', async function () { | ||
assert.deepStrictEqual(cache.readMetadata(Browser.CHROME), { | ||
aliases: {}, | ||
}); | ||
}); | ||
|
||
it('throw an error if .metadata is malformed', async function () { | ||
// @ts-expect-error wrong type on purpose; | ||
cache.writeMetadata(Browser.CHROME, 'metadata'); | ||
assert.throws(() => { | ||
return cache.readMetadata(Browser.CHROME); | ||
}, new Error(`.metadata is not an object`)); | ||
}); | ||
|
||
it('writes and reads .metadata', async function () { | ||
cache.writeMetadata(Browser.CHROME, { | ||
aliases: { | ||
canary: '123.0.0.0', | ||
}, | ||
}); | ||
assert.deepStrictEqual(cache.readMetadata(Browser.CHROME), { | ||
aliases: { | ||
canary: '123.0.0.0', | ||
}, | ||
}); | ||
|
||
assert.deepStrictEqual( | ||
cache.resolveAlias(Browser.CHROME, 'canary'), | ||
'123.0.0.0' | ||
); | ||
}); | ||
}); |
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