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

Commit

Permalink
fix(types.ts): added HTML to the ContentType enum & renamed `catego…
Browse files Browse the repository at this point in the history
…ryDefinitions` -> `categories`

Also bumped deps

BREAKING CHANGE: Renamed environment option `categoryDefinitions` to `categories`

fix #153
  • Loading branch information
ryparker committed Feb 5, 2021
1 parent edadfa8 commit 93c9925
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 213 deletions.
17 changes: 8 additions & 9 deletions README.md
@@ -1,6 +1,5 @@
# Jest Circus Allure Environment

[![npm version](https://badge.fury.io/js/jest-circus-allure-environment.svg)](https://badge.fury.io/js/jest-circus-allure-environment)
[![jest](https://jestjs.io/img/jest-badge.svg)](https://github.com/facebook/jest)
![Lint-Build-Test-Publish](https://github.com/ryparker/jest-circus-allure-reporter/workflows/Lint-Build-Test-Publish/badge.svg)
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo)
Expand Down Expand Up @@ -115,14 +114,14 @@ _See the [setupFilesAfterEnv docs](https://jestjs.io/docs/en/configuration#setup

Options that can be passed into the `environmentOptions` property of your `jest.config.js`

| Parameter | Description | Default |
| ------------------- | ----------------------------------------------------------------------------------- | ------------------ |
| resultsDir | Path where Allure result files will be written. | `"allure-results"` |
| jiraUrl | URL to Jira instance. Any `@issue` docblock pragmas will link to this URL. | `undefined` |
| tmsUrl | URL to TMS instance. Any `@tms` docblock pragmas will link to this URL. | `undefined` |
| environmentInfo | Key value pairs that will appear under the environment section of the Allure report | `{}` |
| categoryDefinitions | Array of custom categories you wish to see in the Allure report | `[]` |
| testPath | Path to your test files. This path will be subtracted from the Allure report when organizing tests into suites. | `Jest.config.rootDir` |
| Parameter | Description | Default |
| --------------- | ---------------------------------------------------------------------------------------------------------------- | --------------------- |
| resultsDir | Path where Allure result files will be written. | `"allure-results"` |
| jiraUrl | URL to Jira instance. Any `@issue` docblock pragmas will link to this URL. | `undefined` |
| tmsUrl | URL to TMS instance. Any `@tms` docblock pragmas will link to this URL. | `undefined` |
| environmentInfo | Key value pairs that will appear under the environment section of the Allure report | `{}` |
| categories | Array of custom categories you wish to see in the Allure report. [See an example](./src/category-definitions.ts) | `[]` |
| testPath | Path to your test files. This path will be subtracted from the Allure report when organizing tests into suites. | `Jest.config.rootDir` |

## 📈 DocBlocks

Expand Down
19 changes: 10 additions & 9 deletions package.json
Expand Up @@ -17,7 +17,8 @@
},
"jest": {
"testEnvironment": "./dist",
"testRunner": "jest-circus/runner"
"testRunner": "jest-circus/runner",
"logHeapUsage": true
},
"xo": {
"globals": [
Expand Down Expand Up @@ -89,20 +90,20 @@
"@semantic-release/git": "^9.0.0",
"@types/allure-js-commons": "^0.0.1",
"@types/highlight.js": "^10.1.0",
"@types/jest": "^26.0.19",
"@types/lodash": "^4.14.167",
"@types/node": "^14.14.19",
"commitizen": "^4.2.2",
"@types/jest": "^26.0.20",
"@types/lodash": "^4.14.168",
"@types/node": "^14.14.25",
"commitizen": "^4.2.3",
"conventional-changelog-conventionalcommits": "^4.5.0",
"cz-conventional-changelog": "3.3.0",
"eslint-config-xo-typescript": "^0.37.0",
"eslint-plugin-jest": "^24.1.3",
"husky": "^4.3.6",
"husky": "^4.3.8",
"jest": "^26.6.3",
"lint-staged": "^10.5.3",
"semantic-release": "^17.3.1",
"semantic-release": "^17.3.7",
"typescript": "^4.1.3",
"xo": "^0.36.1"
"xo": "^0.37.1"
},
"engines": {
"node": ">=12.x"
Expand All @@ -123,4 +124,4 @@
"collect",
"analyze"
]
}
}
2 changes: 1 addition & 1 deletion src/allure-node-environment.ts
Expand Up @@ -56,7 +56,7 @@ export default class AllureNodeEnvironment extends NodeEnvironment {
jiraUrl: config.testEnvironmentOptions?.jiraUrl as string,
tmsUrl: config.testEnvironmentOptions?.tmsUrl as string,
environmentInfo: config.testEnvironmentOptions?.environmentInfo as Record<string, any>,
categoryDefinitions: config.testEnvironmentOptions?.categories as Array<Record<string, any>>
categories: config.testEnvironmentOptions?.categories as Array<Record<string, any>>
});
}

Expand Down
26 changes: 11 additions & 15 deletions src/allure-reporter.ts
@@ -1,30 +1,26 @@
import type * as jest from '@jest/types';
import * as os from 'os';

import {
AllureGroup,
AllureRuntime,
AllureStep,
AllureTest,
Category,
ContentType,
ExecutableItemWrapper,
LabelName,
LinkType,
Stage,
Status,
StatusDetails
Status
} from 'allure-js-commons';

import JestAllureInterface from './jest-allure-interface';
import {createHash} from 'crypto';
import defaultCategoryDefinitions from './category-definitions';
import defaultCategories from './category-definitions';
import {parseWithComments} from 'jest-docblock';

import stripAnsi = require('strip-ansi');
import _ = require('lodash');
import prettier = require('prettier/standalone');
import parser = require('prettier/parser-typescript');
import type {ContentType} from './types';
import type * as jest from '@jest/types';

export default class AllureReporter {
currentExecutable: ExecutableItemWrapper | null = null;
Expand All @@ -34,14 +30,14 @@ export default class AllureReporter {
private readonly tests: AllureTest[] = [];
private readonly jiraUrl: string;
private readonly tmsUrl: string;
private readonly categoryDefinitions: Category[] = defaultCategoryDefinitions;
private readonly categories: Category[] = defaultCategories;

constructor(options: {
allureRuntime: AllureRuntime;
jiraUrl?: string;
tmsUrl?: string;
environmentInfo?: Record<string, string>;
categoryDefinitions?: Category[];
categories?: Category[];
}) {
this.allureRuntime = options.allureRuntime;

Expand All @@ -53,14 +49,14 @@ export default class AllureReporter {
this.allureRuntime.writeEnvironmentInfo(options.environmentInfo);
}

if (options.categoryDefinitions) {
this.categoryDefinitions = [
...this.categoryDefinitions,
...options.categoryDefinitions
if (options.categories) {
this.categories = [
...this.categories,
...options.categories
];
}

this.allureRuntime.writeCategoriesDefinitions(this.categoryDefinitions);
this.allureRuntime.writeCategoriesDefinitions(this.categories);
}

getImplementation(): JestAllureInterface {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Expand Up @@ -7,6 +7,7 @@ declare global {
export {default} from './allure-node-environment';

export * from 'allure-js-commons';
export type {ContentType} from './types';
export type {default as StepWrapper} from './step-wrapper';
export type {default as JestAllureInterface} from './jest-allure-interface';

5 changes: 2 additions & 3 deletions src/jest-allure-interface.ts
Expand Up @@ -3,7 +3,6 @@ import {
AllureRuntime,
AllureStep,
AllureTest,
ContentType,
ExecutableItemWrapper,
LabelName,
LinkType,
Expand All @@ -12,9 +11,9 @@ import {
StepInterface,
isPromise
} from 'allure-js-commons';

import type AllureReporter from './allure-reporter';
import StepWrapper from './step-wrapper';
import type AllureReporter from './allure-reporter';
import type {ContentType} from './types';

export default class JestAllureInterface extends Allure {
public jiraUrl: string;
Expand Down
3 changes: 2 additions & 1 deletion src/step-wrapper.ts
@@ -1,4 +1,5 @@
import type {AllureStep, StepInterface, Stage, ContentType} from 'allure-js-commons';
import type {AllureStep, StepInterface, Stage} from 'allure-js-commons';
import type {ContentType} from './types';
import {Status} from 'allure-js-commons';
import type AllureReporter from './allure-reporter';

Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
@@ -0,0 +1,7 @@
import type {ContentType as AllureContentType} from 'allure-js-commons';

enum CustomContentType {
HTML = 'text/html'
}

export type ContentType = AllureContentType | CustomContentType;

0 comments on commit 93c9925

Please sign in to comment.