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

Refactor: add swappable writer to have in-memory results in testing #39

Merged
merged 2 commits into from
Aug 22, 2019
Merged
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
2 changes: 1 addition & 1 deletion packages/allure-mocha/.prettierrc → .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"singleQuote": true,
"singleQuote": false,
"useTabs": false,
"tabWidth": 2,
"semi": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-cucumberjs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ export {
}
from "./src/CucumberJSAllureReporter";
export {
AllureRuntime, AllureConfig, ContentType, Severity, GlobalInfoWriter, ExecutorInfo, Category
AllureRuntime, AllureConfig, ContentType, Severity, ExecutorInfo, Category
} from "allure-js-commons";
1 change: 0 additions & 1 deletion packages/allure-cucumberjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
],
"repository": "https://github.com/allure-framework/allure-js",
"main": "./dist/index.js",
"typings": "./dist/declarations/",
"scripts": {
"clean": "rimraf ./dist ./out",
"lint": "eslint ./src ./features ./index.ts --ext .ts",
Expand Down
14 changes: 5 additions & 9 deletions packages/allure-cucumberjs/src/CucumberAllureInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import {
AllureTest,
ContentType,
ExecutableItemWrapper,
GlobalInfoWriter,
isPromise,
LabelName,
Severity, Status, StepInterface
Status,
StepInterface,
AllureRuntime
} from "allure-js-commons";
import { CucumberJSAllureFormatter } from "./CucumberJSAllureReporter";

export class CucumberAllureInterface extends Allure {
constructor(private readonly reporter: CucumberJSAllureFormatter) {
super();
constructor(private readonly reporter: CucumberJSAllureFormatter, runtime: AllureRuntime) {
super(runtime);
}

protected get currentExecutable(): ExecutableItemWrapper {
Expand Down Expand Up @@ -78,10 +78,6 @@ export class CucumberAllureInterface extends Allure {
addLabel(name: string, value: string): void {
this.currentTest.addLabel(name, value);
}

getGlobalInfoWriter(): GlobalInfoWriter {
return this.reporter.getGlobalInfoWriter();
}
}

export class WrappedStep {
Expand Down
7 changes: 1 addition & 6 deletions packages/allure-cucumberjs/src/CucumberJSAllureReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
AllureTest,
ContentType,
ExecutableItemWrapper,
GlobalInfoWriter,
LabelName
} from "allure-js-commons";
import { Result } from "./events/Result";
Expand Down Expand Up @@ -81,7 +80,7 @@ export class CucumberJSAllureFormatter extends Formatter {
return message;
};

this.allureInterface = new CucumberAllureInterface(this);
this.allureInterface = new CucumberAllureInterface(this, this.allureRuntime);
options.supportCodeLibrary.World.prototype.allure = this.allureInterface;
this.beforeHooks = options.supportCodeLibrary.beforeTestCaseHookDefinitions;
this.afterHooks = options.supportCodeLibrary.afterTestCaseHookDefinitions;
Expand Down Expand Up @@ -317,10 +316,6 @@ export class CucumberJSAllureFormatter extends Formatter {
writeAttachment(content: Buffer | string, type: ContentType): string {
return this.allureRuntime.writeAttachment(content, type);
}

getGlobalInfoWriter(): GlobalInfoWriter {
return this.allureRuntime as GlobalInfoWriter;
}
}


3 changes: 1 addition & 2 deletions packages/allure-cucumberjs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"chai",
"cucumber"
],
"outDir": "./dist",
"declarationDir": "./dist/declarations"
"outDir": "./dist"
}
}
1 change: 0 additions & 1 deletion packages/allure-jasmine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export {
ContentType,
Severity,
Allure,
GlobalInfoWriter,
ExecutorInfo,
Category
} from "allure-js-commons";
1 change: 0 additions & 1 deletion packages/allure-jasmine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"author": "Ilya Korobitsyn <mail@korobochka.org>",
"repository": "https://github.com/allure-framework/allure-js",
"main": "./dist/index.js",
"typings": "./dist/declarations/",
"scripts": {
"clean": "rimraf ./dist ./out",
"lint": "eslint ./src ./test ./index.ts --ext .ts",
Expand Down
43 changes: 22 additions & 21 deletions packages/allure-jasmine/src/JasmineAllureReporter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
/* eslint-disable no-undef */
import {
AllureGroup, IAllureRuntime, AllureStep, AllureTest, ContentType, ExecutableItemWrapper,
isPromise, LabelName, Severity, Stage, Status, GlobalInfoWriter, Allure, StepInterface, Label
AllureGroup,
AllureRuntime,
AllureStep,
AllureTest,
ContentType,
ExecutableItemWrapper,
isPromise,
LabelName,
Stage,
Status,
Allure,
StepInterface,
Label,
IAllureConfig
} from "allure-js-commons";
import FailedExpectation = jasmine.FailedExpectation;

Expand All @@ -22,8 +33,10 @@ export class JasmineAllureReporter implements jasmine.CustomReporter {
private runningTest: AllureTest | null = null;
private stepStack: AllureStep[] = [];
private runningExecutable: ExecutableItemWrapper | null = null;
private readonly runtime: AllureRuntime;

constructor(private readonly runtime: IAllureRuntime) {
constructor(config: IAllureConfig) {
this.runtime = new AllureRuntime(config);
this.installHooks();
}

Expand All @@ -39,11 +52,7 @@ export class JasmineAllureReporter implements jasmine.CustomReporter {
}

getInterface(): Allure {
return new JasmineAllureInterface(this);
}

getGlobalInfoWriter(): GlobalInfoWriter {
return this.runtime as GlobalInfoWriter;
return new JasmineAllureInterface(this, this.runtime);
}

get currentTest(): AllureTest {
Expand Down Expand Up @@ -164,8 +173,7 @@ export class JasmineAllureReporter implements jasmine.CustomReporter {
this.labelStack.pop();
}

jasmineDone(runDetails: jasmine.RunDetails): void {
}
jasmineDone(runDetails: jasmine.RunDetails): void {}

private findMessageAboutThrow(expectations?: FailedExpectation[]): FailedExpectation | null {
for (const e of expectations || []) {
Expand Down Expand Up @@ -252,10 +260,9 @@ export class JasmineAllureReporter implements jasmine.CustomReporter {
}
}


export class JasmineAllureInterface extends Allure {
constructor(private readonly reporter: JasmineAllureReporter) {
super();
constructor(private readonly reporter: JasmineAllureReporter, runtime: AllureRuntime) {
super(runtime);
}

public label(name: string, value: string): void {
Expand All @@ -267,9 +274,7 @@ export class JasmineAllureInterface extends Allure {
}

protected get currentExecutable(): ExecutableItemWrapper {
return this.reporter.currentStep
|| this.reporter.currentExecutable
|| this.reporter.currentTest;
return this.reporter.currentStep || this.reporter.currentExecutable || this.reporter.currentTest;
}

protected get currentTest(): AllureTest {
Expand Down Expand Up @@ -314,10 +319,6 @@ export class JasmineAllureInterface extends Allure {
const file = this.reporter.writeAttachment(content, type);
this.currentExecutable.addAttachment(name, type, file);
}

getGlobalInfoWriter(): GlobalInfoWriter {
return this.reporter.getGlobalInfoWriter();
}
}

class WrappedStep { // needed?
Expand Down
20 changes: 7 additions & 13 deletions packages/allure-jasmine/test/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import {Allure, InMemoryAllureRuntime} from "allure-js-commons";
import {JasmineAllureReporter} from "../src/JasmineAllureReporter";
import { Allure, InMemoryAllureWriter } from "allure-js-commons";
import { JasmineAllureReporter } from "../src/JasmineAllureReporter";
import Env = jasmine.Env;

export async function runTest(fun: (j: Env, k: Allure) => void): Promise<InMemoryAllureRuntime> {
const runtime = new InMemoryAllureRuntime({
resultsDir: "./out/allure-results"
});

const d = new Promise((resolve, reject) => {
const reporter = new JasmineAllureReporter(runtime);
export async function runTest(fun: (j: Env, k: Allure) => void) {
const writer = new InMemoryAllureWriter();
await new Promise((resolve, reject) => {
const reporter = new JasmineAllureReporter({ writer, resultsDir: "unused" });
const env: Env = eval("new jasmine.Env()");
env.addReporter(reporter);
env.addReporter({ jasmineDone: resolve });
const allure = reporter.getInterface();
fun(env, allure);
env.execute();
});

await d;
return runtime;
return writer;
}

export function delay(ms: number) {
Expand All @@ -33,7 +28,6 @@ export function delayFail(ms: number) {
});
}


/*
todo:
failing test +
Expand Down
39 changes: 10 additions & 29 deletions packages/allure-jasmine/test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,29 @@
import { JasmineAllureReporter } from "../src/JasmineAllureReporter";
import { JasmineConsoleReporter } from "../src/JasmineConsoleReporter";
import {
Status,
GlobalInfoWriter,
Allure,
AllureRuntime
} from "allure-js-commons";
import { TestResult } from "allure-js-commons";
import { Status, TestResult } from "allure-js-commons";

jasmine.getEnv().addReporter(new JasmineConsoleReporter());

export const runtime = new AllureRuntime({
const reporter = new JasmineAllureReporter({
resultsDir: "./out/allure-results",
testMapper: (result: TestResult) => {
if (result.status == Status.SKIPPED) result.fullName = `(WAS SKIPPED) ${result.fullName}`;
return result;
}
});
const reporter = new JasmineAllureReporter(runtime);
jasmine.getEnv().addReporter(reporter);

export const allure: Allure = reporter.getInterface();
const giw: GlobalInfoWriter = allure.getGlobalInfoWriter();
export const allure = reporter.getInterface();

giw.writeExecutorInfo({
"name": "Jenkins",
"type": "jenkins",
"url": "http://example.org",
"buildOrder": 13,
"buildName": "allure-report_deploy#13",
"buildUrl": "http://example.org/build#13",
"reportUrl": "http://example.org/build#13/AllureReport",
"reportName": "Demo allure report"
allure.writeEnvironmentInfo({
a: "b",
PATH: "azazaz",
APPDATA: "C:\\USERS\\test (x86)\\AppData",
PS1: "\\[\\0330;$MSYSTEM;${PWD//[^[:ascii:]]/?}\\007\\]",
TEST1: "\\usr\\bin"
});

giw.writeEnvironmentInfo({
"a": "b",
"PATH": "azazaz",
"APPDATA": "C:\\USERS\\test (x86)\\AppData",
"PS1": "\\[\\0330;$MSYSTEM;${PWD//[^[:ascii:]]/?}\\007\\]",
"TEST1": "\\usr\\bin"
});

giw.writeCategories([
allure.writeCategoriesDefinitions([
{
"name": "Sad tests",
"messageRegex": /.*Sad.*/,
Expand Down
3 changes: 1 addition & 2 deletions packages/allure-jasmine/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"node",
"jasmine"
],
"outDir": "./dist",
"declarationDir": "./dist/declarations"
"outDir": "./dist"
}
}
1 change: 0 additions & 1 deletion packages/allure-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"author": "Stanislav Seliverstov <s.seliverstov@gmail.com>",
"repository": "https://github.com/allure-framework/allure-js",
"main": "./dist/index.js",
"typings": "./dist/declarations/",
"scripts": {
"clean": "rimraf ./dist ./out",
"lint": "eslint ./test --ext .ts",
Expand Down
18 changes: 8 additions & 10 deletions packages/allure-jest/test/default-runner/allure-report.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { JasmineAllureReporter } from "allure-jasmine";
import { AllureRuntime, Status, TestResult } from "allure-js-commons";
import { Status, TestResult } from "allure-js-commons";

const reporter = new JasmineAllureReporter(
new AllureRuntime({
resultsDir: "./out/allure-results",
testMapper: (result: TestResult) => {
if (result.status == Status.SKIPPED) result.fullName = `(WAS SKIPPED) ${result.fullName}`;
return result;
}
})
);
const reporter = new JasmineAllureReporter({
resultsDir: "./out/allure-results",
testMapper: (result: TestResult) => {
if (result.status == Status.SKIPPED) result.fullName = `(WAS SKIPPED) ${result.fullName}`;
return result;
}
});
jasmine.getEnv().addReporter(reporter);
3 changes: 1 addition & 2 deletions packages/allure-jest/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
],
"skipLibCheck": true,
"outDir": "./dist",
"rootDir": "./",
"declarationDir": "./dist/declarations"
"rootDir": "./"
}
}
4 changes: 1 addition & 3 deletions packages/allure-js-commons/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export { AllureRuntime } from "./src/AllureRuntime";
export { InMemoryAllureWriter } from "./src/writers";
export { AllureConfig, IAllureConfig } 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 { GlobalInfoWriter } from "./src/GlobalInfoWriter";
export {
Attachment,
Category,
Expand All @@ -26,5 +26,3 @@ export {
Status,
LinkType
} from "./src/model";
export { InMemoryAllureRuntime } from "./src/InMemoryAllureRuntime";
export { IAllureRuntime } from "./src/IAllureRuntime";
1 change: 0 additions & 1 deletion packages/allure-js-commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"author": "Ilya Korobitsyn <mail@korobochka.org>",
"repository": "https://github.com/allure-framework/allure-js",
"main": "./dist/index.js",
"typings": "./dist/declarations/",
"scripts": {
"clean": "rimraf ./dist",
"lint": "eslint ./src ./index.ts --ext .ts",
Expand Down
Loading