Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Allure commons #897

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 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.
2 changes: 2 additions & 0 deletions packages/allure-js-commons/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { AllureBrowserRuntime as AllureRuntime } from "./src/browser/runtime";
export { AllureInMemoryAllureWriter } from "./src/framework/writers/AllureInMemoryWriter";
70 changes: 2 additions & 68 deletions packages/allure-js-commons/index.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,2 @@
export { AllureRuntime } from "./src/AllureRuntime";
export {
typeToExtension,
InMemoryAllureWriter,
FileSystemAllureWriter,
MessageAllureWriter,
AllureResults
} from "./src/writers";
export { AllureConfig } from "./src/AllureConfig";
export { AllureGroup } from "./src/AllureGroup";
export { ExecutableItemWrapper } from "./src/ExecutableItemWrapper";
export { AllureTest } from "./src/AllureTest";
export { AllureStep } from "./src/ExecutableItemWrapper";
export { isPromise } from "./src/isPromise";
export { Allure, StepInterface } from "./src/Allure";
export {
StepBodyFunction,
AllureCommandStep,
AllureCommandStepExecutable
} from "./src/AllureCommandStep";
export {
AttachmentOptions,
MetadataMessage,
Attachment,
Category,
ExecutableItem,
StepResult,
Parameter,
StatusDetails,
Link,
Label,
ExecutorInfo,
TestResultContainer,
FixtureResult,
TestResult,
ContentType,
LabelName,
Severity,
Stage,
Status,
LinkType,
ParameterOptions,
StepMetadata,
AttachmentMetadata,
ImageDiffAttachment
} from "./src/model";

export {
allureIdRegexp,
allureIdRegexpGlobal,
allureLabelRegexp,
allureLabelRegexpGlobal,
allureReportFolder,
escapeRegExp,
getLabelsFromEnv,
getStatusFromError,
getSuitesLabels,
isAnyStepFailed,
md5,
readImageAsBase64,
serialize,
stripAscii,
extractMetadataFromString
} from "./src/utils";

export { AllureRuntimeApiInterface } from "./src/framework";

export { TestPlanV1, parseTestPlan } from "./src/testplan";
export * from "./src/model";
export * from "./src/utils";
2 changes: 2 additions & 0 deletions packages/allure-js-commons/node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { AllureNodeRuntime as AllureRuntime } from "./src/node/runtime";
export * from "./src/node/writers";
12 changes: 12 additions & 0 deletions packages/allure-js-commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./node": {
"import": "./dist/node.js",
"require": "./dist/node.js",
"types": "./dist/node.d.ts"
},
"./browser": {
"import": "./dist/browser.js",
"require": "./dist/browser.js",
"types": "./dist/browser.d.ts"
},
"./internal": {
"import": "./dist/internal.js",
"require": "./dist/internal.js",
Expand All @@ -39,12 +49,14 @@
"test": "ts-node --project test/tsconfig.json test/runner.ts"
},
"dependencies": {
"md5": "^2.3.0",
"properties": "^1.2.1",
"strip-ansi": "^5.2.0"
},
"devDependencies": {
"@types/chai": "^4.3.6",
"@types/eslint": "^8",
"@types/md5": "^2.3.5",
"@types/mocha": "^10.0.1",
"@types/node": "^20.6.3",
"@types/sinon": "^17.0.0",
Expand Down
8 changes: 0 additions & 8 deletions packages/allure-js-commons/src/AllureConfig.ts

This file was deleted.

18 changes: 18 additions & 0 deletions packages/allure-js-commons/src/browser/runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { AllureConfig } from "../framework/AllureConfig";
import { AllureRuntime } from "../framework/AllureRuntime";
import md5 from "md5";

export class AllureBrowserRuntime extends AllureRuntime {
constructor(config: AllureConfig) {
super(config, {
uuid: () => window.crypto.randomUUID(),
md5,
});
}

writeAttachmentFromPath() {
throw new Error(
"Browser Allure runtime doesn't support writting attachments from path! User AllureNodeRuntime instead or alternative methods to write attachments.",
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Stage,
Status,
StepMetadata,
} from "./model";
} from "../model";

export type StepBodyFunction<T = any> = (
this: AllureCommandStepExecutable,
Expand Down
7 changes: 7 additions & 0 deletions packages/allure-js-commons/src/framework/AllureConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { TestResult } from "../model";
import { AllureWriter } from "./AllureWriter";

export interface AllureConfig {
readonly writer: AllureWriter;
readonly testMapper?: (test: TestResult) => TestResult | null;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { stepResult } from "./constructors";
import { isPromise } from "./isPromise";
import { stepResult } from "./AllureResults";
import { isPromise } from "../utils";
import {
AttachmentOptions,
ContentType,
Expand All @@ -11,10 +11,11 @@ import {
StatusDetails,
StepResult,
TestResult,
} from "./model";
import { isAllStepsEnded, isAnyStepFailed, serialize } from "./utils";
} from "../model";
import { serialize } from "../utils";
import { isAllStepsEnded, isAnyStepFailed } from "./utils";

export class ExecutableItemWrapper {
export class AllureExecutable {
constructor(private readonly info: FixtureResult | TestResult) {}

get wrappedItem(): FixtureResult | TestResult {
Expand Down Expand Up @@ -86,10 +87,13 @@ export class ExecutableItemWrapper {

public startStep(name: string, start?: number): AllureStep {
const result = stepResult();

this.info.steps.push(result);

const allureStep = new AllureStep(result, start);

allureStep.name = name;

return allureStep;
}

Expand Down Expand Up @@ -139,13 +143,14 @@ export class ExecutableItemWrapper {
}

// This class is here because of circular dependency with ExecutableItemWrapper
export class AllureStep extends ExecutableItemWrapper {
export class AllureStep extends AllureExecutable {
constructor(
// eslint-disable-next-line @typescript-eslint/no-shadow
private readonly stepResult: StepResult,
start: number = Date.now(),
) {
super(stepResult);

this.stepResult.start = start;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { TestResultContainer } from "../model";
import { AllureExecutable } from "./AllureExecutable";
import { fixtureResult, testResultContainer } from "./AllureResults";
import { AllureRuntime } from "./AllureRuntime";
import { AllureTest } from "./AllureTest";
import { ExecutableItemWrapper } from "./ExecutableItemWrapper";
import { fixtureResult, testResultContainer } from "./constructors";
import { TestResultContainer } from "./model";

export class AllureGroup {
private testResultContainer: TestResultContainer = testResultContainer();
private testResultContainer: TestResultContainer;

constructor(private readonly runtime: AllureRuntime) {}
constructor(private readonly runtime: AllureRuntime) {
this.testResultContainer = testResultContainer(runtime.crypto.uuid());
}

startGroup(name?: string): AllureGroup {
const group = new AllureGroup(this.runtime);

this.testResultContainer.children.push(group.uuid);
group.name = name || "Unnamed";

return group;
}

Expand Down Expand Up @@ -42,15 +46,17 @@ export class AllureGroup {
this.testResultContainer.name = name;
}

addBefore(): ExecutableItemWrapper {
addBefore(): AllureExecutable {
const result = fixtureResult();

this.testResultContainer.befores.push(result);
return new ExecutableItemWrapper(result);
return new AllureExecutable(result);
}

addAfter(): ExecutableItemWrapper {
addAfter(): AllureExecutable {
const result = fixtureResult();

this.testResultContainer.afters.push(result);
return new ExecutableItemWrapper(result);
return new AllureExecutable(result);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { randomUUID } from "crypto";
import { FixtureResult, Stage, Status, StepResult, TestResult, TestResultContainer } from "./model";
import { FixtureResult, Stage, Status, StepResult, TestResult, TestResultContainer } from "../model";

export const testResultContainer = (): TestResultContainer => {
export type UUIDGenerator = () => string;

export const testResultContainer = (uuid: string): TestResultContainer => {
return {
uuid: randomUUID(),
uuid,
children: [],
befores: [],
afters: [],
Expand Down Expand Up @@ -32,10 +33,10 @@ export const stepResult = (): StepResult => {
};
};

export const testResult = (): TestResult => {
export const testResult = (uuid: string, historyUuid: string): TestResult => {
return {
uuid: randomUUID(),
historyId: randomUUID(),
uuid,
historyId: historyUuid,
status: undefined,
statusDetails: {},
stage: Stage.PENDING,
Expand Down
Loading
Loading