Skip to content

Commit

Permalink
fix(allure-js-commons): detect pw expect (via #1159)
Browse files Browse the repository at this point in the history
  • Loading branch information
baev authored Sep 26, 2024
1 parent 5f877c5 commit 7cf6281
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
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

0 comments on commit 7cf6281

Please sign in to comment.