Skip to content

Commit

Permalink
add report for allure-jest package (via #1016)
Browse files Browse the repository at this point in the history
  • Loading branch information
baev authored Jun 25, 2024
1 parent 83ac013 commit e117686
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .pnp.cjs

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

2 changes: 1 addition & 1 deletion packages/allure-jest/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
overrides: [
{
extends: ["plugin:@typescript-eslint/disable-type-checked"],
files: [".eslintrc.cjs"],
files: [".eslintrc.cjs", "vitest.config.ts", "vitest-setup.ts"],
}
],
};
4 changes: 4 additions & 0 deletions packages/allure-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,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": "vitest run"
Expand All @@ -66,6 +68,8 @@
"@types/source-map-support": "^0.5.7",
"@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",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.0.0",
Expand Down
53 changes: 38 additions & 15 deletions packages/allure-jest/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import { fork } from "node:child_process";
import { randomUUID } from "node:crypto";
import { mkdir, rm, writeFile } from "node:fs/promises";
import { join } 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";

export const runJestInlineTest = async (test: string): Promise<AllureResults> => {
export const runJestInlineTest = async (testContent: string): Promise<AllureResults> => {
const testDir = join(__dirname, "fixtures", randomUUID());
const configFilePath = join(testDir, "jest.config.js");
const testFilePath = join(testDir, "sample.test.js");
const configFileName = "jest.config.js";
const configFilePath = join(testDir, configFileName);
const testFileName = "sample.test.js";
const testFilePath = join(testDir, testFileName);
const configContent = `
const config = {
testEnvironment: require.resolve("allure-jest/node"),
Expand All @@ -28,19 +31,39 @@ export const runJestInlineTest = async (test: string): Promise<AllureResults> =>
module.exports = config;
`;

await mkdir(testDir, { recursive: true });
await writeFile(configFilePath, configContent, "utf8");
await writeFile(testFilePath, test, "utf8");
await step("create test dir", async () => {
await mkdir(testDir, { recursive: true });
});
await step(configFileName, async () => {
await writeFile(configFilePath, configContent, "utf8");
await attachment(configFileName, configContent, {
contentType: "text/plain",
encoding: "utf-8",
fileExtension: ".js",
});
});
await step(testFileName, async () => {
await writeFile(testFilePath, testContent, "utf8");
await attachment(testFileName, testContent, {
contentType: "text/plain",
encoding: "utf-8",
fileExtension: ".js",
});
});

const modulePath = require.resolve("jest-cli/bin/jest");
const modulePath = await step("resolve jest", () => {
return require.resolve("jest-cli/bin/jest");
});
const args = ["--config", configFilePath, testDir];
const testProcess = fork(modulePath, args, {
env: {
...process.env,
ALLURE_POST_PROCESSOR_FOR_TEST: String("true"),
},
cwd: testDir,
stdio: "pipe",
const testProcess = await step(`${modulePath} ${args.join(" ")}`, () => {
return fork(modulePath, args, {
env: {
...process.env,
ALLURE_POST_PROCESSOR_FOR_TEST: String("true"),
},
cwd: testDir,
stdio: "pipe",
});
});

const messageReader = new MessageReader();
Expand All @@ -57,7 +80,7 @@ export const runJestInlineTest = async (test: string): Promise<AllureResults> =>
return new Promise((resolve) => {
testProcess.on("exit", async () => {
await rm(testDir, { recursive: true });

await messageReader.attachResults();
return resolve(messageReader.results);
});
});
Expand Down
1 change: 1 addition & 0 deletions packages/allure-jest/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-jest/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
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4342,7 +4342,9 @@ __metadata:
"@types/source-map-support": "npm:^0.5.7"
"@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"
eslint: "npm:^8.57.0"
eslint-config-prettier: "npm:^9.0.0"
Expand Down

0 comments on commit e117686

Please sign in to comment.