Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support local aliases when launching a browser (#11947)
- Loading branch information
Showing
9 changed files
with
222 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,72 @@ | ||
/** | ||
* @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' | ||
); | ||
}); | ||
|
||
it('resolves latest', async function () { | ||
cache.writeMetadata(Browser.CHROME, { | ||
aliases: { | ||
canary: '115.0.5789', | ||
stable: '114.0.5789', | ||
}, | ||
}); | ||
|
||
assert.deepStrictEqual( | ||
cache.resolveAlias(Browser.CHROME, 'latest'), | ||
'115.0.5789' | ||
); | ||
}); | ||
}); |
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