Skip to content

Commit

Permalink
[test visibility] Early Flake Detection for vitest (#4714)
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-fernandez committed Sep 30, 2024
1 parent bf12ecd commit 6c79d53
Show file tree
Hide file tree
Showing 4 changed files with 745 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, test, expect } from 'vitest'
import { sum } from './sum'

let numAttempt = 0
let numOtherAttempt = 0

describe('early flake detection', () => {
test('can retry tests that eventually pass', { repeats: process.env.SHOULD_REPEAT && 2 }, () => {
expect(sum(1, 2)).to.equal(numAttempt++ > 1 ? 3 : 4)
})

test('can retry tests that always pass', { repeats: process.env.SHOULD_REPEAT && 2 }, () => {
if (process.env.ALWAYS_FAIL) {
expect(sum(1, 2)).to.equal(4)
} else {
expect(sum(1, 2)).to.equal(3)
}
})

test('does not retry if it is not new', () => {
expect(sum(1, 2)).to.equal(3)
})

test.skip('does not retry if the test is skipped', () => {
expect(sum(1, 2)).to.equal(3)
})

if (process.env.SHOULD_ADD_EVENTUALLY_FAIL) {
test('can retry tests that eventually fail', () => {
expect(sum(1, 2)).to.equal(numOtherAttempt++ < 3 ? 3 : 4)
})
}
})
Loading

0 comments on commit 6c79d53

Please sign in to comment.