Skip to content

Commit

Permalink
fix: test name doesn't have the file anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Mar 26, 2024
1 parent e2fd18e commit a202e9d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/vitest/src/integrations/chai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getCurrentTest } from '@vitest/runner'
import { ASYMMETRIC_MATCHERS_OBJECT, GLOBAL_EXPECT, addCustomEqualityTesters, getState, setState } from '@vitest/expect'
import type { Assertion, ExpectStatic } from '@vitest/expect'
import type { MatcherState } from '../../types/chai'
import { getFullName } from '../../utils/tasks'
import { getTestName } from '../../utils/tasks'
import { getCurrentEnvironment, getWorkerState } from '../../utils/global'

export function createExpect(test?: TaskPopulated) {
Expand Down Expand Up @@ -42,7 +42,7 @@ export function createExpect(test?: TaskPopulated) {
expectedAssertionsNumberErrorGen: null,
environment: getCurrentEnvironment(),
testPath,
currentTestName: test ? getFullName(test as Test) : globalState.currentTestName,
currentTestName: test ? getTestName(test as Test) : globalState.currentTestName,
}, expect)

// @ts-expect-error untyped
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/runtime/runners/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ExpectStatic } from '@vitest/expect'
import { GLOBAL_EXPECT, getState, setState } from '@vitest/expect'
import { getSnapshotClient } from '../../integrations/snapshot/chai'
import { vi } from '../../integrations/vi'
import { getFullName, getNames, getTests, getWorkerState } from '../../utils'
import { getNames, getTestName, getTests, getWorkerState } from '../../utils'
import { createExpect } from '../../integrations/chai/index'
import type { ResolvedConfig } from '../../types/config'
import type { VitestExecutor } from '../execute'
Expand Down Expand Up @@ -99,7 +99,7 @@ export class VitestTestRunner implements VitestRunner {
expectedAssertionsNumber: null,
expectedAssertionsNumberErrorGen: null,
testPath: test.file.filepath,
currentTestName: getFullName(test),
currentTestName: getTestName(test),
snapshotState: this.snapshotClient.snapshotState,
}, (globalThis as any)[GLOBAL_EXPECT])
}
Expand Down
4 changes: 4 additions & 0 deletions packages/vitest/src/utils/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ export function hasFailedSnapshot(suite: Arrayable<Task>): boolean {
export function getFullName(task: Task, separator = ' > ') {
return getNames(task).join(separator)
}

export function getTestName(task: Task, separator = ' > ') {
return getNames(task).slice(1).join(separator)
}

0 comments on commit a202e9d

Please sign in to comment.