From d368c5db192254ad1688e238357cdb81e33357ce Mon Sep 17 00:00:00 2001 From: Daniel Izdebski Date: Tue, 24 Oct 2023 18:38:35 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(core):=20Add=20`defineWalletSe?= =?UTF-8?q?tup`=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/package.json | 3 +++ packages/core/src/defineWalletSetup.ts | 14 +++++++++++++ packages/core/test/defineWalletSetup.test.ts | 21 ++++++++++++++++++++ pnpm-lock.yaml | 4 +++- 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 packages/core/src/defineWalletSetup.ts create mode 100644 packages/core/test/defineWalletSetup.test.ts diff --git a/packages/core/package.json b/packages/core/package.json index c7c911bcd..78563ecfe 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -49,5 +49,8 @@ "tsup": "^7.2.0", "typescript": "^5.2.2", "vitest": "^0.34.6" + }, + "peerDependencies": { + "playwright-core": "1.39.0" } } diff --git a/packages/core/src/defineWalletSetup.ts b/packages/core/src/defineWalletSetup.ts new file mode 100644 index 000000000..16990c6a1 --- /dev/null +++ b/packages/core/src/defineWalletSetup.ts @@ -0,0 +1,14 @@ +import type { BrowserContext, Page } from 'playwright-core' +import { getWalletSetupFuncHash } from './utils/getWalletSetupFuncHash' + +export type WalletSetupFunction = (context: BrowserContext, walletPage: Page) => Promise + +// TODO: This runs at least twice. Should we cache it somehow? +export function defineWalletSetup(fn: WalletSetupFunction) { + const hash = getWalletSetupFuncHash(fn) + + return { + hash, + fn + } +} diff --git a/packages/core/test/defineWalletSetup.test.ts b/packages/core/test/defineWalletSetup.test.ts new file mode 100644 index 000000000..454a8607e --- /dev/null +++ b/packages/core/test/defineWalletSetup.test.ts @@ -0,0 +1,21 @@ +import { describe, expect, it } from 'vitest' +import { defineWalletSetup } from '../src/defineWalletSetup' + +const EXPECTED_HASH = '69620d59802a61c6900f' + +const testWalletSetupFunction = async (): Promise => { + const result = 1 + 2 + if (result !== 3) { + throw new Error('That damn Quacker messed with my math again! 😡') + } + + return +} + +describe('defineWalletSetup', () => { + it('returns both hash and function', async () => { + const { hash, fn } = defineWalletSetup(testWalletSetupFunction) + expect(hash).toEqual(EXPECTED_HASH) + expect(fn.toString()).toEqual(testWalletSetupFunction.toString()) + }) +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fb78787f0..90e333dd2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -58,6 +58,9 @@ importers: fs-extra: specifier: ^11.1.1 version: 11.1.1 + playwright-core: + specifier: 1.39.0 + version: 1.39.0 unzipper: specifier: ^0.10.14 version: 0.10.14 @@ -3126,7 +3129,6 @@ packages: resolution: {integrity: sha512-+k4pdZgs1qiM+OUkSjx96YiKsXsmb59evFoqv8SKO067qBA+Z2s/dCzJij/ZhdQcs2zlTAgRKfeiiLm8PQ2qvw==} engines: {node: '>=16'} hasBin: true - dev: true /playwright@1.38.0: resolution: {integrity: sha512-fJGw+HO0YY+fU/F1N57DMO+TmXHTrmr905J05zwAQE9xkuwP/QLDk63rVhmyxh03dYnEhnRbsdbH9B0UVVRB3A==}