Skip to content

Commit

Permalink
Fix flaky tests and add utility to debug flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hyphenized committed Feb 11, 2023
1 parent 0419b9d commit 4ff6cc4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
9 changes: 7 additions & 2 deletions background/services/chain/tests/db.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ describe("Chain Database ", () => {
expect(await db.getAccountsToTrack()).toHaveLength(1)
await db.addAccountToTrack(account2)
const accountsToTrack = await db.getAccountsToTrack()
expect(accountsToTrack).toEqual([account1, account2])
expect(accountsToTrack).toEqual(
expect.arrayContaining([account1, account2])
)
})

it("should not add the same account twice.", async () => {
Expand Down Expand Up @@ -127,7 +129,10 @@ describe("Chain Database ", () => {
expect(await db.getAccountsToTrack()).toHaveLength(1)
await db.addAccountToTrack(account2)
const accountsToTrack = await db.getAccountsToTrack()
expect(accountsToTrack).toEqual([account1, account2])

expect(accountsToTrack).toEqual(
expect.arrayContaining([account1, account2])
)
})
})
describe("getAllSavedTransactionHashes", () => {
Expand Down
21 changes: 21 additions & 0 deletions setupJest.env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,24 @@ beforeEach(() => {
afterEach(() => {
global.indexedDB = new IDBFactory()
})

it.flaky = function checkFlaky(label: string, testCase: () => unknown): void {
// eslint-disable-next-line no-only-tests/no-only-tests
it.only(label, () => {
const results = []
for (let i = 0; i < 2000; i += 1) {
results.push(testCase())
}
return Promise.all(results)
})
}

// eslint-disable-next-line @typescript-eslint/no-namespace, @typescript-eslint/no-unused-vars
declare namespace jest {
interface It {
/**
* Used for debugging flaky tests
*/
flaky: (label: string, testCase: () => unknown) => void
}
}

0 comments on commit 4ff6cc4

Please sign in to comment.