Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat(core): Add defineWalletSetup function #948

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@
"tsup": "^7.2.0",
"typescript": "^5.2.2",
"vitest": "^0.34.6"
},
"peerDependencies": {
"playwright-core": "1.39.0"
}
}
14 changes: 14 additions & 0 deletions packages/core/src/defineWalletSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { BrowserContext, Page } from 'playwright-core'
import { getWalletSetupFuncHash } from './utils/getWalletSetupFuncHash'

export type WalletSetupFunction = (context: BrowserContext, walletPage: Page) => Promise<void>

// TODO: This runs at least twice. Should we cache it somehow?
export function defineWalletSetup(fn: WalletSetupFunction) {
const hash = getWalletSetupFuncHash(fn)

return {
hash,
fn
}
}
21 changes: 21 additions & 0 deletions packages/core/test/defineWalletSetup.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, expect, it } from 'vitest'
import { defineWalletSetup } from '../src/defineWalletSetup'

const EXPECTED_HASH = '69620d59802a61c6900f'

const testWalletSetupFunction = async (): Promise<void> => {
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())
})
})
4 changes: 3 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.