-
Notifications
You must be signed in to change notification settings - Fork 129
add global attachments and errors #1407
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3f42c81
add global attachments and errors
formaceft-93 6afd14b
fix mr issues
formaceft-93 754b802
split runtime and globalRuntime invocation
formaceft-93 3827b42
remove globals from legacies api
formaceft-93 63ddcf5
add timestamps and insta writing globals
formaceft-93 2d451c5
add timestamp test && fix vitest issue
formaceft-93 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
packages/allure-codeceptjs/test/spec/runtime/modern/globals.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import { expect, it } from "vitest"; | ||
| import { runCodeceptJsInlineTest } from "../../../utils.js"; | ||
|
|
||
| it("writes globals payload from scenario body", async () => { | ||
| const before = Date.now(); | ||
| const { globals, attachments } = await runCodeceptJsInlineTest({ | ||
| "login.test.js": ` | ||
| const { globalAttachment, globalError } = require("allure-js-commons"); | ||
|
|
||
| Feature("sample-feature"); | ||
| Scenario("sample-scenario", async () => { | ||
| await globalAttachment("global-log", "hello", { contentType: "text/plain" }); | ||
| await globalError({ message: "global setup failed", trace: "stack" }); | ||
| }); | ||
| `, | ||
| }); | ||
| const after = Date.now(); | ||
|
|
||
| const globalsEntries = Object.entries(globals ?? {}); | ||
| expect(globalsEntries.length).toBeGreaterThan(0); | ||
| globalsEntries.forEach(([globalsFileName]) => { | ||
| expect(globalsFileName).toMatch(/.+-globals\.json/); | ||
| }); | ||
|
|
||
| const allErrors = globalsEntries.flatMap(([, info]) => info.errors); | ||
| const allAttachments = globalsEntries.flatMap(([, info]) => info.attachments); | ||
| expect(allErrors).toEqual( | ||
| expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| message: "global setup failed", | ||
| trace: "stack", | ||
| timestamp: expect.any(Number), | ||
| }), | ||
| ]), | ||
| ); | ||
| allErrors.forEach((error) => { | ||
| expect(error.timestamp).toBeGreaterThanOrEqual(before); | ||
| expect(error.timestamp).toBeLessThanOrEqual(after); | ||
| }); | ||
| allAttachments.forEach((attachment) => { | ||
| expect(attachment.timestamp).toBeGreaterThanOrEqual(before); | ||
| expect(attachment.timestamp).toBeLessThanOrEqual(after); | ||
| }); | ||
| expect(allErrors.filter((error) => error.message === "global setup failed")).toHaveLength(1); | ||
| expect(allAttachments.filter((attachment) => attachment.name === "global-log")).toHaveLength(1); | ||
|
|
||
| const scenarioAttachment = allAttachments.find((a) => a.name === "global-log"); | ||
| expect(scenarioAttachment?.type).toBe("text/plain"); | ||
| const encodedScenarioAttachment = attachments[scenarioAttachment!.source] as string; | ||
| expect(Buffer.from(encodedScenarioAttachment, "base64").toString("utf-8")).toBe("hello"); | ||
| }); | ||
|
|
||
| it("writes globals payload from suite hooks", async () => { | ||
| const before = Date.now(); | ||
| const { globals, attachments } = await runCodeceptJsInlineTest({ | ||
| "login.test.js": ` | ||
| const { globalAttachment, globalError } = require("allure-js-commons"); | ||
|
|
||
| Feature("sample-feature"); | ||
| BeforeSuite(async () => { | ||
| await globalAttachment("before-suite-log", "before", { contentType: "text/plain" }); | ||
| }); | ||
|
|
||
| AfterSuite(async () => { | ||
| await globalError({ message: "after suite error" }); | ||
| }); | ||
|
|
||
| Scenario("sample-scenario", async () => {}); | ||
| `, | ||
| }); | ||
| const after = Date.now(); | ||
|
|
||
| const globalsEntries = Object.entries(globals ?? {}); | ||
| expect(globalsEntries.length).toBeGreaterThan(0); | ||
|
|
||
| const allErrors = globalsEntries.flatMap(([, info]) => info.errors); | ||
| const allAttachments = globalsEntries.flatMap(([, info]) => info.attachments); | ||
| expect(allErrors).toEqual( | ||
| expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| message: "after suite error", | ||
| timestamp: expect.any(Number), | ||
| }), | ||
| ]), | ||
| ); | ||
| allErrors.forEach((error) => { | ||
| expect(error.timestamp).toBeGreaterThanOrEqual(before); | ||
| expect(error.timestamp).toBeLessThanOrEqual(after); | ||
| }); | ||
| allAttachments.forEach((attachment) => { | ||
| expect(attachment.timestamp).toBeGreaterThanOrEqual(before); | ||
| expect(attachment.timestamp).toBeLessThanOrEqual(after); | ||
| }); | ||
|
|
||
| const beforeSuiteAttachment = allAttachments.find((a) => a.name === "before-suite-log"); | ||
| expect(beforeSuiteAttachment?.type).toBe("text/plain"); | ||
| const encodedBeforeSuiteAttachment = attachments[beforeSuiteAttachment!.source] as string; | ||
| expect(Buffer.from(encodedBeforeSuiteAttachment, "base64").toString("utf-8")).toBe("before"); | ||
| }); | ||
|
|
||
| it("does not collect globals from module scope", async () => { | ||
| const { globals, stdout } = await runCodeceptJsInlineTest({ | ||
| "login.test.js": ` | ||
| const { globalError } = require("allure-js-commons"); | ||
|
|
||
| void globalError({ message: "module scope error" }); | ||
|
|
||
| Feature("sample-feature"); | ||
| Scenario("sample-scenario", async () => {}); | ||
| `, | ||
| }); | ||
|
|
||
| const globalsEntries = Object.entries(globals ?? {}); | ||
| expect(globalsEntries).toHaveLength(0); | ||
| expect(stdout.join("\n")).toContain("no test runtime is found"); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/allure-cucumberjs/test/samples/support/runtime/modern/globals.cjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| const { Given } = require("@cucumber/cucumber"); | ||
| const { globalAttachment, globalError } = require("allure-js-commons"); | ||
|
|
||
| Given("a passed step", async () => { | ||
| await globalAttachment("global-log", "hello", { contentType: "text/plain" }); | ||
| await globalError({ message: "global setup failed", trace: "stack" }); | ||
| }); |
12 changes: 12 additions & 0 deletions
12
packages/allure-cucumberjs/test/samples/support/runtime/modern/globalsContexts.cjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| const { Before, After } = require("@cucumber/cucumber"); | ||
| const { globalAttachment, globalError } = require("allure-js-commons"); | ||
|
|
||
| void globalError({ message: "module scope error" }); | ||
|
|
||
| Before(async () => { | ||
| await globalAttachment("before-log", "before", { contentType: "text/plain" }); | ||
| }); | ||
|
|
||
| After(async () => { | ||
| await globalError({ message: "after hook error" }); | ||
| }); |
85 changes: 85 additions & 0 deletions
85
packages/allure-cucumberjs/test/spec/runtime/modern/globals.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import { expect, it } from "vitest"; | ||
| import { runCucumberInlineTest } from "../../../utils.js"; | ||
|
|
||
| it("writes globals payload from runtime API calls", async () => { | ||
| const { globals, attachments } = await runCucumberInlineTest(["hooks"], ["runtime/modern/globals"], { | ||
| parallel: false, | ||
| }); | ||
|
|
||
| const globalsEntries = Object.entries(globals ?? {}); | ||
| expect(globalsEntries.length).toBeGreaterThan(0); | ||
| globalsEntries.forEach(([globalsFileName]) => { | ||
| expect(globalsFileName).toMatch(/.+-globals\.json/); | ||
| }); | ||
|
|
||
| const allErrors = globalsEntries.flatMap(([, info]) => info.errors); | ||
| const allAttachments = globalsEntries.flatMap(([, info]) => info.attachments); | ||
| expect(allErrors).toEqual( | ||
| expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| message: "global setup failed", | ||
| trace: "stack", | ||
| timestamp: expect.any(Number), | ||
| }), | ||
| ]), | ||
| ); | ||
| allErrors.forEach((error) => { | ||
| expect(error.timestamp).toEqual(expect.any(Number)); | ||
| }); | ||
| allAttachments.forEach((attachment) => { | ||
| expect(attachment.timestamp).toEqual(expect.any(Number)); | ||
| }); | ||
| expect(allErrors.filter((error) => error.message === "global setup failed")).toHaveLength(1); | ||
| expect(allAttachments.filter((attachment) => attachment.name === "global-log")).toHaveLength(1); | ||
|
|
||
| const globalAttachmentRef = allAttachments.find((attachment) => attachment.name === "global-log"); | ||
| expect(globalAttachmentRef).toBeDefined(); | ||
| expect(globalAttachmentRef!.name).toBe("global-log"); | ||
| expect(globalAttachmentRef!.type).toBe("text/plain"); | ||
|
|
||
| const encodedAttachment = attachments[globalAttachmentRef!.source] as string; | ||
| expect(Buffer.from(encodedAttachment, "base64").toString("utf-8")).toBe("hello"); | ||
| }); | ||
|
|
||
| it("supports globals from hooks", async () => { | ||
| const { globals, attachments } = await runCucumberInlineTest(["hooks"], ["hooks", "runtime/modern/globalsContexts"], { | ||
| parallel: false, | ||
| }); | ||
|
|
||
| const globalsEntries = Object.entries(globals ?? {}); | ||
| expect(globalsEntries.length).toBeGreaterThan(0); | ||
|
|
||
| const allErrors = globalsEntries.flatMap(([, info]) => info.errors); | ||
| const allAttachments = globalsEntries.flatMap(([, info]) => info.attachments); | ||
| expect(allErrors).toEqual( | ||
| expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| message: "after hook error", | ||
| timestamp: expect.any(Number), | ||
| }), | ||
| ]), | ||
| ); | ||
| allErrors.forEach((error) => { | ||
| expect(error.timestamp).toEqual(expect.any(Number)); | ||
| }); | ||
| allAttachments.forEach((attachment) => { | ||
| expect(attachment.timestamp).toEqual(expect.any(Number)); | ||
| }); | ||
|
|
||
| const beforeAttachmentRef = allAttachments.find((a) => a.name === "before-log"); | ||
| expect(beforeAttachmentRef?.type).toBe("text/plain"); | ||
| const encodedAttachment = attachments[beforeAttachmentRef!.source] as string; | ||
| expect(Buffer.from(encodedAttachment, "base64").toString("utf-8")).toBe("before"); | ||
| }); | ||
|
|
||
| it("does not collect globals from support module scope", async () => { | ||
| const { globals } = await runCucumberInlineTest(["hooks"], ["hooks", "runtime/modern/globalsContexts"], { | ||
| parallel: false, | ||
| }); | ||
|
|
||
| const globalsEntries = Object.entries(globals ?? {}); | ||
| expect(globalsEntries.length).toBeGreaterThan(0); | ||
|
|
||
| const allErrors = globalsEntries.flatMap(([, info]) => info.errors); | ||
| expect(allErrors).not.toEqual(expect.arrayContaining([{ message: "module scope error" }])); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.