diff --git a/.pnp.cjs b/.pnp.cjs index 721ae5e64..fc33aac39 100755 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -6435,7 +6435,9 @@ const RAW_RUNTIME_STATE = ["@types/node", "npm:20.11.20"],\ ["@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"],\ ["babel-plugin-transform-import-meta", "virtual:ab27e3168e0bdfb2dc5b30f86375269d7862a0be07fda8f1a257183a90c281219d82f6498de90bd23a4b5fcb916cfc7e850768c6711fc7742befb82622788606#npm:2.2.1"],\ ["chai", "npm:4.4.1"],\ @@ -6456,7 +6458,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:98c60b7d3b6c5117c4513c6cb8006cab39e0411be8ffe9bb791d9b6d0a1566b28587d5455e7567553092cbdbab928cfaf2a758f8f25f0e31ddedfee569ca964b#npm:1.4.0"]\ + ["vitest", "virtual:f37ad3099f3665d5bbc9ee71081416c8874087a5d9739472f56367e210ca9246356f462b31407a28e510bc022801edd4632f86364db715287d62bd50b42e2c00#npm:1.6.0"]\ ],\ "linkType": "SOFT"\ }]\ diff --git a/packages/allure-mocha/.eslintrc.cjs b/packages/allure-mocha/.eslintrc.cjs index f8628a6eb..f3f01f9ff 100644 --- a/packages/allure-mocha/.eslintrc.cjs +++ b/packages/allure-mocha/.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"], }, { files: ["**/*.cjs", "**/*.js"], diff --git a/packages/allure-mocha/package.json b/packages/allure-mocha/package.json index b1b44e15f..49bf73f23 100644 --- a/packages/allure-mocha/package.json +++ b/packages/allure-mocha/package.json @@ -38,12 +38,14 @@ "dist" ], "scripts": { + "allure-report": "allure serve ./out/allure-results", "clean": "rimraf ./dist ./out", "compile": "run-s 'compile:*'", "compile:esm-babel": "babel --config-file ./babel.esm.json ./src --out-dir ./dist/esm --extensions '.ts' --source-maps", "compile:cjs-babel": "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 ./src ./test --ext .ts --fix", "test": "run-s --print-name 'test:*'", @@ -68,6 +70,8 @@ "@types/node": "^20.6.3", "@typescript-eslint/eslint-plugin": "^7.0.0", "@typescript-eslint/parser": "^7.0.0", + "allure-commandline": "^2.29.0", + "allure-vitest": "workspace:*", "babel-plugin-add-module-exports": "^1.0.4", "babel-plugin-transform-import-meta": "^2.2.1", "chai": "^4.3.8", @@ -88,7 +92,7 @@ "ts-node": "^10.9.1", "tslib": "^2.6.2", "typescript": "^5.2.2", - "vitest": "^1.4.0" + "vitest": "^1.6.0" }, "peerDependencies": { "mocha": ">=6.2.x" diff --git a/packages/allure-mocha/test/spec/framework/result.test.ts b/packages/allure-mocha/test/spec/framework/result.test.ts index c03f44c0f..9024fe36b 100644 --- a/packages/allure-mocha/test/spec/framework/result.test.ts +++ b/packages/allure-mocha/test/spec/framework/result.test.ts @@ -29,9 +29,8 @@ describe("defaults", () => { }); it("has timing props", () => { - expect(test.start).greaterThan(0); - expect(test.stop).greaterThan(test.start as number); expect(test.start).greaterThanOrEqual(sampleStart); + expect(test.stop).greaterThanOrEqual(test.start as number); expect(test.stop).lessThanOrEqual(sampleStop); }); diff --git a/packages/allure-mocha/test/utils.ts b/packages/allure-mocha/test/utils.ts index f2e498721..96fff01ec 100644 --- a/packages/allure-mocha/test/utils.ts +++ b/packages/allure-mocha/test/utils.ts @@ -3,6 +3,7 @@ import { randomUUID } from "node:crypto"; import { appendFileSync } from "node:fs"; import { copyFile, mkdir, readFile, writeFile } from "node:fs/promises"; import * as path from "node:path"; +import { attachment, attachmentPath, parameter, step } from "allure-js-commons"; import type { AllureResults, Category } from "allure-js-commons/sdk"; import { MessageReader } from "allure-js-commons/sdk/reporter"; @@ -50,6 +51,10 @@ abstract class AllureMochaTestRunner { } run = async (...samples: readonly (string | readonly string[])[]) => { + // TODO parameter should accept any type + await parameter("parallel", `${RUN_IN_PARALLEL}`); + await parameter("module", SPEC_FORMAT); + const testDir = path.join(this.runResultsDir, randomUUID()); const filesToCopy = [...this.getFilesToCopy(testDir)]; @@ -73,49 +78,61 @@ abstract class AllureMochaTestRunner { const cmdContent = [scriptPath, ...scriptArgs].join("\n "); await mkdir(testDir, { recursive: true }); - await Promise.all([ - ...filesToCopy.map(async ([src, dst]) => { + for (const [src, dst] of filesToCopy) { + const name = path.basename(dst); + await step(name, async () => { const dstDir = path.dirname(dst); await mkdir(dstDir, { recursive: true }); await copyFile(src, dst); - }), - ...filesToTransform.map(async ([src, dst, uncomment]) => { + await attachmentPath(name, src, { contentType: "text/plain" }); + }); + } + + for (const [src, dst, uncomment] of filesToTransform) { + const name = path.basename(dst); + await step(name, async () => { const dstDir = path.dirname(dst); const content = await readFile(src, { encoding: "utf-8" }); await mkdir(dstDir, { recursive: true }); const uncommentedSample = content.replace(uncomment, "$1"); - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - writeFile(dst, uncommentedSample, { encoding: "utf-8" }); - }), - writeFile(cmdPath, cmdContent, "utf-8"), - ]); + await writeFile(dst, uncommentedSample, { encoding: "utf-8" }); + await attachment(name, uncommentedSample, { contentType: "text/plain" }); + }); + } + + await step(path.basename(cmdPath), async () => { + await writeFile(cmdPath, cmdContent, "utf-8"); + }); if (this.config.testplan) { const testplanPath = path.join(testDir, "testplan.json"); this.config.env ??= {}; this.config.env.ALLURE_TESTPLAN_PATH = testplanPath; const selectorPrefix = path.relative(path.join(__dirname, ".."), testDir); - await writeFile( - testplanPath, - JSON.stringify({ - version: "1.0", - tests: this.config.testplan.map((test) => ({ - id: test.id, - selector: test.selector ? this.resolveTestplanSelector(selectorPrefix, test.selector) : undefined, - })), - }), - { encoding: "utf-8" }, - ); + const content = JSON.stringify({ + version: "1.0", + tests: this.config.testplan.map((test) => ({ + id: test.id, + selector: test.selector ? this.resolveTestplanSelector(selectorPrefix, test.selector) : undefined, + })), + }); + await writeFile(testplanPath, content, { encoding: "utf-8" }); + await attachment(path.basename(testplanPath), content, { + contentType: "application/json", + fileExtension: "json", + }); } - const testProcess = fork(scriptPath, scriptArgs, { - env: { - ...process.env, - ...this.config.env, - ALLURE_MOCHA_TESTHOST_PID: process.pid.toString(), - }, - cwd: testDir, - stdio: "pipe", + const testProcess = await step(`${scriptPath} ${scriptArgs.join(" ")}`, () => { + return fork(scriptPath, scriptArgs, { + env: { + ...process.env, + ...this.config.env, + ALLURE_MOCHA_TESTHOST_PID: process.pid.toString(), + }, + cwd: testDir, + stdio: "pipe", + }); }); const messageReader = new MessageReader(); @@ -133,7 +150,8 @@ abstract class AllureMochaTestRunner { }); return await new Promise((resolve, reject) => { - testProcess.on("exit", (code, signal) => { + testProcess.on("exit", async (code, signal) => { + await messageReader.attachResults(); if ((code ?? -1) >= 0 && !signal) { resolve(messageReader.results); } else if (signal) { diff --git a/packages/allure-mocha/vitest-setup.ts b/packages/allure-mocha/vitest-setup.ts new file mode 100644 index 000000000..47b029ecc --- /dev/null +++ b/packages/allure-mocha/vitest-setup.ts @@ -0,0 +1 @@ +import "allure-vitest/setup"; diff --git a/packages/allure-mocha/vitest.config.mts b/packages/allure-mocha/vitest.config.mts index f05ce21c5..3a8bd4a6e 100644 --- a/packages/allure-mocha/vitest.config.mts +++ b/packages/allure-mocha/vitest.config.mts @@ -6,8 +6,9 @@ export default defineConfig({ fileParallelism: false, testTimeout: 25000, hookTimeout: 25000, - reporters: ["default"], globalSetup: ["./test/setup.ts"], + setupFiles: ["./vitest-setup.ts"], + reporters: ["default", ["allure-vitest/reporter", { resultsDir: "./out/allure-results" }]], typecheck: { enabled: true, tsconfig: "./tsconfig.test.json", diff --git a/yarn.lock b/yarn.lock index 5507ca566..294b792d4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4442,7 +4442,9 @@ __metadata: "@types/node": "npm:^20.6.3" "@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:*" babel-plugin-add-module-exports: "npm:^1.0.4" babel-plugin-transform-import-meta: "npm:^2.2.1" chai: "npm:^4.3.8" @@ -4463,7 +4465,7 @@ __metadata: ts-node: "npm:^10.9.1" tslib: "npm:^2.6.2" typescript: "npm:^5.2.2" - vitest: "npm:^1.4.0" + vitest: "npm:^1.6.0" peerDependencies: mocha: ">=6.2.x" languageName: unknown