From 42a10cabb9deb2e425ecc0e34afc78ad0e72e4c5 Mon Sep 17 00:00:00 2001 From: Dmitry Baev Date: Mon, 24 Jun 2024 13:24:52 +0100 Subject: [PATCH] add report for allure-cucumberjs package --- .pnp.cjs | 13 ++-- packages/allure-cucumberjs/.eslintrc.cjs | 2 +- packages/allure-cucumberjs/package.json | 7 +- packages/allure-cucumberjs/test/utils.ts | 75 +++++++++++++++------ packages/allure-cucumberjs/vitest-setup.ts | 1 + packages/allure-cucumberjs/vitest.config.ts | 9 ++- yarn.lock | 7 +- 7 files changed, 76 insertions(+), 38 deletions(-) create mode 100644 packages/allure-cucumberjs/vitest-setup.ts diff --git a/.pnp.cjs b/.pnp.cjs index a93ddcbe9..721ae5e64 100755 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -6207,6 +6207,7 @@ const RAW_RUNTIME_STATE = ["@types/sinon", "npm:17.0.3"],\ ["@typescript-eslint/eslint-plugin", "virtual:a59b12f7fe7bf3b80fc61d73eaaa33af60483f6ce31789d384fbe8ef169791f667d2559ec5f2fbae1a273a658ce021f1f5f1ea0718c56f81b30ad4e95a5668dd#npm:7.10.0"],\ ["@typescript-eslint/parser", "virtual:a59b12f7fe7bf3b80fc61d73eaaa33af60483f6ce31789d384fbe8ef169791f667d2559ec5f2fbae1a273a658ce021f1f5f1ea0718c56f81b30ad4e95a5668dd#npm:7.10.0"],\ + ["allure-commandline", "npm:2.29.0"],\ ["allure-js-commons", "workspace:packages/allure-js-commons"],\ ["allure-vitest", "workspace:packages/allure-vitest"],\ ["babel-plugin-add-module-exports", "npm:1.0.4"],\ @@ -6225,7 +6226,7 @@ const RAW_RUNTIME_STATE = ["sinon", "npm:18.0.0"],\ ["ts-node", "virtual:3c6c31eedba60f6d4a0031098f0272720e7414162569ae8f58388d36f8e79683154a59f38a8e5aece9f0d5e45421fab86d5311a37a1c1aec338de3c79151496a#npm:10.9.2"],\ ["typescript", "patch:typescript@npm%3A5.3.3#optional!builtin::version=5.3.3&hash=e012d7"],\ - ["vitest", "virtual:606d5fd11adc18cba076ddb26a9b3adaf466a45eef985b60ea990c3ead5fe6bcc20990b0ed8d0763c4a8c861cdc2277964415bf12191df7c6923d8e78816abf5#npm:1.4.0"]\ + ["vitest", "virtual:f37ad3099f3665d5bbc9ee71081416c8874087a5d9739472f56367e210ca9246356f462b31407a28e510bc022801edd4632f86364db715287d62bd50b42e2c00#npm:1.6.0"]\ ],\ "linkType": "SOFT"\ }]\ @@ -6266,7 +6267,7 @@ const RAW_RUNTIME_STATE = ["rimraf", "npm:5.0.5"],\ ["ts-node", "virtual:3c6c31eedba60f6d4a0031098f0272720e7414162569ae8f58388d36f8e79683154a59f38a8e5aece9f0d5e45421fab86d5311a37a1c1aec338de3c79151496a#npm:10.9.2"],\ ["typescript", "patch:typescript@npm%3A5.3.3#optional!builtin::version=5.3.3&hash=e012d7"],\ - ["vitest", "virtual:606d5fd11adc18cba076ddb26a9b3adaf466a45eef985b60ea990c3ead5fe6bcc20990b0ed8d0763c4a8c861cdc2277964415bf12191df7c6923d8e78816abf5#npm:1.4.0"]\ + ["vitest", "virtual:98c60b7d3b6c5117c4513c6cb8006cab39e0411be8ffe9bb791d9b6d0a1566b28587d5455e7567553092cbdbab928cfaf2a758f8f25f0e31ddedfee569ca964b#npm:1.4.0"]\ ],\ "linkType": "SOFT"\ }]\ @@ -6455,7 +6456,7 @@ const RAW_RUNTIME_STATE = ["ts-node", "virtual:3c6c31eedba60f6d4a0031098f0272720e7414162569ae8f58388d36f8e79683154a59f38a8e5aece9f0d5e45421fab86d5311a37a1c1aec338de3c79151496a#npm:10.9.2"],\ ["tslib", "npm:2.6.2"],\ ["typescript", "patch:typescript@npm%3A5.3.3#optional!builtin::version=5.3.3&hash=e012d7"],\ - ["vitest", "virtual:606d5fd11adc18cba076ddb26a9b3adaf466a45eef985b60ea990c3ead5fe6bcc20990b0ed8d0763c4a8c861cdc2277964415bf12191df7c6923d8e78816abf5#npm:1.4.0"]\ + ["vitest", "virtual:98c60b7d3b6c5117c4513c6cb8006cab39e0411be8ffe9bb791d9b6d0a1566b28587d5455e7567553092cbdbab928cfaf2a758f8f25f0e31ddedfee569ca964b#npm:1.4.0"]\ ],\ "linkType": "SOFT"\ }]\ @@ -18494,10 +18495,10 @@ const RAW_RUNTIME_STATE = ],\ "linkType": "HARD"\ }],\ - ["virtual:606d5fd11adc18cba076ddb26a9b3adaf466a45eef985b60ea990c3ead5fe6bcc20990b0ed8d0763c4a8c861cdc2277964415bf12191df7c6923d8e78816abf5#npm:1.4.0", {\ - "packageLocation": "./.yarn/__virtual__/vitest-virtual-73a2b10a06/0/cache/vitest-npm-1.4.0-465b7cb84c-cf4675657f.zip/node_modules/vitest/",\ + ["virtual:98c60b7d3b6c5117c4513c6cb8006cab39e0411be8ffe9bb791d9b6d0a1566b28587d5455e7567553092cbdbab928cfaf2a758f8f25f0e31ddedfee569ca964b#npm:1.4.0", {\ + "packageLocation": "./.yarn/__virtual__/vitest-virtual-5d3074a0f5/0/cache/vitest-npm-1.4.0-465b7cb84c-cf4675657f.zip/node_modules/vitest/",\ "packageDependencies": [\ - ["vitest", "virtual:606d5fd11adc18cba076ddb26a9b3adaf466a45eef985b60ea990c3ead5fe6bcc20990b0ed8d0763c4a8c861cdc2277964415bf12191df7c6923d8e78816abf5#npm:1.4.0"],\ + ["vitest", "virtual:98c60b7d3b6c5117c4513c6cb8006cab39e0411be8ffe9bb791d9b6d0a1566b28587d5455e7567553092cbdbab928cfaf2a758f8f25f0e31ddedfee569ca964b#npm:1.4.0"],\ ["@edge-runtime/vm", null],\ ["@types/edge-runtime__vm", null],\ ["@types/happy-dom", null],\ diff --git a/packages/allure-cucumberjs/.eslintrc.cjs b/packages/allure-cucumberjs/.eslintrc.cjs index 3a49fd6c6..5a2b11a2d 100644 --- a/packages/allure-cucumberjs/.eslintrc.cjs +++ b/packages/allure-cucumberjs/.eslintrc.cjs @@ -7,7 +7,7 @@ module.exports = { overrides: [ { extends: ["plugin:@typescript-eslint/disable-type-checked"], - files: [".eslintrc.cjs"], + files: [".eslintrc.cjs", "vitest.config.ts", "vitest-setup.ts"], } ], }; diff --git a/packages/allure-cucumberjs/package.json b/packages/allure-cucumberjs/package.json index 4f52e637c..dd74a5857 100644 --- a/packages/allure-cucumberjs/package.json +++ b/packages/allure-cucumberjs/package.json @@ -33,12 +33,14 @@ "dist" ], "scripts": { + "allure-report": "allure serve ./out/allure-results", "clean": "rimraf ./dist ./out", "compile": "run-s 'compile:*'", "compile:esm": "babel --config-file ./babel.esm.json ./src --out-dir ./dist/esm --extensions '.ts' --source-maps", "compile:cjs": "babel --config-file ./babel.cjs.json ./src --out-dir ./dist/cjs --extensions '.ts' --source-maps", "compile:types": "tsc", "compile:fixup": "node ./scripts/fixup.mjs", + "generate-report": "allure generate ./out/allure-results -o ./out/allure-report --clean", "lint": "eslint ./src ./test --ext .ts", "lint:fix": "eslint --fix ./src ./test --ext .ts", "test": "vitest run" @@ -69,7 +71,8 @@ "@types/sinon": "^17.0.0", "@typescript-eslint/eslint-plugin": "^7.0.0", "@typescript-eslint/parser": "^7.0.0", - "allure-vitest": "workspace:^", + "allure-commandline": "^2.29.0", + "allure-vitest": "workspace:*", "babel-plugin-add-module-exports": "^1.0.4", "chai": "^4.3.8", "chai-like": "^1.1.1", @@ -86,6 +89,6 @@ "sinon": "^18.0.0", "ts-node": "^10.9.1", "typescript": "^5.2.2", - "vitest": "^1.4.0" + "vitest": "^1.6.0" } } diff --git a/packages/allure-cucumberjs/test/utils.ts b/packages/allure-cucumberjs/test/utils.ts index 2c14ddb19..1daf22554 100644 --- a/packages/allure-cucumberjs/test/utils.ts +++ b/packages/allure-cucumberjs/test/utils.ts @@ -2,6 +2,7 @@ import { fork } from "node:child_process"; import { randomUUID } from "node:crypto"; import { copyFile, mkdir, rm, writeFile } from "node:fs/promises"; import { dirname, join, resolve as resolvePath } from "node:path"; +import { attachment, attachmentPath, step } from "allure-js-commons"; import type { AllureResults } from "allure-js-commons/sdk"; import { MessageReader } from "allure-js-commons/sdk/reporter"; @@ -57,38 +58,70 @@ export const runCucumberInlineTest = async ( require("allure-cucumberjs"); `; - await mkdir(testDir, { recursive: true }); - await mkdir(supportTempPath, { recursive: true }); - await writeFile(configFilePath, configContent, "utf8"); - await writeFile(reporterFilePath, reporterContent, "utf8"); - await writeFile(worldFilePath, worldContent, "utf8"); + await step(`create test dir ${testDir}`, async () => { + await mkdir(testDir, { recursive: true }); + }); + await step(`create support temp dir ${supportTempPath}`, async () => { + await mkdir(supportTempPath, { recursive: true }); + }); + await step("config.js", async () => { + await writeFile(configFilePath, configContent, "utf8"); + await attachment("config.js", configContent, { + contentType: "text/plain", + encoding: "utf-8", + fileExtension: ".js", + }); + }); + await step("reporter.js", async () => { + await writeFile(reporterFilePath, reporterContent, "utf8"); + await attachment("reporter.js", reporterContent, { + contentType: "text/plain", + encoding: "utf-8", + fileExtension: ".js", + }); + }); + await step("world.js", async () => { + await writeFile(worldFilePath, worldContent, "utf8"); + await attachment("world.js", worldContent, { + contentType: "text/plain", + encoding: "utf-8", + fileExtension: ".js", + }); + }); - await Promise.all( - features.map(async (feature) => { + for (const feature of features) { + await step(`features/${feature}.feature`, async () => { const featurePath = join(fixturesPath, "features", `${feature}.feature`); await copyFile(featurePath, join(featuresTempPath, `${feature}.feature`)); - }), - ); - await Promise.all( - stepsDefs.map(async (stepsDef) => { + await attachmentPath(`features/${feature}.feature`, featurePath, { contentType: "text/plain" }); + }); + } + + for (const stepsDef of stepsDefs) { + await step(`support/${stepsDef}.cjs`, async () => { const stepsDefPath = join(fixturesPath, "support", `${stepsDef}.cjs`); const supportFilePath = join(supportTempPath, `${stepsDef}.js`); await mkdir(dirname(supportFilePath), { recursive: true }); await copyFile(stepsDefPath, supportFilePath); - }), - ); + await attachmentPath(`support/${stepsDef}.cjs`, stepsDefPath, { contentType: "text/plain" }); + }); + } - const modulePath = resolvePath(require.resolve("@cucumber/cucumber"), "../../bin/cucumber-js"); + const modulePath = await step("resolve @cucumber/cucumber", () => { + return resolvePath(require.resolve("@cucumber/cucumber"), "../../bin/cucumber-js"); + }); const args = ["--config", "./config.js"]; - const testProcess = fork(modulePath, args, { - env: { - ...process.env, - }, - cwd: testDir, - stdio: "pipe", + const testProcess = await step(`${modulePath} ${args.join(" ")}`, () => { + return fork(modulePath, args, { + env: { + ...process.env, + }, + cwd: testDir, + stdio: "pipe", + }); }); const messageReader = new MessageReader(); @@ -105,7 +138,7 @@ export const runCucumberInlineTest = async ( return new Promise((resolve) => { testProcess.on("exit", async () => { await rm(testDir, { recursive: true }); - + await messageReader.attachResults(); return resolve(messageReader.results); }); }); diff --git a/packages/allure-cucumberjs/vitest-setup.ts b/packages/allure-cucumberjs/vitest-setup.ts new file mode 100644 index 000000000..47b029ecc --- /dev/null +++ b/packages/allure-cucumberjs/vitest-setup.ts @@ -0,0 +1 @@ +import "allure-vitest/setup"; diff --git a/packages/allure-cucumberjs/vitest.config.ts b/packages/allure-cucumberjs/vitest.config.ts index f2607bb4b..592139ee2 100644 --- a/packages/allure-cucumberjs/vitest.config.ts +++ b/packages/allure-cucumberjs/vitest.config.ts @@ -5,12 +5,11 @@ export default defineConfig({ dir: "./test/spec", fileParallelism: false, testTimeout: 5000, - reporters: [ - "default", - ], + setupFiles: ["./vitest-setup.ts"], + reporters: ["default", ["allure-vitest/reporter", { resultsDir: "./out/allure-results" }]], typecheck: { enabled: true, - tsconfig: "./tsconfig.test.json" - } + tsconfig: "./tsconfig.test.json", + }, }, }); diff --git a/yarn.lock b/yarn.lock index 477cecc11..5507ca566 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4228,8 +4228,9 @@ __metadata: "@types/sinon": "npm:^17.0.0" "@typescript-eslint/eslint-plugin": "npm:^7.0.0" "@typescript-eslint/parser": "npm:^7.0.0" + allure-commandline: "npm:^2.29.0" allure-js-commons: "workspace:*" - allure-vitest: "workspace:^" + allure-vitest: "workspace:*" babel-plugin-add-module-exports: "npm:^1.0.4" chai: "npm:^4.3.8" chai-like: "npm:^1.1.1" @@ -4246,7 +4247,7 @@ __metadata: sinon: "npm:^18.0.0" ts-node: "npm:^10.9.1" typescript: "npm:^5.2.2" - vitest: "npm:^1.4.0" + vitest: "npm:^1.6.0" languageName: unknown linkType: soft @@ -4501,7 +4502,7 @@ __metadata: languageName: unknown linkType: soft -"allure-vitest@workspace:*, allure-vitest@workspace:^, allure-vitest@workspace:packages/allure-vitest": +"allure-vitest@workspace:*, allure-vitest@workspace:packages/allure-vitest": version: 0.0.0-use.local resolution: "allure-vitest@workspace:packages/allure-vitest" dependencies: