-
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.
Feat: adds testing fixtures for setup/teardown (#51)
* feat: disable screenshots on failed tests * feat: add worker unit tests
- Loading branch information
1 parent
3b343fa
commit 6915c97
Showing
9 changed files
with
295 additions
and
173 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
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
128 changes: 58 additions & 70 deletions
128
packages/core-web/src/services/FederationService.test.ts
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 |
---|---|---|
@@ -1,70 +1,58 @@ | ||
import { test, expect } from 'vitest' | ||
import { TestFedimintWallet } from '../test/TestFedimintWallet' | ||
import { beforeAll } from 'vitest' | ||
|
||
let randomTestingId: string | ||
let wallet: TestFedimintWallet | ||
|
||
beforeAll(async () => { | ||
randomTestingId = Math.random().toString(36).substring(2, 15) | ||
wallet = new TestFedimintWallet() | ||
expect(wallet).toBeDefined() | ||
await expect( | ||
wallet.joinFederation(wallet.testing.TESTING_INVITE, randomTestingId), | ||
).resolves.toBeUndefined() | ||
expect(wallet.isOpen()).toBe(true) | ||
|
||
// 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('getConfig should return the federation config', async () => { | ||
expect(wallet).toBeDefined() | ||
expect(wallet.isOpen()).toBe(true) | ||
const counterBefore = wallet.testing.getRequestCounter() | ||
await expect(wallet.federation.getConfig()).resolves.toMatchObject({ | ||
api_endpoints: expect.any(Object), | ||
broadcast_public_keys: expect.any(Object), | ||
consensus_version: expect.any(Object), | ||
meta: expect.any(Object), | ||
modules: expect.any(Object), | ||
}) | ||
expect(wallet.testing.getRequestCounter()).toBe(counterBefore + 1) | ||
}) | ||
|
||
test('getFederationId should return the federation id', async () => { | ||
expect(wallet).toBeDefined() | ||
expect(wallet.isOpen()).toBe(true) | ||
|
||
const counterBefore = wallet.testing.getRequestCounter() | ||
const federationId = await wallet.federation.getFederationId() | ||
expect(federationId).toBeTypeOf('string') | ||
expect(federationId).toHaveLength(64) | ||
expect(wallet.testing.getRequestCounter()).toBe(counterBefore + 1) | ||
}) | ||
|
||
test('getInviteCode should return the invite code', async () => { | ||
expect(wallet).toBeDefined() | ||
expect(wallet.isOpen()).toBe(true) | ||
|
||
const counterBefore = wallet.testing.getRequestCounter() | ||
const inviteCode = await wallet.federation.getInviteCode(0) | ||
expect(inviteCode).toBeTypeOf('string') | ||
expect(wallet.testing.getRequestCounter()).toBe(counterBefore + 1) | ||
}) | ||
|
||
test('listOperations should return the list of operations', async () => { | ||
expect(wallet).toBeDefined() | ||
expect(wallet.isOpen()).toBe(true) | ||
|
||
const counterBefore = wallet.testing.getRequestCounter() | ||
await expect(wallet.federation.listOperations()).resolves.toMatchObject([]) | ||
expect(wallet.testing.getRequestCounter()).toBe(counterBefore + 1) | ||
}) | ||
import { expect } from 'vitest' | ||
import { walletTest } from '../test/setupTests' | ||
|
||
walletTest( | ||
'getConfig should return the federation config', | ||
async ({ wallet }) => { | ||
expect(wallet).toBeDefined() | ||
expect(wallet.isOpen()).toBe(true) | ||
const counterBefore = wallet.testing.getRequestCounter() | ||
await expect(wallet.federation.getConfig()).resolves.toMatchObject({ | ||
api_endpoints: expect.any(Object), | ||
broadcast_public_keys: expect.any(Object), | ||
consensus_version: expect.any(Object), | ||
meta: expect.any(Object), | ||
modules: expect.any(Object), | ||
}) | ||
expect(wallet.testing.getRequestCounter()).toBe(counterBefore + 1) | ||
}, | ||
) | ||
|
||
walletTest( | ||
'getFederationId should return the federation id', | ||
async ({ wallet }) => { | ||
expect(wallet).toBeDefined() | ||
expect(wallet.isOpen()).toBe(true) | ||
|
||
const counterBefore = wallet.testing.getRequestCounter() | ||
const federationId = await wallet.federation.getFederationId() | ||
expect(federationId).toBeTypeOf('string') | ||
expect(federationId).toHaveLength(64) | ||
expect(wallet.testing.getRequestCounter()).toBe(counterBefore + 1) | ||
}, | ||
) | ||
|
||
walletTest( | ||
'getInviteCode should return the invite code', | ||
async ({ wallet }) => { | ||
expect(wallet).toBeDefined() | ||
expect(wallet.isOpen()).toBe(true) | ||
|
||
const counterBefore = wallet.testing.getRequestCounter() | ||
const inviteCode = await wallet.federation.getInviteCode(0) | ||
expect(inviteCode).toBeTypeOf('string') | ||
expect(wallet.testing.getRequestCounter()).toBe(counterBefore + 1) | ||
}, | ||
) | ||
|
||
walletTest( | ||
'listOperations should return the list of operations', | ||
async ({ wallet }) => { | ||
expect(wallet).toBeDefined() | ||
expect(wallet.isOpen()).toBe(true) | ||
|
||
const counterBefore = wallet.testing.getRequestCounter() | ||
await expect(wallet.federation.listOperations()).resolves.toMatchObject([]) | ||
expect(wallet.testing.getRequestCounter()).toBe(counterBefore + 1) | ||
}, | ||
) |
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.