diff --git a/packages/allure-cypress/src/reporter.ts b/packages/allure-cypress/src/reporter.ts index 2003bb3d1..360564422 100644 --- a/packages/allure-cypress/src/reporter.ts +++ b/packages/allure-cypress/src/reporter.ts @@ -64,6 +64,9 @@ export class AllureCypress { this.createEmptyRunContext(run.spec.absolute); this.endSpec(run.spec, run.video || undefined); }); + + this.allureRuntime.writeEnvironmentInfo(); + this.allureRuntime.writeCategoriesDefinitions(); } endSpec(spec: Cypress.Spec, cypressVideoPath?: string) { diff --git a/packages/allure-cypress/test/spec/categories.spec.ts b/packages/allure-cypress/test/spec/categories.spec.ts new file mode 100644 index 000000000..74ac14e8f --- /dev/null +++ b/packages/allure-cypress/test/spec/categories.spec.ts @@ -0,0 +1,72 @@ +import { expect, it } from "vitest"; +import { Status } from "allure-js-commons"; +import { runCypressInlineTest } from "../utils.js"; + +it("has categories", async () => { + const { categories } = await runCypressInlineTest({ + "cypress/e2e/sample.cy.js": () => ` + it('sample test', () => {}); + `, + "cypress.config.js": ({ allureCypressModuleBasePath }) => ` + const { allureCypress } = require("${allureCypressModuleBasePath}/reporter.js"); + + module.exports = { + e2e: { + baseUrl: "https://allurereport.org", + viewportWidth: 1240, + setupNodeEvents: (on, config) => { + allureCypress(on, { + categories: [ + { + name: "Sad tests", + messageRegex: ".*Sad.*", + matchedStatuses: ["${Status.FAILED}"], + }, + { + name: "Infrastructure problems", + messageRegex: ".*RuntimeException.*", + matchedStatuses: ["${Status.BROKEN}"], + }, + { + name: "Outdated tests", + messageRegex: ".*FileNotFound.*", + matchedStatuses: ["${Status.BROKEN}"], + }, + { + name: "Regression", + messageRegex: "${String.raw`.*\\sException:.*`}", + matchedStatuses: ["${Status.BROKEN}"], + }, + ] + }); + + return config; + }, + }, + }; + `, + }); + + expect(categories).toEqual([ + { + name: "Sad tests", + messageRegex: ".*Sad.*", + matchedStatuses: [Status.FAILED], + }, + { + name: "Infrastructure problems", + messageRegex: ".*RuntimeException.*", + matchedStatuses: [Status.BROKEN], + }, + { + name: "Outdated tests", + messageRegex: ".*FileNotFound.*", + matchedStatuses: [Status.BROKEN], + }, + { + name: "Regression", + messageRegex: ".*\\sException:.*", + matchedStatuses: [Status.BROKEN], + }, + ]); +}); diff --git a/packages/allure-cypress/test/spec/environmentInfo.spec.ts b/packages/allure-cypress/test/spec/environmentInfo.spec.ts new file mode 100644 index 000000000..b19a4f360 --- /dev/null +++ b/packages/allure-cypress/test/spec/environmentInfo.spec.ts @@ -0,0 +1,35 @@ +import { expect, it } from "vitest"; +import { runCypressInlineTest } from "../utils.js"; + +it("has environment info", async () => { + const { envInfo } = await runCypressInlineTest({ + "cypress/e2e/sample.cy.js": () => ` + it('sample test', () => {}); + `, + "cypress.config.js": ({ allureCypressModuleBasePath }) => ` + const { allureCypress } = require("${allureCypressModuleBasePath}/reporter.js"); + + module.exports = { + e2e: { + baseUrl: "https://allurereport.org", + viewportWidth: 1240, + setupNodeEvents: (on, config) => { + allureCypress(on, { + environmentInfo: { + envVar1: "envVar1Value", + envVar2: "envVar2Value", + }, + }); + + return config; + }, + }, + }; + `, + }); + + expect(envInfo).toEqual({ + envVar1: "envVar1Value", + envVar2: "envVar2Value", + }); +}); diff --git a/packages/allure-cypress/test/utils.ts b/packages/allure-cypress/test/utils.ts index cfedf4076..3b1c27f75 100644 --- a/packages/allure-cypress/test/utils.ts +++ b/packages/allure-cypress/test/utils.ts @@ -3,12 +3,16 @@ import { randomUUID } from "node:crypto"; import { mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises"; import { dirname, join, resolve as resolvePath } from "node:path"; import type { TestResult, TestResultContainer } from "allure-js-commons"; -import type { AllureResults } from "allure-js-commons/sdk"; +import type { AllureResults, EnvironmentInfo } from "allure-js-commons/sdk"; +import { parseProperties } from "allure-js-commons/sdk/reporter"; -type CypressTestFiles = Record< - string, - (modulesPaths: { allureCommonsModulePath: string; allureCypressModulePath: string }) => string ->; +type CypressModulesPaths = { + allureCommonsModulePath: string; + allureCypressModulePath: string; + allureCypressModuleBasePath: string; +}; + +type CypressTestFiles = Record string>; export const runCypressInlineTest = async ( testFiles: CypressTestFiles, @@ -18,6 +22,8 @@ export const runCypressInlineTest = async ( tests: [], groups: [], attachments: {}, + categories: [], + envInfo: undefined, }; const testDir = join(__dirname, "fixtures", randomUUID()); const allureCypressModuleBasePath = dirname(require.resolve("allure-cypress")); @@ -62,6 +68,7 @@ export const runCypressInlineTest = async ( testFilesToWrite[testFile]({ allureCommonsModulePath, allureCypressModulePath, + allureCypressModuleBasePath, }), "utf8", ); @@ -93,6 +100,16 @@ export const runCypressInlineTest = async ( const resultFiles = await readdir(testResultsDir); for (const resultFile of resultFiles) { + if (resultFile === "categories.json") { + res.categories = JSON.parse(await readFile(join(testResultsDir, resultFile), "utf8")); + continue; + } + + if (resultFile === "environment.properties") { + res.envInfo = parseProperties(await readFile(join(testResultsDir, resultFile), "utf8")) as EnvironmentInfo; + continue; + } + if (/-attachment\.\S+$/.test(resultFile)) { res.attachments[resultFile] = await readFile(join(testResultsDir, resultFile), "utf8"); continue;