From a202e9daa592d5c2800b3efd1deec663a1dcff99 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Tue, 26 Mar 2024 16:02:13 +0100 Subject: [PATCH] fix: test name doesn't have the file anymore --- packages/vitest/src/integrations/chai/index.ts | 4 ++-- packages/vitest/src/runtime/runners/test.ts | 4 ++-- packages/vitest/src/utils/tasks.ts | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/vitest/src/integrations/chai/index.ts b/packages/vitest/src/integrations/chai/index.ts index 77650a3667ec8..9ed4c439202ce 100644 --- a/packages/vitest/src/integrations/chai/index.ts +++ b/packages/vitest/src/integrations/chai/index.ts @@ -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) { @@ -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 diff --git a/packages/vitest/src/runtime/runners/test.ts b/packages/vitest/src/runtime/runners/test.ts index f14f56274b428..e8e4057482497 100644 --- a/packages/vitest/src/runtime/runners/test.ts +++ b/packages/vitest/src/runtime/runners/test.ts @@ -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' @@ -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]) } diff --git a/packages/vitest/src/utils/tasks.ts b/packages/vitest/src/utils/tasks.ts index 54b613b76f73a..5188634862269 100644 --- a/packages/vitest/src/utils/tasks.ts +++ b/packages/vitest/src/utils/tasks.ts @@ -18,3 +18,7 @@ export function hasFailedSnapshot(suite: Arrayable): 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) +}