Skip to content

Commit

Permalink
add report for allure-codeceptjs package (via #1012)
Browse files Browse the repository at this point in the history
  • Loading branch information
baev authored Jun 24, 2024
1 parent f1ef515 commit 8930aa5
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 257 deletions.
123 changes: 3 additions & 120 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/allure-codeceptjs/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
}
],
};
6 changes: 5 additions & 1 deletion packages/allure-codeceptjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
"dist"
],
"scripts": {
"allure-report": "allure serve ./out/allure-results",
"clean": "rimraf ./dist ./out ./test-results",
"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 ./src ./test --ext .ts --fix",
"test": "vitest run"
Expand All @@ -55,6 +57,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",
"codeceptjs": "^3.5.4",
"eslint": "^8.57.0",
Expand All @@ -69,6 +73,6 @@
"rimraf": "^5.0.1",
"ts-node": "^10.9.2",
"typescript": "^5.2.2",
"vitest": "^1.5.0"
"vitest": "^1.6.0"
}
}
42 changes: 28 additions & 14 deletions packages/allure-codeceptjs/test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { fork } from "node:child_process";
import { randomUUID } from "node:crypto";
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { extname, join } from "node:path";
import { dirname, resolve as resolvePath } from "node:path";
import { attachment, step } from "allure-js-commons";
import type { AllureResults } from "allure-js-commons/sdk";
import { MessageReader } from "allure-js-commons/sdk/reporter";

Expand All @@ -17,24 +18,34 @@ export const runCodeceptJsInlineTest = async (
};
const testDir = join(__dirname, "temp", randomUUID());

await mkdir(testDir, { recursive: true });
await step(`create test dir ${testDir}`, async () => {
await mkdir(testDir, { recursive: true });
});

for (const file of Object.keys(testFiles)) {
const filePath = join(testDir, file);
await step(file, async () => {
const filePath = join(testDir, file);

await mkdir(dirname(filePath), { recursive: true });
await writeFile(filePath, testFiles[file as keyof typeof testFiles], "utf8");
await mkdir(dirname(filePath), { recursive: true });
const content = testFiles[file as keyof typeof testFiles];
await writeFile(filePath, content, "utf8");
await attachment(file, content, { encoding: "utf-8", contentType: "text/plain", fileExtension: extname(file) });
});
}

const modulePath = require.resolve("codeceptjs/bin/codecept.js");
const modulePath = await step("resolve codeceptjs", () => {
return require.resolve("codeceptjs/bin/codecept.js");
});
const args = ["run", "-c", testDir];
const testProcess = fork(modulePath, args, {
env: {
...process.env,
...env,
},
cwd: testDir,
stdio: "pipe",
const testProcess = await step(`${modulePath} ${args.join(" ")}`, () => {
return fork(modulePath, args, {
env: {
...process.env,
...env,
},
cwd: testDir,
stdio: "pipe",
});
});

testProcess.stdout?.setEncoding("utf8").on("data", (chunk) => {
Expand All @@ -53,6 +64,9 @@ export const runCodeceptJsInlineTest = async (
});

return new Promise((resolve) => {
testProcess.on("exit", () => resolve(messageReader.results));
testProcess.on("exit", () => {
messageReader.attachResults();
return resolve(messageReader.results);
});
});
};
1 change: 1 addition & 0 deletions packages/allure-codeceptjs/vitest-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "allure-vitest/setup";
3 changes: 2 additions & 1 deletion packages/allure-codeceptjs/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ 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",
Expand Down
1 change: 1 addition & 0 deletions packages/allure-playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"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 ./src ./test --ext .ts --fix",
Expand Down
38 changes: 38 additions & 0 deletions packages/allure-playwright/scripts/fixup.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { mkdirSync, writeFileSync } from "node:fs";
import { join, resolve } from "node:path";
import { fileURLToPath } from "node:url";

const dirname = fileURLToPath(new URL(".", import.meta.url));
const esmBuildPath = resolve(dirname, "../dist/esm");
const cjsBuildPath = resolve(dirname, "../dist/cjs");

try {
mkdirSync(esmBuildPath, { recursive: true });
} catch (err) {}

try {
mkdirSync(cjsBuildPath, { recursive: true });
} catch (err) {}

writeFileSync(
join(esmBuildPath, "package.json"),
JSON.stringify(
{
type: "module",
},
null,
2,
),
"utf8",
);
writeFileSync(
join(cjsBuildPath, "package.json"),
JSON.stringify(
{
type: "commonjs",
},
null,
2,
),
"utf8",
);
Loading

0 comments on commit 8930aa5

Please sign in to comment.