|
| 1 | +import { ContentType } from "allure-js-commons"; |
| 2 | +import { expect, it } from "vitest"; |
| 3 | + |
| 4 | +import { runCucumberInlineTest } from "../utils.js"; |
| 5 | + |
| 6 | +it("handles playwright trace attachments in after hooks", async () => { |
| 7 | + const { tests, groups, attachments } = await runCucumberInlineTest(["hookAttachments"], ["hookAttachments"]); |
| 8 | + |
| 9 | + expect(tests).toHaveLength(2); |
| 10 | + |
| 11 | + const traceTest = tests.find((t) => t.name === "trace attachment in after hook"); |
| 12 | + const regularTest = tests.find((t) => t.name === "regular attachment in after hook"); |
| 13 | + |
| 14 | + expect(traceTest).toBeDefined(); |
| 15 | + expect(regularTest).toBeDefined(); |
| 16 | + |
| 17 | + // playwright trace attachment should be in the test result |
| 18 | + expect(traceTest!.steps).toEqual( |
| 19 | + expect.arrayContaining([ |
| 20 | + expect.objectContaining({ |
| 21 | + name: "Given a passed step", |
| 22 | + status: "passed", |
| 23 | + }), |
| 24 | + expect.objectContaining({ |
| 25 | + name: "Playwright Trace", |
| 26 | + attachments: expect.arrayContaining([ |
| 27 | + expect.objectContaining({ |
| 28 | + name: "Playwright Trace", |
| 29 | + type: ContentType.PLAYWRIGHT_TRACE, |
| 30 | + }), |
| 31 | + ]), |
| 32 | + }), |
| 33 | + ]), |
| 34 | + ); |
| 35 | + |
| 36 | + // regular attachment should not be in the test result |
| 37 | + expect(regularTest!.steps).toEqual( |
| 38 | + expect.arrayContaining([ |
| 39 | + expect.objectContaining({ |
| 40 | + name: "Given a passed step", |
| 41 | + status: "passed", |
| 42 | + }), |
| 43 | + ]), |
| 44 | + ); |
| 45 | + expect(regularTest!.steps!.find((s) => s.name === "Text attachment")).toBeUndefined(); |
| 46 | + expect(regularTest!.attachments).toHaveLength(0); |
| 47 | + |
| 48 | + // regular attachment should be in the after fixture of the group |
| 49 | + expect(groups).toHaveLength(2); |
| 50 | + const regularGroup = groups.find((g) => g.afters?.some((a) => a.steps?.some((s) => s.name === "Text attachment"))); |
| 51 | + expect(regularGroup).toBeDefined(); |
| 52 | + expect(regularGroup!.afters).toEqual( |
| 53 | + expect.arrayContaining([ |
| 54 | + expect.objectContaining({ |
| 55 | + steps: expect.arrayContaining([ |
| 56 | + expect.objectContaining({ |
| 57 | + name: "Text attachment", |
| 58 | + attachments: expect.arrayContaining([ |
| 59 | + expect.objectContaining({ |
| 60 | + name: "Text attachment", |
| 61 | + type: "text/plain", |
| 62 | + }), |
| 63 | + ]), |
| 64 | + }), |
| 65 | + ]), |
| 66 | + }), |
| 67 | + ]), |
| 68 | + ); |
| 69 | + |
| 70 | + expect(Object.keys(attachments as object)).toHaveLength(2); |
| 71 | +}); |
0 commit comments