From cea220a02f6fd431067ffdc75729176bf3c2fe12 Mon Sep 17 00:00:00 2001 From: Vladimir Semenov Date: Thu, 15 Feb 2024 20:33:20 +0700 Subject: [PATCH 1/2] fix --- packages/allure-vitest/src/reporter.ts | 9 +++++---- .../allure-vitest/test/spec/direct/timeline.test.ts | 11 ++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/allure-vitest/src/reporter.ts b/packages/allure-vitest/src/reporter.ts index 58c0a9dd0..300258838 100644 --- a/packages/allure-vitest/src/reporter.ts +++ b/packages/allure-vitest/src/reporter.ts @@ -32,6 +32,7 @@ const { ALLURE_HOST_NAME, ALLURE_THREAD_NAME } = env; export default class AllureReporter implements Reporter { private allureRuntime: AllureRuntime; private options: AllureReporterOptions; + private hostname: string = ALLURE_HOST_NAME || hostname(); constructor(options: AllureReporterOptions) { this.options = options; @@ -113,7 +114,7 @@ export default class AllureReporter implements Reporter { const testDisplayName = currentTest.displayName || titleMetadata.cleanTitle; const links = currentTest.links ? this.processMetadataLinks(currentTest.links) : []; const labels: Label[] = [].concat(currentTest.labels || []).concat(titleMetadata.labels); - const test = parent.startTest(testDisplayName); + const test = parent.startTest(testDisplayName, task.result.startTime); const suitePath = getSuitePath(task); const normalizedTestPath = normalize(relative(cwd(), task.file.filepath)) .replace(/^\//, "") @@ -129,7 +130,7 @@ export default class AllureReporter implements Reporter { test.addLabel(LabelName.FRAMEWORK, "vitest"); test.addLabel(LabelName.LANGUAGE, "javascript"); test.addLabel(LabelName.THREAD, ALLURE_THREAD_NAME || pid.toString()); - test.addLabel(LabelName.HOST, ALLURE_HOST_NAME || hostname.toString()); + test.addLabel(LabelName.HOST, ALLURE_HOST_NAME || this.hostname.toString()); getSuitesLabels(suitePath).forEach((label) => { test.addLabel(label.name, label.value); @@ -158,8 +159,8 @@ export default class AllureReporter implements Reporter { break; } } - + const endTime = task.result ? (task.result.startTime + task.result.duration): undefined; test.calculateHistoryId(); - test.endTest(task.result?.duration); + test.endTest(endTime); } } diff --git a/packages/allure-vitest/test/spec/direct/timeline.test.ts b/packages/allure-vitest/test/spec/direct/timeline.test.ts index a90484885..c4ba1b24d 100644 --- a/packages/allure-vitest/test/spec/direct/timeline.test.ts +++ b/packages/allure-vitest/test/spec/direct/timeline.test.ts @@ -7,10 +7,19 @@ it("adds check thread and hostname", async () => { import { test } from "vitest"; import { attachment } from "allure-vitest"; - test("text attachment", async (t) => {}); + function sleep(milliseconds) { + return new Promise((resolve) => { + setTimeout(resolve, milliseconds); + }); + } + + test("text attachment", async (t) => { + await sleep(10); + }); `); expect(tests).toHaveLength(1); expect(tests[0].labels).toContainEqual({ name: LabelName.HOST, value: expect.any(String) }); expect(tests[0].labels).toContainEqual({ name: LabelName.THREAD, value: expect.any(String) }); + expect(tests[0].start || 0).toBeLessThan(tests[0].stop || 0); }); From 21092f32da7785fff3fa35be90157f99fd499ee1 Mon Sep 17 00:00:00 2001 From: Vladimir Semenov Date: Thu, 15 Feb 2024 22:15:30 +0700 Subject: [PATCH 2/2] fix --- packages/allure-vitest/src/reporter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/allure-vitest/src/reporter.ts b/packages/allure-vitest/src/reporter.ts index 300258838..3bff615bb 100644 --- a/packages/allure-vitest/src/reporter.ts +++ b/packages/allure-vitest/src/reporter.ts @@ -159,7 +159,7 @@ export default class AllureReporter implements Reporter { break; } } - const endTime = task.result ? (task.result.startTime + task.result.duration): undefined; + const endTime = task.result ? task.result.startTime + task.result.duration : undefined; test.calculateHistoryId(); test.endTest(endTime); }