-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { BrowserContext } from '@playwright/test' | ||
import { z } from 'zod' | ||
|
||
const Extension = z.object({ | ||
id: z.string(), | ||
name: z.string() | ||
}) | ||
|
||
const Extensions = z.array(Extension) | ||
|
||
/** | ||
* Returns the extension ID for the given extension name. The ID is fetched from the `chrome://extensions` page. | ||
* | ||
* ::: tip | ||
* This function soon will be removed to improve the developer experience! 😇 | ||
* ::: | ||
* | ||
* @param context - The browser context. | ||
* @param extensionName - The name of the extension, e.g., `Keplr`. | ||
* | ||
* @returns The extension ID. | ||
*/ | ||
export async function getExtensionId(context: BrowserContext, extensionName: string) { | ||
const page = await context.newPage() | ||
await page.goto('chrome://extensions') | ||
|
||
const unparsedExtensions = await page.evaluate('chrome.management.getAll()') | ||
|
||
const allExtensions = Extensions.parse(unparsedExtensions) | ||
const targetExtension = allExtensions.find( | ||
(extension) => extension.name.toLowerCase() === extensionName.toLowerCase() | ||
) | ||
|
||
if (!targetExtension) { | ||
throw new Error( | ||
[ | ||
`[GetExtensionId] Extension with name ${extensionName} not found.`, | ||
`Available extensions: ${allExtensions.map((extension) => extension.name).join(', ')}` | ||
].join('\n') | ||
) | ||
} | ||
|
||
await page.close() | ||
|
||
return targetExtension.id | ||
} |
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,19 @@ | ||
import { downloadFile, ensureCacheDirExists, unzipArchive } from '@synthetixio/synpress-cache' | ||
|
||
export const DEFAULT_KEPLR_VERSION = '0.12.101' | ||
export const EXTENSION_DOWNLOAD_URL = `https://github.com/chainapsis/keplr-wallet/releases/download/v${DEFAULT_KEPLR_VERSION}/keplr-extension-manifest-v2-v${DEFAULT_KEPLR_VERSION}.zip`; | ||
export async function prepareExtension() { | ||
const cacheDirPath = ensureCacheDirExists() | ||
|
||
const downloadResult = await downloadFile({ | ||
url: EXTENSION_DOWNLOAD_URL, | ||
outputDir: cacheDirPath, | ||
fileName: `keplr-extension-manifest-v2-v${DEFAULT_KEPLR_VERSION}.zip` | ||
}) | ||
|
||
const unzipResult = await unzipArchive({ | ||
archivePath: downloadResult.filePath | ||
}) | ||
|
||
return unzipResult.outputPath | ||
} |