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(allure-js-commons): detect pw expect #1159

Merged
merged 1 commit into from
Sep 26, 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
2 changes: 2 additions & 0 deletions packages/allure-js-commons/src/sdk/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const getStatusFromError = (error: Error): Status => {
case /assert/gi.test(error.name):
case /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:
return Status.FAILED;
default:
return Status.BROKEN;
Expand Down
50 changes: 50 additions & 0 deletions packages/allure-js-commons/test/sdk/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,56 @@ describe("getStatusFromError", () => {
});
});

describe("with any error with matcherResult field", () => {
class CustomError extends Error {
matcherResult = {};
}

it("returns failed", () => {
try {
throw new CustomError("something");
} catch (err) {
expect(getStatusFromError(err as Error)).toBe(Status.FAILED);
}
});
});

describe("with any error with playwright expect stack", () => {
it("returns failed", () => {
try {
// eslint-disable-next-line no-throw-literal
throw {
message: "some message",
stack:
" at Proxy.<anonymous> (node_modules/playwright/lib/matchers/expect.js:198:37)\n" +
" at Context.<anonymous> (test/spec/sample.js:6:13)\n" +
" at process.processImmediate (node:internal/timers:476:21)\n" +
" at process.callbackTrampoline (node:internal/async_hooks:130:17)",
} as Error;
} catch (err) {
expect(getStatusFromError(err as Error)).toBe(Status.FAILED);
}
});
});

describe("with any error with vitest expect stack", () => {
it("returns failed", () => {
try {
// eslint-disable-next-line no-throw-literal
throw {
message: "some message",
stack:
" at Proxy.<anonymous> (node_modules/@vitest/expect)\n" +
" at Context.<anonymous> (test/spec/sample.js:6:13)\n" +
" at process.processImmediate (node:internal/timers:476:21)\n" +
" at process.callbackTrampoline (node:internal/async_hooks:130:17)",
} as Error;
} catch (err) {
expect(getStatusFromError(err as Error)).toBe(Status.FAILED);
}
});
});

describe("with any not-assertion error", () => {
it("returns broken", () => {
try {
Expand Down
Loading