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

Commit

Permalink
fix(allure.description): allure.description should now fetch the curr…
Browse files Browse the repository at this point in the history
…ently active test
  • Loading branch information
ryparker committed Sep 3, 2020
1 parent d541eb7 commit f645bae
Show file tree
Hide file tree
Showing 6 changed files with 1,314 additions and 1,269 deletions.
3 changes: 1 addition & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ updates:
directory: "/"
schedule:
interval: "daily"
rebase-strategy: "auto"
pull-request-branch-name:
# Separate sections of the branch name with a hyphen
# for example, `dependabot-npm_and_yarn-next_js-acorn-6.4.1`
separator: "-"
32 changes: 17 additions & 15 deletions .github/workflows/automerge-dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
name: automerge on pull request
on: [pull_request]
# Base of workflow from [this medium article](https://medium.com/@toufik.airane/automerge-github-dependabot-alerts-with-github-actions-7cd6f5763750)
# According to this [issue](https://github.com/dependabot/feedback/issues/134) if the repo contains the labels "major", "minor", "patch" then Dependabot will automatically label PRs.

name: Dependabot

on:
pull_request:

jobs:
automerge:
name: automerge dependabot
auto-merge:
name: Merge PRs labelled with Minor or Patch
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'

if: github.actor == 'dependabot[bot]' && (contains(github.event.pull_request.labels.*.name, 'minor') || contains(github.event.pull_request.labels.*.name, 'patch'))

steps:
- name: merge
uses: actions/github-script@0.2.0
- name: Merge if labels exist
uses: actions/github-script@e2ddba4dfcf622c123222f25bce0589fa3d1d493
with:
script: |
github.pullRequests.createReview({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
pull_number: context.payload.pull_request.number,
event: 'APPROVE'
})
github.pullRequests.merge({
github.issues.createComment({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
pull_number: context.payload.pull_request.number
issue_number: context.payload.pull_request.number,
body: '@dependabot merge'
})
github-token: ${{github.token}}
84 changes: 40 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,34 +126,33 @@ Options that can be passed into the `environmentOptions` property of your `jest.

You may set code comments inside your tests called DocBlocks, that can be parsed for specific allure report pragmas. These are the supported DocBlock pragmas you may add to a test.


### 🔍 Descriptions

Add descriptions that document the tested functionality.

```TS
test('does something important, when triggered by user', () => {
/** This uses a 3rd party API that typically undergoes maintenance on Tuesdays.
*/
/** This uses a 3rd party API that typically undergoes maintenance on Tuesdays.
*/

...
...
})
```

### 🏷 Tag

Tag a test with a custom label.

_Set multiple tags using a `, ` deliminator._
_Set multiple tags using a `,` deliminator._

```TS
test('does something important, when triggered by user', () => {
/**
* @tag beta
* @tag feature-flagged, api-v3
*/
/**
* @tag beta
* @tag feature-flagged, api-v3
*/

...
...
})
```

Expand All @@ -163,11 +162,11 @@ Set an owner for a test.

```TS
test('does something important, when triggered by user', () => {
/**
* @owner ios-team
*/
/**
* @owner ios-team
*/

...
..
})
```

Expand All @@ -187,11 +186,11 @@ Example of setting a test as "critical" severity

```TS
test('does something important, when triggered by user', () => {
/**
* @severity critical
*/
/**
* @severity critical
*/

...
...
})
```

Expand All @@ -205,18 +204,17 @@ Mark tests with a behavior label to organize tests in a feature based hierarchy.
| feature | Tests that if fail, will effect the expected functionality of a feature. |
| story | Tests that if fail, will effect the expected functionality of story. |


Example
Example:

```TS
test('validation message appears, when email field is skipped', () => {
/**
* @epic Automate user sign up
* @feature Registration page
* @story Validate required registration fields before creating new user
*/
/**
* @epic Automate user sign up
* @feature Registration page
* @story Validate required registration fields before creating new user
*/

...
...
})
```

Expand All @@ -229,50 +227,48 @@ Add Jira and TMS links to a test.
| issue | Adds a link to the test report that will open an existing issue in Jira. |
| tms | Adds a link to the test report that will open an existing test case in your test management system. |


Example
Example:

```TS
test('validation message appears, when email field is skipped', () => {
/**
* @issue DEBT-60
* @tms CORE-122
*/
/**
* @issue DEBT-60
* @tms CORE-122
*/

...
...
})
```

## 👩‍🎓 Advanced


### 🎛 Global Allure API

An instance of the allure runtime will be available on the Node global variable. You can utilize it's APIs to provide custom reporting functionality.

```TS
/**
* Returns the Allure test instance for the currently running test when called inside of a test.
* Returns the Allure test instance for the currently running test.
*/
allure.currentTest(): AllureTest;

/**
* Starts and returns a new step instance on the current executable.
* Adds a description to the report of the current test. Supports markdown.
*/
allure.description(description: string): void;
allure.description(markdown: string): void;

/**
* Starts and returns a new step instance on the current executable.
*/
allure.startStep(name: string): StepWrapper;

/**
* Starts a new Allure step sets it's status and attachments then ends the step all in one method.
* Starts a new Allure step, sets the status, and adds any provided attachments (optional), then ends the step.
*/
allure.logStep(
name: string,
status: Status,
attachments?: Array<{ name: string; content: string; type: ContentType }>
name: string,
status: Status,
attachments?: Array<{ name: string; content: string; type: ContentType }>
): void;

/**
Expand All @@ -284,9 +280,9 @@ allure.parameter(name: string, value: string): void;
* Attach a file to the report of the current executable.
*/
allure.attachment(
name: string,
content: Buffer | string,
type: ContentType
name: string,
content: Buffer | string,
type: ContentType
);

/**
Expand Down
40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,38 +52,38 @@
]
},
"dependencies": {
"@jest/environment": "^26.1.0",
"@jest/reporters": "^26.1.0",
"@jest/types": "^26.1.0",
"allure-js-commons": "^2.0.0-beta.7",
"@jest/environment": "^26.3.0",
"@jest/reporters": "^26.4.1",
"@jest/types": "^26.3.0",
"allure-js-commons": "2.0.0-beta.8",
"ansi_up": "^4.0.4",
"crypto": "^1.0.1",
"jest-circus": "^26.1.0",
"jest-circus": "^26.4.2",
"jest-docblock": "^26.0.0",
"jest-environment-node": "^26.1.0",
"lodash": "^4.17.19",
"prettier": "^2.0.5",
"pretty-format": "^26.1.0",
"jest-environment-node": "^26.3.0",
"lodash": "^4.17.20",
"prettier": "^2.1.1",
"pretty-format": "^26.4.2",
"strip-ansi": "^6.0.0"
},
"devDependencies": {
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@types/allure-js-commons": "^0.0.1",
"@types/highlight.js": "^9.12.4",
"@types/jest": "^26.0.7",
"@types/lodash": "^4.14.158",
"@types/node": "^14.0.27",
"commitizen": "^4.1.2",
"cz-conventional-changelog": "^3.2.0",
"eslint-config-xo-typescript": "^0.31.0",
"eslint-plugin-jest": "^23.19.0",
"@types/jest": "^26.0.13",
"@types/lodash": "^4.14.161",
"@types/node": "^14.6.3",
"commitizen": "^4.2.1",
"cz-conventional-changelog": "^3.3.0",
"eslint-config-xo-typescript": "^0.32.0",
"eslint-plugin-jest": "^23.20.0",
"husky": "^4.2.5",
"jest": "^26.1.0",
"lint-staged": "^10.2.11",
"jest": "^26.4.2",
"lint-staged": "^10.3.0",
"semantic-release": "^17.1.1",
"typescript": "^3.9.7",
"xo": "^0.32.1"
"typescript": "^4.0.2",
"xo": "^0.33.1"
},
"engines": {
"node": ">=12.x"
Expand Down
28 changes: 21 additions & 7 deletions src/jest-allure-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
AllureTest,
ContentType,
ExecutableItemWrapper,
Status,
StepInterface,
isPromise,
LabelName,
LinkType,
Severity,
LinkType
Status,
StepInterface,
isPromise
} from 'allure-js-commons';

import type AllureReporter from './allure-reporter';
Expand All @@ -33,7 +33,8 @@ export default class JestAllureInterface extends Allure {
const executable: AllureStep | AllureTest | ExecutableItemWrapper | null =
this.reporter.currentStep ??
this.reporter.currentTest ??
this.reporter.currentExecutable;
this.reporter.currentExecutable;

if (!executable) {
throw new Error('No executable!');
}
Expand Down Expand Up @@ -103,6 +104,7 @@ export default class JestAllureInterface extends Allure {

if (isPromise(result)) {
const promise = result as Promise<any>;

return promise
.then(a => {
wrappedStep.endStep();
Expand Down Expand Up @@ -135,11 +137,23 @@ export default class JestAllureInterface extends Allure {
}

public description(markdown: string) {
this.description(markdown);
const {currentTest} = this.reporter;

if (!currentTest) {
throw new Error('Expected a test to be executing before adding a description.');
}

currentTest.description = markdown;
}

public descriptionHtml(html: string) {
this.descriptionHtml(html);
const {currentTest} = this.reporter;

if (!currentTest) {
throw new Error('Expected a test to be executing before adding an HTML description.');
}

currentTest.descriptionHtml = html;
}

public attachment(
Expand Down
Loading

0 comments on commit f645bae

Please sign in to comment.