-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup testing framework vitest (#28)
* feat: added vitest harness and initial tests * feat: added coverage reporting * feat: add tests to workflow * chore: readd tsconfig * chore: changeset * fix: testing workflow * chore: cleanup logs
- Loading branch information
1 parent
51c326d
commit 779e924
Showing
10 changed files
with
1,215 additions
and
17 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,5 @@ | ||
--- | ||
'@fedimint/core-web': patch | ||
--- | ||
|
||
Set up vitest testing framework |
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 |
---|---|---|
|
@@ -20,17 +20,30 @@ | |
"changeset:prepublish": "pnpm run build", | ||
"version": "changeset version", | ||
"typecheck": "pnpm run --r --parallel typecheck", | ||
"coverage": "vitest run --coverage", | ||
"test": "pnpm run test:headless", | ||
"test:coverage": "vitest run --coverage", | ||
"test:headless": "vitest", | ||
"test:ui": "vitest --browser.headless=false --ui", | ||
"format": "prettier --write .", | ||
"watch": "pnpm run --r --parallel --filter \"./packages/**\" watch" | ||
}, | ||
"devDependencies": { | ||
"@changesets/cli": "^2.27.7", | ||
"@types/bun": "^1.1.1", | ||
"@types/node": "^20.14.8", | ||
"@vitest/browser": "^2.1.1", | ||
"@vitest/coverage-v8": "^2.1.1", | ||
"@vitest/ui": "^2.1.1", | ||
"glob": "^10.3.12", | ||
"happy-dom": "^15.7.4", | ||
"playwright": "^1.47.1", | ||
"prettier": "^3.3.3", | ||
"sherif": "^0.8.4", | ||
"simple-git-hooks": "^2.11.1", | ||
"typescript": "5.5.2" | ||
"typescript": "5.5.2", | ||
"vite-plugin-wasm": "^3.3.0", | ||
"vitest": "^2.1.1" | ||
}, | ||
"packageManager": "[email protected]", | ||
"engines": { | ||
|
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,76 @@ | ||
import { test, expect, vi } from 'vitest' | ||
import { FedimintWallet } from './FedimintWallet' | ||
import { beforeAll } from 'vitest' | ||
|
||
let randomTestingId: string | ||
let wallet: FedimintWallet | ||
// Testnet | ||
const TESTING_FEDERATION = | ||
'fed11qgqrgvnhwden5te0v9k8q6rp9ekh2arfdeukuet595cr2ttpd3jhq6rzve6zuer9wchxvetyd938gcewvdhk6tcqqysptkuvknc7erjgf4em3zfh90kffqf9srujn6q53d6r056e4apze5cw27h75' | ||
|
||
beforeAll(() => { | ||
randomTestingId = Math.random().toString(36).substring(2, 15) | ||
wallet = new FedimintWallet() | ||
expect(wallet).toBeDefined() | ||
|
||
// Cleanup after all tests | ||
return async () => { | ||
// clear up browser resources | ||
await wallet.cleanup() | ||
// remove the wallet db | ||
indexedDB.deleteDatabase(randomTestingId) | ||
// swap out the randomTestingId for a new one, to avoid raciness | ||
randomTestingId = Math.random().toString(36).substring(2, 15) | ||
} | ||
}) | ||
|
||
test('initial open & join', async () => { | ||
expect(wallet).toBeDefined() | ||
expect(wallet.isOpen()).toBe(false) | ||
// On initial open, it should return false | ||
// because no federations have been joined | ||
await expect(wallet.open(randomTestingId)).resolves.toBe(false) | ||
await expect( | ||
wallet.joinFederation(TESTING_FEDERATION, randomTestingId), | ||
).resolves.toBeUndefined() | ||
expect(wallet.isOpen()).toBe(true) | ||
await expect(wallet.waitForOpen()).resolves.toBeUndefined() | ||
}) | ||
|
||
test('Error on open & join if wallet is already open', async () => { | ||
expect(wallet).toBeDefined() | ||
expect(wallet.isOpen()).toBe(true) | ||
|
||
// Test opening an already open wallet | ||
try { | ||
await wallet.open(randomTestingId) | ||
} catch (error) { | ||
expect(error).toBeInstanceOf(Error) | ||
expect((error as Error).message).toBe( | ||
'The FedimintWallet is already open. You can only call `FedimintWallet.open on closed clients.`', | ||
) | ||
} | ||
|
||
// Test joining federation on an already open wallet | ||
try { | ||
await wallet.joinFederation(TESTING_FEDERATION, randomTestingId) | ||
} catch (error) { | ||
expect(error).toBeInstanceOf(Error) | ||
expect((error as Error).message).toBe( | ||
'The FedimintWallet is already open. You can only call `FedimintWallet.joinFederation` on closed clients.', | ||
) | ||
} | ||
}) | ||
test('getConfig', async () => { | ||
expect(wallet).toBeDefined() | ||
expect(wallet.isOpen()).toBe(true) | ||
const config = await wallet.getConfig() | ||
expect(config).toBeDefined() | ||
}) | ||
|
||
test('empty getBalance', async () => { | ||
expect(wallet).toBeDefined() | ||
expect(wallet.isOpen()).toBe(true) | ||
await expect(wallet.waitForOpen()).resolves.toBeUndefined() | ||
await expect(wallet.getBalance()).resolves.toEqual(0) | ||
}) |
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
Oops, something went wrong.