Skip to content

Commit

Permalink
Tracking doc: rewrite @wdio/allure-reporter package into Typescript (
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuxlu authored Dec 22, 2020
1 parent 98f35e7 commit 040ddd0
Show file tree
Hide file tree
Showing 37 changed files with 3,489 additions and 3,206 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ tests/typings/**/dist

**/build
/*.js
allure-reporter.d.ts
devtools.d.ts
!.eslintrc.js
!jest.config.js
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"devDependencies": {
"@octokit/rest": "^18.0.0",
"@tsconfig/node10": "^1.0.7",
"@types/cheerio": "^0.22.22",
"@types/jest": "^26.0.0",
"@types/node": "^14.14.13",
"@typescript-eslint/eslint-plugin": "^4.4.0",
Expand Down
55 changes: 55 additions & 0 deletions packages/wdio-allure-reporter/allure-reporter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
declare namespace AllureReporter {
type StepStatus = 'passed' | 'failed' | 'broken' | 'canceled' | 'skipped'

function addFeature(
featureName: string
): void;
function addLabel(
name: string,
value: string
): void;
function addSeverity(
severity: string
): void;
function addIssue(
issue: string
): void;
function addTestId(
testId: string
): void;
function addStory(
storyName: string
): void;
function addEnvironment(
name: string,
value: string
): void;
function addDescription(
description: string,
descriptionType: string
): void;
function addAttachment(
name: string,
content: any,
mimeType?: string
): void;
function startStep(
title: string
): void;
function endStep(
status?: StepStatus
): void;
function addStep(
title: string,
attachmentObject?: object,
status?: string
): void;
function addArgument(
name: string,
value: string
): void;
}

declare module "@wdio/allure-reporter" {
export default AllureReporter
}
100 changes: 100 additions & 0 deletions packages/wdio-allure-reporter/src/@types/allure-js-commons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Allure is providing its own types in v2, but there's too many changes,
// so this is temporarily copied here to customize typings with allure 1
// Type definitions for allure-js-commons 0.0
// Project: https://github.com/allure-framework/allure-js
// Definitions by: Denis Artyuhovich <https://github.com/zaqqaz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.7
declare module 'allure-js-commons/beans/step' {
class Step {}
export = Step
}

declare module 'allure-js-commons' {
class Allure {
constructor();

setOptions(options: Allure.Options): void;
getCurrentSuite(): Allure.Suite;
getCurrentTest(): Allure.Test;
startSuite(suiteName: string, timestamp?: number): void;
endSuite(timestamp?: number): void;
startCase(testName: string, timestamp?: number): void;
endCase(status: Allure.Status, err?: {}, timestamp?: number): void;
startStep(stepName?: string, timestamp?: number): void;
endStep(status: Allure.Status, timestamp?: number): void;
setDescription(description: string, timestamp?: number): void;
addAttachment(attachmentName: string, buffer: any, type?: string): void;
pendingCase(testName: string, timestamp?: number): void;
}

export = Allure;
namespace Allure {
interface Options {
targetDir: string;
}

// type Status = "passed" | "pending" | "skipped" | "failed" | "broken";
type Status = 'passed' | 'pending' | 'skipped' | 'failed' | 'broken' | 'canceled';

enum TYPE {
TEXT = 'text',
HTML = 'html',
MARKDOWN = 'markdown'
}

class Suite {
currentStep: Allure.Step;
testcases: string[];
name: string;

constructor(name: string, timestamp?: number);

end(timestamp?: number): void;
hasTests(): boolean;
addTest(test: Test): boolean;
toXML(): string;
}

class Test {
steps: Allure.Step[];
name: string;

constructor(name: string, timestamp?: number);

setDescription(description: string | undefined, type?: TYPE): void;
addLabel(name: string, value?: string): void;
addParameter(kind: any, name: string, value?: string): void;
addStep(step: Step): void;
addAttachment(attachment: Attachment): void;
end(status: Status, error: Error, timestamp?: number): void;
toXML(): string;
}

class Description {
constructor(value: string, type: TYPE);

toXML(): string;
}

class Step {
attachments: Attachment[];

constructor(name: string, timestamp?: number);

addStep(step: Step): void;
addAttachment(attachment: Attachment): void;
end(status: Status, error: Error, timestamp?: number): void;
toXML(): string;
}

class Attachment {
constructor(title: string, source: any, size: number, mime: string);

addStep(step: Step): void;
addAttachment(attachment: Attachment): void;
end(status: Status, error: Error, timestamp?: number): void;
toXML(): string;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
function indentAll(lines) {
return lines.split('\n').map(x => ' ' + x).join('\n')
}

/**
* An error that encapsulates more than one error, to support soft-assertions from Jasmine
* even though Allure's API assumes one error-per test
*/
export default class CompoundError extends Error {
constructor(...innerErrors) {
const message = ['CompoundError: One or more errors occurred. ---'].
concat(innerErrors.map(x => {
if (x.stack) return `${indentAll(x.stack)}\n--- End of stack trace ---`
return ` ${x.message}\n--- End of error message ---`
})).join('\n')

super(message)
this.innerErrors = innerErrors
}
}
function indentAll(lines: string) {
return lines.split('\n').map(x => ' ' + x).join('\n')
}

/**
* An error that encapsulates more than one error, to support soft-assertions from Jasmine
* even though Allure's API assumes one error-per test
*/
export default class CompoundError extends Error {
public innerErrors: Error[]

constructor(...innerErrors: Error[]) {
const message = ['CompoundError: One or more errors occurred. ---'].
concat(innerErrors.map(x => {
if (x.stack) return `${indentAll(x.stack)}\n--- End of stack trace ---`
return ` ${x.message}\n--- End of error message ---`
})).join('\n')

super(message)
this.innerErrors = innerErrors
}
}
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
const PASSED = 'passed'
const FAILED = 'failed'
const BROKEN = 'broken'
const PENDING = 'pending'
const CANCELED = 'canceled'
const SKIPPED = 'skipped'

const testStatuses = {
PASSED,
FAILED,
BROKEN,
PENDING
}

const stepStatuses = {
PASSED,
FAILED,
BROKEN,
CANCELED,
SKIPPED
}

const events = {
addLabel: 'allure:addLabel',
addFeature: 'allure:addFeature',
addStory: 'allure:addStory',
addSeverity: 'allure:addSeverity',
addIssue: 'allure:addIssue',
addTestId: 'allure:addTestId',
addEnvironment: 'allure:addEnvironment',
addDescription: 'allure:addDescription',
addAttachment: 'allure:addAttachment',
startStep: 'allure:startStep',
endStep: 'allure:endStep',
addStep: 'allure:addStep',
addArgument: 'allure:addArgument'
}

const mochaEachHooks = ['"before each" hook', '"after each" hook']
const mochaAllHooks = ['"before all" hook', '"after all" hook']
const linkPlaceholder = '{}'

export { testStatuses, stepStatuses, events, mochaEachHooks, mochaAllHooks, linkPlaceholder }
import Allure from 'allure-js-commons'

export const PASSED = 'passed'
export const FAILED = 'failed'
export const BROKEN = 'broken'
export const PENDING = 'pending'
export const CANCELED = 'canceled'
export const SKIPPED = 'skipped'

const testStatuses: Record<string, Allure.Status> = {
PASSED,
FAILED,
BROKEN,
PENDING
} as const
const stepStatuses: Record<string, Allure.Status> = {
PASSED,
FAILED,
BROKEN,
CANCELED,
SKIPPED
} as const

const events = {
addLabel: 'allure:addLabel',
addFeature: 'allure:addFeature',
addStory: 'allure:addStory',
addSeverity: 'allure:addSeverity',
addIssue: 'allure:addIssue',
addTestId: 'allure:addTestId',
addEnvironment: 'allure:addEnvironment',
addDescription: 'allure:addDescription',
addAttachment: 'allure:addAttachment',
startStep: 'allure:startStep',
endStep: 'allure:endStep',
addStep: 'allure:addStep',
addArgument: 'allure:addArgument'
}

const mochaEachHooks = ['"before each" hook', '"after each" hook']
const mochaAllHooks = ['"before all" hook', '"after all" hook']
const linkPlaceholder = '{}'

export { testStatuses, stepStatuses, events, mochaEachHooks, mochaAllHooks, linkPlaceholder }
Loading

0 comments on commit 040ddd0

Please sign in to comment.