Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading