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 vitest duration #1192

Merged
merged 3 commits into from
Nov 20, 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
457 changes: 219 additions & 238 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/mlly-npm-1.6.1-947df259c8-00b4c35523.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/allure-codeceptjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"npm-run-all2": "^7.0.0",
"rimraf": "^6.0.0",
"typescript": "^5.2.2",
"vitest": "^1.6.0"
"vitest": "^2.1.5"
},
"peerDependencies": {
"codeceptjs": ">=2.3.6"
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-cucumberjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"npm-run-all2": "^7.0.0",
"rimraf": "^6.0.0",
"typescript": "^5.2.2",
"vitest": "^1.6.0"
"vitest": "^2.1.5"
},
"peerDependencies": {
"@cucumber/cucumber": ">=10.8.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"npm-run-all2": "^7.0.0",
"rimraf": "^6.0.0",
"typescript": "^5.2.2",
"vitest": "^1.6.0"
"vitest": "^2.1.5"
},
"peerDependencies": {
"cypress": ">=12.17.4"
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-jasmine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"npm-run-all2": "^7.0.0",
"rimraf": "^6.0.0",
"typescript": "^5.2.2",
"vitest": "^1.6.0"
"vitest": "^2.1.5"
},
"peerDependencies": {
"jasmine": ">=2.7.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"npm-run-all2": "^7.0.0",
"rimraf": "^6.0.0",
"typescript": "^5.2.2",
"vitest": "^1.6.0"
"vitest": "^2.1.5"
},
"peerDependencies": {
"jest": ">=24.8.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-js-commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"npm-run-all2": "^7.0.0",
"rimraf": "^6.0.0",
"typescript": "^5.2.2",
"vitest": "^1.6.0"
"vitest": "^2.1.5"
},
"peerDependencies": {
"allure-playwright": "workspace:*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,9 @@ export class ReporterRuntime {
result.start = result.stop;
}
}
return result;
return {
start: result.start ? Math.round(result.start) : undefined,
stop: result.stop ? Math.round(result.stop) : undefined,
};
};
}
6 changes: 3 additions & 3 deletions packages/allure-js-commons/src/sdk/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { FixtureResult, Label, StatusDetails, StepResult, TestResult } from
import { LabelName, Status } from "../model.js";
import type { RuntimeMessage, SerializeOptions } from "./types.js";

export const getStatusFromError = (error: Error): Status => {
export const getStatusFromError = (error: Partial<Error>): Status => {
switch (true) {
/**
* Native `node:assert` and `chai` (`vitest` uses it under the hood) throw `AssertionError`
Expand All @@ -12,8 +12,8 @@ export const getStatusFromError = (error: Error): Status => {
*/
case /assert/gi.test(error.constructor.name):
case /expectation/gi.test(error.constructor.name):
case /assert/gi.test(error.name):
case /assert/gi.test(error.message):
case error.name && /assert/gi.test(error.name):
case error.message && /assert/gi.test(error.message):
case error.stack && /@vitest\/expect/gi.test(error.stack):
case error.stack && /playwright\/lib\/matchers\/expect\.js/gi.test(error.stack):
case "matcherResult" in error:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ describe("ReporterRuntime", () => {
expect(testResult.start).toBe(start);
expect(testResult.stop).toBe(start + duration);
});
it("should round timings after stop", () => {
const writer = mockWriter();
const runtime = new ReporterRuntime({ writer });

const start = randomInt(10_000_000) + 0.23;
const duration = randomInt(100_000) + 0.43;
const rootUuid = runtime.startTest({ start });
runtime.stopTest(rootUuid, { duration });
runtime.writeTest(rootUuid);

const [testResult] = writer.writeResult.mock.calls[0];
expect(testResult.start).toBe(Math.round(start));
expect(testResult.stop).toBe(Math.round(start + duration));
});

it("should set test stop from stop", () => {
const writer = mockWriter();
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-mocha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"npm-run-all2": "^7.0.0",
"rimraf": "^6.0.0",
"typescript": "^5.2.2",
"vitest": "^1.6.0"
"vitest": "^2.1.5"
},
"peerDependencies": {
"mocha": ">=6.2.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"npm-run-all2": "^7.0.0",
"rimraf": "^6.0.0",
"typescript": "^5.2.2",
"vitest": "^1.6.0"
"vitest": "^2.1.5"
},
"peerDependencies": {
"@playwright/test": ">=1.36.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/allure-vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@types/node": "^20.14.2",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"@vitest/runner": "^1.6.0",
"@vitest/runner": "^2.1.5",
"allure-commandline": "^2.29.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
Expand All @@ -72,7 +72,7 @@
"npm-run-all2": "^7.0.0",
"rimraf": "^6.0.0",
"typescript": "^5.2.2",
"vitest": "^1.6.0"
"vitest": "^2.1.5"
},
"peerDependencies": {
"@vitest/runner": ">=1.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-vitest/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const getSuitePath = (task: Task): string[] => {

export const getTestMetadata = (task: Task) => {
const suitePath = getSuitePath(task);
const relativeTestPath = getPosixPath(getRelativePath(task.file!.filepath));
const relativeTestPath = getPosixPath(getRelativePath(task.file.filepath));

const { cleanTitle, labels } = extractMetadataFromString(task.name);

Expand Down
39 changes: 39 additions & 0 deletions packages/allure-vitest/test/spec/duration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { describe, expect, it } from "vitest";
import { runVitestInlineTest } from "../utils.js";

describe("test timings", () => {
it("should set correct timings for tests", async () => {
const before = new Date().getTime();
const { tests } = await runVitestInlineTest(`
import { test, expect } from "vitest";

test("sample test", async () => {
expect(1).toBe(1);
});
`);
const after = new Date().getTime();

expect(tests).toHaveLength(1);
const [tr] = tests;

expect(tr.start).toBeGreaterThanOrEqual(before);
expect(tr.start).toBeLessThanOrEqual(after);
expect(tr.stop).toBeGreaterThanOrEqual(tr.start!);
});

it("should set integer timings for tests", async () => {
const { tests } = await runVitestInlineTest(`
import { test, expect } from "vitest";

test("sample test", async () => {
expect(1).toBe(1);
});
`);

expect(tests).toHaveLength(1);
const [tr] = tests;

expect(tr.start).toStrictEqual(Math.trunc(tr.start!));
expect(tr.stop).toStrictEqual(Math.trunc(tr.stop!));
});
});
2 changes: 1 addition & 1 deletion packages/allure-vitest/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const runVitestInlineTest = async (
});
});

const modulePath = require.resolve("vitest/dist/cli-wrapper.js");
const modulePath = require.resolve("vitest/dist/cli.js");
const args = ["run", "--config", configFilePath, "--dir", testDir];
const testProcess = await step(`${modulePath} ${args.join(" ")}`, () => {
return fork(modulePath, args, {
Expand Down
2 changes: 1 addition & 1 deletion packages/newman-reporter-allure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"postman-collection": "^4.2.1",
"rimraf": "^6.0.0",
"typescript": "^5.2.2",
"vitest": "^1.6.0"
"vitest": "^2.1.5"
},
"peerDependencies": {
"newman": ">=3.5.0"
Expand Down
Loading
Loading