jest-circus-allure-environment
Advanced tools
Comparing version 0.9.0 to 0.10.0
@@ -0,1 +1,13 @@ | ||
# [0.10.0](https://github.com/ryparker/jest-circus-allure-environment/compare/v0.9.0...v0.10.0) (2020-07-15) | ||
### Bug Fixes | ||
* **fixed .git repo link:** reconfigured .git/config to use renamed repo ([f76b77f](https://github.com/ryparker/jest-circus-allure-environment/commit/f76b77f6c0853257e39924ba45004b375f70819a)) | ||
### Features | ||
* **allure reporter:** implemented docblock pragma parsing which will be used to add more reporting ([7997047](https://github.com/ryparker/jest-circus-allure-environment/commit/79970479b8a5fa651da24144a7c7bcc9bb05843c)) | ||
# [0.9.0](https://github.com/ryparker/jest-circus-allure-environment/compare/v0.8.0...v0.9.0) (2020-07-12) | ||
@@ -2,0 +14,0 @@ |
@@ -8,3 +8,3 @@ "use strict"; | ||
constructor(config, context) { | ||
var _a, _b, _c, _d; | ||
var _a, _b, _c, _d, _e, _f; | ||
super(config); | ||
@@ -22,5 +22,11 @@ const allureConfig = { | ||
} | ||
this.reporter = new allure_reporter_1.default(new allure_js_commons_1.AllureRuntime(allureConfig), (_b = config.testEnvironmentOptions) === null || _b === void 0 ? void 0 : _b.jiraUrl, (_c = config.testEnvironmentOptions) === null || _c === void 0 ? void 0 : _c.environmentInfo); | ||
this.reporter = new allure_reporter_1.default({ | ||
allureRuntime: new allure_js_commons_1.AllureRuntime(allureConfig), | ||
jiraUrl: (_b = config.testEnvironmentOptions) === null || _b === void 0 ? void 0 : _b.jiraUrl, | ||
tmsUrl: (_c = config.testEnvironmentOptions) === null || _c === void 0 ? void 0 : _c.tmsUrl, | ||
environmentInfo: (_d = config.testEnvironmentOptions) === null || _d === void 0 ? void 0 : _d.environmentInfo, | ||
categoryDefinitions: (_e = config.testEnvironmentOptions) === null || _e === void 0 ? void 0 : _e.categories | ||
}); | ||
this.global.allure = this.reporter.getImplementation(); | ||
if (((_d = this.docblockPragmas) === null || _d === void 0 ? void 0 : _d.prototype) !== undefined) { | ||
if (((_f = this.docblockPragmas) === null || _f === void 0 ? void 0 : _f.prototype) !== undefined) { | ||
console.log('this.docblockPragmas:', this.docblockPragmas); | ||
@@ -93,4 +99,4 @@ } | ||
* Making this the most reliable event to start the test case, so | ||
* that only the test context is captured in the allure "Test body" | ||
* execution. | ||
* that only the test context is captured in the allure | ||
* "Test body" execution. | ||
*/ | ||
@@ -113,6 +119,7 @@ this.reporter.startCase(event.test, state, this.testPath); | ||
*/ | ||
/** @privateRemarks | ||
/** @privateRemarks -Issue- | ||
* If we capture errors from both test_done and test_fn_failure | ||
* the test case will be overriden causing allure to lose any test | ||
* context like steps that the overriden test case may have had. | ||
* the test case will be overriden causing allure to lose any | ||
* test context like steps that the overriden test case may have | ||
* had. | ||
* A workaround might be to refactor the AllureReporter class | ||
@@ -122,2 +129,5 @@ * by decouple the endTestCase method from the passTestCase, | ||
*/ | ||
/** @privateRemarks -Issue- | ||
* afterEach hooks appears in the allure "test body". | ||
*/ | ||
if (event.test.errors.length > 0) { | ||
@@ -124,0 +134,0 @@ this.reporter.failTestCase(event.test, state, this.testPath, event.test.errors[0]); |
/// <reference types="node" /> | ||
import JestAllureInterface from './jest-allure-interface'; | ||
import type * as jest from '@jest/types'; | ||
import { AllureGroup, AllureRuntime, AllureStep, AllureTest, ContentType, ExecutableItemWrapper } from 'allure-js-commons'; | ||
import { AllureGroup, AllureRuntime, AllureStep, AllureTest, Category, ContentType, ExecutableItemWrapper } from 'allure-js-commons'; | ||
export default class AllureReporter { | ||
currentExecutable: ExecutableItemWrapper | null; | ||
private runningTest; | ||
private readonly allureRuntime; | ||
currentExecutable: ExecutableItemWrapper | null; | ||
private readonly suites; | ||
private readonly steps; | ||
private runningTest; | ||
private readonly jiraUrl; | ||
constructor(allureRuntime: AllureRuntime, jiraUrl?: string, environmentInfo?: Record<string, string>); | ||
private readonly tmsUrl; | ||
private readonly categoryDefinitions; | ||
constructor(options: { | ||
allureRuntime: AllureRuntime; | ||
jiraUrl?: string; | ||
tmsUrl?: string; | ||
environmentInfo?: Record<string, string>; | ||
categoryDefinitions?: Category[]; | ||
}); | ||
getImplementation(): JestAllureInterface; | ||
@@ -34,3 +42,7 @@ get currentSuite(): AllureGroup | null; | ||
private handleError; | ||
private extractCodeDetails; | ||
private extractDocBlock; | ||
private setAllureReportPragmas; | ||
private addSuiteLabelsToTestCase; | ||
private collectTestParentNames; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const jest_allure_interface_1 = require("./jest-allure-interface"); | ||
const jest_docblock_1 = require("jest-docblock"); | ||
const stripAnsi = require("strip-ansi"); | ||
@@ -10,72 +11,26 @@ const _ = require("lodash"); | ||
const crypto_1 = require("crypto"); | ||
const category_definitions_1 = require("./category-definitions"); | ||
// Import AnsiUp from 'ansi_up'; | ||
// const ansiUp = new AnsiUp(); | ||
class AllureReporter { | ||
constructor(allureRuntime, jiraUrl, environmentInfo) { | ||
this.allureRuntime = allureRuntime; | ||
constructor(options) { | ||
var _a, _b; | ||
this.currentExecutable = null; | ||
this.runningTest = null; | ||
this.suites = []; | ||
this.steps = []; | ||
this.runningTest = null; | ||
this.jiraUrl = jiraUrl; | ||
if (environmentInfo) { | ||
this.allureRuntime.writeEnvironmentInfo(environmentInfo); | ||
this.categoryDefinitions = category_definitions_1.default; | ||
this.allureRuntime = options.allureRuntime; | ||
this.jiraUrl = (_a = options.jiraUrl) !== null && _a !== void 0 ? _a : 'https://github.com/ryparker/jest-circus-allure-environment/blob/master/README.md'; | ||
this.tmsUrl = (_b = options.tmsUrl) !== null && _b !== void 0 ? _b : 'https://github.com/ryparker/jest-circus-allure-environment/blob/master/README.md'; | ||
if (options.environmentInfo) { | ||
this.allureRuntime.writeEnvironmentInfo(options.environmentInfo); | ||
} | ||
this.allureRuntime.writeCategoriesDefinitions([ | ||
{ | ||
name: 'Response status failures', | ||
description: 'Unexpected API response status code.', | ||
messageRegex: '.*toHaveStatusCode.*', | ||
matchedStatuses: [ | ||
allure_js_commons_1.Status.FAILED | ||
] | ||
}, | ||
{ | ||
name: 'Response time failures', | ||
description: 'API responses that took longer than expected.', | ||
messageRegex: '.*toHaveResponseTimeBelow.*', | ||
matchedStatuses: [ | ||
allure_js_commons_1.Status.FAILED | ||
] | ||
}, | ||
{ | ||
name: 'JSON schema failures', | ||
description: 'An object did not validate against an expected JSON schema.', | ||
messageRegex: '.*toMatchSchema.*', | ||
matchedStatuses: [ | ||
allure_js_commons_1.Status.FAILED | ||
] | ||
}, | ||
{ | ||
name: 'Snapshot failures', | ||
description: 'Snapshot does not match the expected snapshot.', | ||
messageRegex: '.*toMatchSnapshot.*', | ||
matchedStatuses: [ | ||
allure_js_commons_1.Status.FAILED | ||
] | ||
}, | ||
{ | ||
name: 'Updated JSON schemas', | ||
description: 'Tests that have updated a JSON schema.', | ||
messageRegex: '.*updated.*schema.*updated.*', | ||
matchedStatuses: [ | ||
allure_js_commons_1.Status.PASSED | ||
] | ||
}, | ||
{ | ||
name: 'Updated snapshots', | ||
description: 'Tests that have updated a snapshot.', | ||
messageRegex: '.*updated.*snapshots.*updated.*', | ||
matchedStatuses: [ | ||
allure_js_commons_1.Status.PASSED | ||
] | ||
}, | ||
{ | ||
name: 'Skipped tests', | ||
description: 'Tests that were skipped in this run.', | ||
matchedStatuses: [ | ||
allure_js_commons_1.Status.SKIPPED | ||
] | ||
} | ||
]); | ||
if (options.categoryDefinitions) { | ||
this.categoryDefinitions = [ | ||
...this.categoryDefinitions, | ||
...options.categoryDefinitions | ||
]; | ||
} | ||
this.allureRuntime.writeCategoriesDefinitions(this.categoryDefinitions); | ||
} | ||
@@ -117,6 +72,6 @@ getImplementation() { | ||
const suite = this.currentSuite; | ||
if (suite && type && type.includes('before')) { | ||
if (suite && type.includes('before')) { | ||
this.currentExecutable = suite.addBefore(); | ||
} | ||
else if (suite && type && type.includes('after')) { | ||
else if (suite && type.includes('after')) { | ||
this.currentExecutable = suite.addAfter(); | ||
@@ -129,3 +84,2 @@ } | ||
if (error) { | ||
// Console.log('endHook -> handleError'); | ||
const { status, message, trace } = this.handleError(error); | ||
@@ -151,19 +105,15 @@ this.currentExecutable.status = status; | ||
this.currentTest.stage = allure_js_commons_1.Stage.RUNNING; | ||
const testFunc = test.fn ? prettier.format(test.fn.toString(), { parser: 'typescript', plugins: [parser] }) : 'Error parsing function'; | ||
this.currentTest.description = `### Test\n\`\`\`typescript\n${testFunc}\n\`\`\`\n`; | ||
if (test.fn) { | ||
const serializedTestCode = test.fn.toString(); | ||
const { code, comments, pragmas } = this.extractCodeDetails(serializedTestCode); | ||
this.setAllureReportPragmas(pragmas); | ||
this.currentTest.description = `${comments}\n### Test\n\`\`\`typescript\n${code}\n\`\`\`\n`; | ||
} | ||
else { | ||
this.currentTest.description = '### Test\nCode is not available.\n'; | ||
} | ||
if ((_b = (_a = state.parentProcess) === null || _a === void 0 ? void 0 : _a.env) === null || _b === void 0 ? void 0 : _b.JEST_WORKER_ID) { | ||
this.currentTest.addLabel(allure_js_commons_1.LabelName.THREAD, state.parentProcess.env.JEST_WORKER_ID); | ||
} | ||
const pathsArray = testPath.split('/'); | ||
const [parentSuite, suite, ...subSuites] = pathsArray; | ||
if (parentSuite) { | ||
this.currentTest.addLabel(allure_js_commons_1.LabelName.PARENT_SUITE, parentSuite); | ||
this.currentTest.addLabel(allure_js_commons_1.LabelName.PACKAGE, parentSuite); | ||
} | ||
if (suite) { | ||
this.currentTest.addLabel(allure_js_commons_1.LabelName.SUITE, suite); | ||
} | ||
if (subSuites.length > 0) { | ||
this.currentTest.addLabel(allure_js_commons_1.LabelName.SUB_SUITE, subSuites.join(' > ')); | ||
} | ||
this.addSuiteLabelsToTestCase(testPath); | ||
} | ||
@@ -257,2 +207,66 @@ passTestCase(test, state, testPath) { | ||
} | ||
extractCodeDetails(serializedTestCode) { | ||
if (this.currentTest === null) { | ||
throw new Error('No active test'); | ||
} | ||
const docblock = this.extractDocBlock(serializedTestCode); | ||
const { pragmas, comments } = jest_docblock_1.parseWithComments(docblock); | ||
let code = serializedTestCode.replace(docblock, ''); | ||
// Add newline before the first expect() | ||
code = code.split(/(expect[\S\s.]*)/g).join('\n'); | ||
code = prettier.format(code, { parser: 'typescript', plugins: [parser] }); | ||
return { code, comments, pragmas }; | ||
} | ||
extractDocBlock(contents) { | ||
const docblockRe = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/gm; | ||
const match = contents.match(docblockRe); | ||
return match ? match[0].trimStart() : ''; | ||
} | ||
setAllureReportPragmas(pragmas) { | ||
if (!this.currentTest) { | ||
throw new Error('No test running.'); | ||
} | ||
const test = this.currentTest; | ||
for (const [pragma, value] of Object.entries(pragmas)) { | ||
switch (pragma) { | ||
case 'issue': | ||
test.addLink(`${this.jiraUrl}${value}`, value, allure_js_commons_1.LinkType.ISSUE); | ||
break; | ||
case 'tms': | ||
test.addLink(`${this.tmsUrl}${value}`, value, allure_js_commons_1.LinkType.TMS); | ||
break; | ||
case 'tag': | ||
case 'tags': | ||
// TODO: Make the comma space optional. | ||
if (value.includes(', ')) { | ||
value.split(', ').map((t) => test.addLabel(allure_js_commons_1.LabelName.TAG, t)); | ||
} | ||
else { | ||
test.addLabel(allure_js_commons_1.LabelName.TAG, value); | ||
} | ||
break; | ||
default: | ||
test.addLabel(pragma, value); | ||
break; | ||
} | ||
} | ||
} | ||
addSuiteLabelsToTestCase(testPath) { | ||
if (!this.currentTest) { | ||
throw new Error('No active test case'); | ||
} | ||
const pathsArray = testPath.split('/'); | ||
const [parentSuite, suite, ...subSuites] = pathsArray; | ||
if (parentSuite) { | ||
this.currentTest.addLabel(allure_js_commons_1.LabelName.PARENT_SUITE, parentSuite); | ||
this.currentTest.addLabel(allure_js_commons_1.LabelName.PACKAGE, parentSuite); | ||
} | ||
if (suite) { | ||
this.currentTest.addLabel(allure_js_commons_1.LabelName.SUITE, suite); | ||
} | ||
if (subSuites.length > 0) { | ||
this.currentTest.addLabel(allure_js_commons_1.LabelName.SUB_SUITE, subSuites.join(' > ')); | ||
} | ||
} | ||
// TODO: Use if describe blocks are present. | ||
collectTestParentNames(parent) { | ||
@@ -259,0 +273,0 @@ const testPath = []; |
{ | ||
"name": "jest-circus-allure-environment", | ||
"version": "0.9.0", | ||
"repository": "https://ryparker@github.com/ryparker/jest-circus-allure-environment.git", | ||
"version": "0.10.0", | ||
"repository": "https://github.com/ryparker/jest-circus-allure-environment.git", | ||
"author": "Ryan Parker <ryan.parker3@outlook.com>", | ||
@@ -51,2 +51,3 @@ "license": "MIT", | ||
"jest-circus": "^26.1.0", | ||
"jest-docblock": "^26.0.0", | ||
"jest-environment-node": "^26.1.0", | ||
@@ -64,3 +65,3 @@ "lodash": "^4.17.19", | ||
"@types/lodash": "^4.14.157", | ||
"@types/node": "^14.0.19", | ||
"@types/node": "^14.0.23", | ||
"commitizen": "^4.1.2", | ||
@@ -67,0 +68,0 @@ "cz-conventional-changelog": "^3.2.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
62994
22
832
13
+ Addedjest-docblock@^26.0.0
+ Addedcaniuse-lite@1.0.30001638(transitive)
+ Addedelectron-to-chromium@1.4.815(transitive)
- Removedcaniuse-lite@1.0.30001639(transitive)
- Removedelectron-to-chromium@1.4.816(transitive)