Skip to content

Commit

Permalink
✨ feat(core): Add defineWalletSetup function
Browse files Browse the repository at this point in the history
  • Loading branch information
duckception committed Oct 24, 2023
1 parent fd8edb1 commit d368c5d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
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.

0 comments on commit d368c5d

Please sign in to comment.