Skip to content

Commit

Permalink
Merge branch 'master' into issue-788-fix-multi-job-mode-tests-skipping
Browse files Browse the repository at this point in the history
  • Loading branch information
epszaw authored Oct 31, 2023
2 parents 8908766 + 5cdd343 commit b25ef46
Show file tree
Hide file tree
Showing 24 changed files with 146 additions and 26 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.

11 changes: 11 additions & 0 deletions .yarn/versions/02394143.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
undecided:
- allure-js
- allure-codeceptjs
- allure-cucumberjs
- allure-decorators
- allure-hermione
- allure-jasmine
- allure-jest
- allure-js-commons
- allure-mocha
- allure-playwright
11 changes: 11 additions & 0 deletions .yarn/versions/2d090405.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
undecided:
- allure-js
- allure-codeceptjs
- allure-cucumberjs
- allure-decorators
- allure-hermione
- allure-jasmine
- allure-jest
- allure-js-commons
- allure-mocha
- allure-playwright
11 changes: 11 additions & 0 deletions .yarn/versions/e8f80546.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
undecided:
- allure-js
- allure-codeceptjs
- allure-cucumberjs
- allure-decorators
- allure-hermione
- allure-jasmine
- allure-jest
- allure-js-commons
- allure-mocha
- allure-playwright
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "allure-js",
"private": true,
"version": "2.8.1",
"version": "2.9.2",
"workspaces": [
"packages/*"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-codeceptjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "allure-codeceptjs",
"version": "2.8.1",
"version": "2.9.2",
"description": "Allure codeceptjs integration",
"license": "Apache-2.0",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-cucumberjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "allure-cucumberjs",
"version": "2.8.1",
"version": "2.9.2",
"description": "Allure Cucumber.JS integration",
"license": "Apache-2.0",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-decorators/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "allure-decorators",
"version": "2.8.1",
"version": "2.9.2",
"description": "Write your tests in a Java-like annotation-driven manner via JS decorators.",
"license": "Apache-2.0",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-hermione/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "allure-hermione",
"version": "2.8.1",
"version": "2.9.2",
"packageManager": "[email protected]",
"license": "Apache-2.0",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-jasmine/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "allure-jasmine",
"version": "2.8.1",
"version": "2.9.2",
"description": "Allure Jasmine integration",
"license": "Apache-2.0",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-jest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "allure-jest",
"version": "2.8.1",
"version": "2.9.2",
"description": "Allure Jest integration",
"license": "Apache-2.0",
"packageManager": "[email protected]",
Expand Down
19 changes: 9 additions & 10 deletions packages/allure-jest/src/AllureJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Status,
} from "allure-js-commons";
import { AllureJestApi } from "./AllureJestApi";
import { getTestId, getTestPath } from "./utils";
import { getTestId, getTestPath, removeAnsiColorsFromString } from "./utils";

const { ALLURE_HOST_NAME, ALLURE_THREAD_NAME, JEST_WORKER_ID } = process.env;
const hostname = os.hostname();
Expand All @@ -21,25 +21,22 @@ export interface AllureEnvironment extends JestEnvironment {
handleAllureMetadata(payload: { currentTestName: string; metadata: MetadataMessage }): void;
}

export interface AllureEnvironmentConfig extends JestEnvironmentConfig {
resultsDir?: string;
}

const createJestEnvironment = <T extends typeof JestEnvironment>(Base: T): T => {
// @ts-expect-error (ts(2545)) Incorrect assumption about a mixin class: https://github.com/microsoft/TypeScript/issues/37142
return class extends Base {
testRootDirPath: string;
runtime: AllureRuntime;
runningTests: Map<string, AllureTest> = new Map();

constructor(config: AllureEnvironmentConfig, context: EnvironmentContext) {
constructor(config: JestEnvironmentConfig, context: EnvironmentContext) {
super(config, context);

this.runtime = new AllureRuntime({
resultsDir: config.resultsDir || "allure-results",
resultsDir:
(config?.projectConfig?.testEnvironmentOptions?.resultsDir as string) || "allure-results",
});
this.global.allure = new AllureJestApi(this, this.global);
this.testRootDirPath = config.projectConfig.rootDir;
this.testRootDirPath = config.globalConfig.rootDir;
}

setup() {
Expand Down Expand Up @@ -151,12 +148,14 @@ const createJestEnvironment = <T extends typeof JestEnvironment>(Base: T): T =>
// jest collects all errors, but we need to report the first one because it's a reason why the test has been failed
const [error] = test.errors;
const hasMultipleErrors = Array.isArray(error);
const errorMessage = (hasMultipleErrors ? error[0].message : error.message) as string;
const errorTrace = (hasMultipleErrors ? error[0].stack : error.stack) as string;

currentTest.stage = Stage.FINISHED;
currentTest.status = Status.FAILED;
currentTest.statusDetails = {
message: hasMultipleErrors ? error[0].message : error.message,
trace: hasMultipleErrors ? error[0].stack : error.stack,
message: removeAnsiColorsFromString(errorMessage),
trace: removeAnsiColorsFromString(errorTrace),
};
}

Expand Down
11 changes: 11 additions & 0 deletions packages/allure-jest/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,14 @@ export const getTestId = (path: string[]): string => path.join(" ");
* @returns
*/
export const getTestFullName = (path: string[]): string => path.join(" > ");

/**
* Removes all ANSI colors codes from given string
* Could be useful, when the codes render in the report, but shouldn't
*
* @param str Source string
* @returns
*/
export const removeAnsiColorsFromString = (str: string): string =>
// eslint-disable-next-line no-control-regex
str.replace(/\u001b\[\d{1,2}m/g, "");
3 changes: 3 additions & 0 deletions packages/allure-jest/test/fixtures/ansiColors.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it("hello", () => {
expect(1).toBe(2);
});
13 changes: 13 additions & 0 deletions packages/allure-jest/test/spec/ansiColors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect } from "chai";
import { runJestTests } from "../utils";

describe("ansiColors", () => {
it("removes ansi colors from text errors", async () => {
const results = await runJestTests(["./test/fixtures/ansiColors.test.js"]);
const [result] = Object.values(results);

expect(result.name).eq("hello");
expect(result.statusDetails.message).not.to.contain("\x1b[");
expect(result.statusDetails.trace).not.to.contain("\x1b[");
});
});
4 changes: 3 additions & 1 deletion packages/allure-js-commons/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "allure-js-commons",
"version": "2.8.1",
"version": "2.9.2",
"description": "Allure JS Commons",
"license": "Apache-2.0",
"author": {
Expand Down Expand Up @@ -39,6 +39,7 @@
"@types/eslint": "^8",
"@types/mocha": "^10.0.1",
"@types/node": "^20.6.3",
"@types/sinon": "^10.0.16",
"@types/source-map-support": "^0.5.7",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
Expand All @@ -55,6 +56,7 @@
"mocha": "^10.2.0",
"mocha-multi-reporters": "^1.5.1",
"rimraf": "^5.0.1",
"sinon": "^16.0.0",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
Expand Down
5 changes: 2 additions & 3 deletions packages/allure-js-commons/src/AllureGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { AllureTest } from "./AllureTest";
import { fixtureResult, testResultContainer } from "./constructors";
import { ExecutableItemWrapper } from "./ExecutableItemWrapper";
import { TestResultContainer } from "./model";
import { getLabelsFromEnv } from "./utils";

export class AllureGroup {
private testResultContainer: TestResultContainer = testResultContainer();
Expand All @@ -19,10 +18,10 @@ export class AllureGroup {

startTest(name?: string, start?: number): AllureTest {
const test = new AllureTest(this.runtime, start);

this.testResultContainer.children.push(test.uuid);
test.name = name || "Unnamed";
const globalLabels = getLabelsFromEnv();
globalLabels.forEach((label) => test.addLabel(label.name, label.value));

return test;
}

Expand Down
7 changes: 6 additions & 1 deletion packages/allure-js-commons/src/AllureTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AllureRuntime } from "./AllureRuntime";
import { testResult } from "./constructors";
import { ExecutableItemWrapper } from "./ExecutableItemWrapper";
import { ExecutableItem, LinkType, MetadataMessage, TestResult } from "./model";
import { md5 } from "./utils";
import { getLabelsFromEnv, md5 } from "./utils";

export class AllureTest extends ExecutableItemWrapper {
private readonly testResult: TestResult;
Expand All @@ -14,8 +14,13 @@ export class AllureTest extends ExecutableItemWrapper {
start: number = Date.now(),
) {
super(testResult());

const globalLabels = getLabelsFromEnv();

this.testResult = this.wrappedItem as TestResult;
this.testResult.start = start;

globalLabels.forEach((label) => this.addLabel(label.name, label.value));
}

endTest(stop: number = Date.now()): void {
Expand Down
51 changes: 51 additions & 0 deletions packages/allure-js-commons/test/specs/AllureTest.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import process from "process";
import { expect } from "chai";
import { restore, stub } from "sinon";
import { AllureRuntime, AllureTest } from "allure-js-commons";

const fixtures = {
name: "test name",
runtimeWriter: {
writeResult: stub(),
writeGroup: stub(),
writeAttachment: stub(),
writeAttachmentFromPath: stub(),
writeEnvironmentInfo: stub(),
writeCategoriesDefinitions: stub(),
},
};

describe("AllureTest", () => {
let runtime: AllureRuntime;

beforeEach(() => {
restore();

stub(process, "env").value({
ALLURE_LABEL_FOO: "foo",
ALLURE_LABEL_BAR: "bar",
});

runtime = new AllureRuntime({
writer: fixtures.runtimeWriter,
resultsDir: "",
});
});

it("assigns global allure labels from env variables to the test", () => {
const currentTest = new AllureTest(runtime);

currentTest.endTest();

expect(fixtures.runtimeWriter.writeResult.args[0][0].labels).eql([
{
name: "foo",
value: "foo",
},
{
name: "bar",
value: "bar",
},
]);
});
});
2 changes: 1 addition & 1 deletion packages/allure-mocha/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "allure-mocha",
"version": "2.8.1",
"version": "2.9.2",
"description": "Allure Mocha integration",
"license": "Apache-2.0",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-playwright/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "allure-playwright",
"version": "2.8.1",
"version": "2.9.2",
"description": "Allure Playwright integration",
"license": "Apache-2.0",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/newman-reporter-allure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $ newman run <Collection> -e <Environment> -r allure
$ newman run <Collection> -e <Environment> -r allure --reporter-allure-export <allure-results-out-dir>
```

Use the option `--report-allure-collection-as-parent-suite` to use the collection name as the parent suite title under the _Suites_ view. This helps when you run multiple collections and want to aggregate them in a single report.
Use the option `--reporter-allure-collection-as-parent-suite` to use the collection name as the parent suite title under the _Suites_ view. This helps when you run multiple collections and want to aggregate them in a single report.

## Metadata

Expand Down
2 changes: 1 addition & 1 deletion packages/newman-reporter-allure/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "newman-reporter-allure",
"version": "2.8.1",
"version": "2.9.2",
"description": "Allure Newman integration",
"author": {
"name": "Qameta Software",
Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2631,6 +2631,7 @@ __metadata:
"@types/eslint": ^8
"@types/mocha": ^10.0.1
"@types/node": ^20.6.3
"@types/sinon": ^10.0.16
"@types/source-map-support": ^0.5.7
"@typescript-eslint/eslint-plugin": ^6.7.0
"@typescript-eslint/parser": ^6.7.0
Expand All @@ -2648,6 +2649,7 @@ __metadata:
mocha-multi-reporters: ^1.5.1
properties: ^1.2.1
rimraf: ^5.0.1
sinon: ^16.0.0
source-map-support: ^0.5.21
ts-node: ^10.9.1
typescript: ^5.2.2
Expand Down

0 comments on commit b25ef46

Please sign in to comment.