Skip to content
This repository has been archived by the owner on Aug 28, 2022. It is now read-only.

Commit

Permalink
feat(allurereporter): accepting environmentInfo and jiraUrl from jest…
Browse files Browse the repository at this point in the history
… environmentt options
  • Loading branch information
ryparker committed Jul 8, 2020
1 parent 4519929 commit b2ae7ab
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 33 deletions.
6 changes: 3 additions & 3 deletions src/allure-node-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class AllureNodeEnvironment extends NodeEnvironment {
constructor(config: Config.ProjectConfig, context: EnvironmentContext) {
super(config);

const allureConfig: IAllureConfig = {resultsDir: 'allure-results', ...config.testEnvironmentOptions};
const allureConfig: IAllureConfig = {resultsDir: 'allure-results'};

this.docblockPragmas = context.docblockPragmas;
this.testPath = context.testPath ? context.testPath.replace(config.rootDir, '') : '';
Expand All @@ -25,12 +25,12 @@ export default class AllureNodeEnvironment extends NodeEnvironment {
this.testPath = this.testPath.split('__tests__/')[1];
}

this.reporter = new AllureReporter(new AllureRuntime(allureConfig));
this.reporter = new AllureReporter(new AllureRuntime(allureConfig), config.testEnvironmentOptions?.enironmentInfo, config.testEnvironmentOptions?.jiraUrl);

this.global.allure = this.reporter.getImplementation();

if (this.docblockPragmas?.prototype !== undefined) {
console.log(this.docblockPragmas);
console.log('this.docblockPragmas:', this.docblockPragmas);
}
}

Expand Down
73 changes: 45 additions & 28 deletions src/allure-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ export default class AllureReporter {
private readonly suites: AllureGroup[] = [];
private readonly steps: AllureStep[] = [];
private runningTest: AllureTest | null = null;
private readonly jiraUrl: string;

constructor(private readonly allureRuntime: AllureRuntime) { }
constructor(private readonly allureRuntime: AllureRuntime, environmentInfo: Record<string, string>, jiraUrl: string) {
this.environmentInfo(environmentInfo);
this.jiraUrl = jiraUrl;
}

public getImplementation(): JestAllureInterface {
return new JestAllureInterface(this, this.allureRuntime);
return new JestAllureInterface(this, this.allureRuntime, this.jiraUrl);
}

get currentSuite(): AllureGroup | null {
Expand Down Expand Up @@ -82,10 +86,9 @@ export default class AllureReporter {
this.currentExecutable.stage = Stage.FINISHED;

if (error) {
this.currentExecutable.status = Status.FAILED;
const {status, message, trace} = this.handleError(error);

const message = stripAnsi(error.message);
const trace = stripAnsi(error.stack ?? '').replace(message, '');
this.currentExecutable.status = status;

this.currentExecutable.statusDetails = {message, trace};
} else {
Expand Down Expand Up @@ -161,29 +164,7 @@ export default class AllureReporter {
}
}

// If (error.matcherResult) {
// console.log('error.matcherResult:', error.matcherResult);
// } else {
// console.log('error:', error);
// }

const status = error.matcherResult ? Status.FAILED : Status.BROKEN;

const isSnapshotFailure = error.matcherResult?.name === 'toMatchSnapshot';

let message: string;
let trace: string;

if (isSnapshotFailure) {
const [matcherHint, ...snapshotDiff] = stripAnsi(error.matcherResult.message()).split('@@');

message = matcherHint;
trace = snapshotDiff.join('');
// Console.log({message, trace});
} else {
message = stripAnsi(error.message);
trace = stripAnsi(error.stack ?? '').replace(message, '');
}
const {status, message, trace} = this.handleError(error);

this.endTest(status, {message, trace});
}
Expand Down Expand Up @@ -223,6 +204,42 @@ export default class AllureReporter {
this.currentTest = null;
}

private handleError(error: Error | any) {
if (error.matcherResult) {
console.log('error.matcherResult:', error.matcherResult);
} else {
console.log('error:', error);
}

const status = error.matcherResult ? Status.FAILED : Status.BROKEN;

const isSnapshotFailure = error.matcherResult?.name === 'toMatchSnapshot';

let message: string;
let trace: string;

if (isSnapshotFailure) {
const [matcherHint, ...snapshotDiff] = stripAnsi(error.matcherResult.message()).split('@@');

message = matcherHint;
trace = snapshotDiff.join('');
} else {
message = stripAnsi(error.message);
trace = stripAnsi(error.stack ?? '').replace(message, '');
}

if (!message && status) {
message = status;
trace = '';
}

return {
status,
message,
trace
};
}

private collectTestParentNames(
parent: jest.Circus.TestEntry | jest.Circus.DescribeBlock | undefined
) {
Expand Down
6 changes: 4 additions & 2 deletions src/jest-allure-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ import type AllureReporter from './allure-reporter';
import StepWrapper from './step-wrapper';

export default class JestAllureInterface extends Allure {
public jiraUrl = '';
public jiraUrl: string;
public tmsUrl = '';

constructor(
private readonly reporter: AllureReporter,
runtime: AllureRuntime
runtime: AllureRuntime,
jiraUrl?: string
) {
super(runtime);
this.jiraUrl = jiraUrl ?? '';
}

public get currentExecutable(): AllureStep | AllureTest | ExecutableItemWrapper {
Expand Down

0 comments on commit b2ae7ab

Please sign in to comment.