Skip to content

Commit

Permalink
fix: don't mark suites state since they are calculated based on child…
Browse files Browse the repository at this point in the history
…ren (#419)

* fix: don't mark suites state since they are calculated based on children

* test: correct tests for test results

* chore: cleanup
  • Loading branch information
sheremet-va committed Jun 18, 2024
1 parent 3527491 commit 32ac59a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
39 changes: 23 additions & 16 deletions src/runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { rm } from 'node:fs/promises'
import stripAnsi from 'strip-ansi'
import * as vscode from 'vscode'
import { getTasks } from '@vitest/ws-client'
import type { ErrorWithDiff, File, ParsedStack, Task, TaskResult } from 'vitest'
import type { ErrorWithDiff, File, ParsedStack, TaskResult } from 'vitest'
import { basename, normalize, relative } from 'pathe'
import { TestFile, TestFolder, getTestData } from '../testTreeData'
import { TestCase, TestFile, TestFolder, getTestData } from '../testTreeData'
import type { TestTree } from '../testTree'
import type { VitestFolderAPI } from '../api'
import { log } from '../log'
Expand Down Expand Up @@ -75,7 +75,7 @@ export class TestRunner extends vscode.Disposable {
if (task.mode === 'skip' || task.mode === 'todo')
testRun.skipped(test)
else
this.markResult(testRun, test, task.result, task)
this.markResult(testRun, test, task.result)
})
})

Expand All @@ -95,7 +95,7 @@ export class TestRunner extends vscode.Disposable {
files.forEach((file) => {
const testItem = this.tree.getTestItemByTask(file)
if (testItem)
this.markResult(testRun, testItem, file.result, file)
this.markResult(testRun, testItem, file.result)
})

if (unhandledError)
Expand Down Expand Up @@ -333,24 +333,31 @@ export class TestRunner extends vscode.Disposable {
})
}

private markResult(testRun: vscode.TestRun, test: vscode.TestItem, result?: TaskResult, task?: Task) {
private markResult(testRun: vscode.TestRun, test: vscode.TestItem, result?: TaskResult) {
const isTestCase = getTestData(test) instanceof TestCase

// generally, we shouldn't mark non test cases because
// parents are calculated based on children
if (!isTestCase) {
if (result?.state === 'fail') {
// errors in a suite are stored only if it happens during discovery
const errors = result.errors?.map(err =>
err.stack || err.message,
)
if (!errors?.length)
return
test.error = errors.join('\n')
}
return
}

if (!result) {
testRun.started(test)
return
}

switch (result.state) {
case 'fail': {
// error in a suite doesn't mean test fail
if (task?.type === 'suite') {
const errors = result.errors?.map(err =>
new vscode.TestMessage(err.stack || err.message),
)
if (!errors)
return
test.error = errors.map(e => e.message.toString()).join('\n')
testRun.errored(test, errors, result.duration)
return
}
const errors = result.errors?.map(err =>
testMessageForTestError(test, err),
) || []
Expand Down
4 changes: 2 additions & 2 deletions test-e2e/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('basic', async ({ launch }) => {

await tester.runAllTests()

await expect(tester.tree.getResults()).toHaveText('3/7')
await expect(tester.tree.getResults()).toHaveText('2/4')
await expect(tester.tree.getFileItem('pass.test.ts')).toHaveState('passed')
await expect(tester.tree.getFileItem('fail.test.ts')).toHaveState('failed')
await expect(tester.tree.getFileItem('mix.test.ts')).toHaveState('failed')
Expand All @@ -36,7 +36,7 @@ test('custom imba language', async ({ launch }) => {

await tester.runAllTests()

await expect(tester.tree.getResults()).toHaveText('5/7')
await expect(tester.tree.getResults()).toHaveText('3/4')
await expect(tester.tree.getFileItem('basic.test.imba')).toHaveState('passed')
await expect(tester.tree.getFileItem('utils.imba')).toHaveState('passed')
await expect(tester.tree.getFileItem('counter.imba')).toHaveState('failed')
Expand Down

0 comments on commit 32ac59a

Please sign in to comment.