Skip to content

Commit

Permalink
fix: mark test as failed when regression test does not fail
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jan 28, 2022
1 parent e3bf454 commit ce99251
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/Tracker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,32 +168,55 @@ export class Tracker {
*/
this.aggregates.total++

/**
* Test was skipped
*/
if (payload.isSkipped) {
this.aggregates.skipped++
return
}

/**
* Test was a todo
*/
if (payload.isTodo) {
this.aggregates.todo++
return
}

/**
* Test completed successfully
* Regression test. Mark test as failed, when there is no error
* Because, we expect regression tests to have errors.
*
* However, there is no need to move anything to the failure
* tree, since there is no real error
*/
if (!payload.hasError) {
this.aggregates.passed++
if (payload.isFailing) {
if (!payload.hasError) {
this.aggregates.failed++
this.hasError = true
} else {
this.aggregates.regression++
}

return
}

/**
* Test has error, but is regression test
* Test completed successfully
*/
if (payload.hasError && payload.isFailing) {
this.aggregates.regression++
if (!payload.hasError) {
this.aggregates.passed++
return
}

this.markTestAsFailed(payload)
}

/**
* Mark test as failed
*/
private markTestAsFailed(payload: TestEndNode) {
/**
* Bump failed count
*/
Expand Down
45 changes: 45 additions & 0 deletions test/tracker/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,49 @@ test.group('Tracker', () => {
])
assert.deepEqual(summary.failedTestsTitles, [])
})

test('mark test as failed when regression test passes', async (assert) => {
const emitter = new Emitter()
const refiner = new Refiner({})
const tracker = new Tracker()

const runner = new Runner(emitter)
const unit = new Suite('unit', emitter)
const functional = new Suite('functional', emitter)

const group = new Group('arithmetic', emitter, refiner)
const testInstance = new Test('test', new TestContext(), emitter, refiner)
testInstance.run(() => {})

const testInstance1 = new Test('test 1', new TestContext(), emitter, refiner)
testInstance1.run(() => {}).fails()

runner.add(unit).add(functional)
unit.add(group)
group.add(testInstance1)

functional.add(testInstance)

emitter.on('runner:start', (payload) => tracker.processEvent('runner:start', payload))
emitter.on('runner:end', (payload) => tracker.processEvent('runner:end', payload))
emitter.on('suite:start', (payload) => tracker.processEvent('suite:start', payload))
emitter.on('suite:end', (payload) => tracker.processEvent('suite:end', payload))
emitter.on('group:start', (payload) => tracker.processEvent('group:start', payload))
emitter.on('group:end', (payload) => tracker.processEvent('group:end', payload))
emitter.on('test:start', (payload) => tracker.processEvent('test:start', payload))
emitter.on('test:end', (payload) => tracker.processEvent('test:end', payload))

await Promise.all([pEvent(emitter, 'runner:end'), runner.exec()])
const summary = tracker.getSummary()
assert.isTrue(summary.hasError)
assert.deepEqual(summary.runnerErrors, [])
assert.equal(summary.total, 2)
assert.equal(summary.passed, 1)
assert.equal(summary.skipped, 0)
assert.equal(summary.todo, 0)
assert.equal(summary.failed, 1)
assert.equal(summary.regression, 0)
assert.deepEqual(summary.failureTree, [])
assert.deepEqual(summary.failedTestsTitles, [])
})
})

0 comments on commit ce99251

Please sign in to comment.