Socket
Socket
Sign inDemoInstall

jest-allure2-adapter

Package Overview
Dependencies
Maintainers
1
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-allure2-adapter - npm Package Compare versions

Comparing version 0.2.51 to 0.2.52

dist/allure-current.d.ts

43

dist/allure-reporter.d.ts
/// <reference types="node" />
import { Allure, AllureGroup, AllureStep, AllureTest, Attachment, Category, ContentType, ExecutableItemWrapper, IAllureConfig, LinkType, Severity, Stage, Status, StatusDetails, StepInterface } from 'allure-js-commons';
import { AllureReporterApi, jasmine_ } from './index';
export declare const dateStr: () => string;
export declare const dateStrShort: () => string;
import { Allure, AllureStep, AllureTest, Attachment, Category, ContentType, ExecutableItemWrapper, IAllureConfig, LinkType, Severity, Stage, Status, StatusDetails, StepInterface } from 'allure-js-commons';
import { AllureCurrentApi, AllureReporterApi, jasmine_ } from './index';
export declare class AllureReporter extends Allure implements AllureReporterApi {

@@ -12,11 +10,13 @@ private runningTest;

private currentStepStatus;
private featureForSuite;
private storyForSuite;
private featureForTest;
private storyForTest;
private storyProps;
private featureProps;
private environmentInfo;
private test_;
private executable;
constructor(config?: IAllureConfig);
get currentGroup(): AllureGroup;
get test(): AllureCurrentApi;
get currentTest(): AllureTest;
protected get currentExecutable(): ExecutableItemWrapper;
private get currentGroup();
private get currentStep();
startGroup(name: string): void;

@@ -26,22 +26,13 @@ startTest(spec: jasmine_.CustomReporterResult): void;

stepStatus(status: Status, details?: StatusDetails | any): void;
private getAttachFile;
endStep(status?: Status, stage?: Stage, details?: StatusDetails | any, end?: number): void;
private endSteps;
private applyGroupping;
endTest(spec: jasmine_.CustomReporterResult): void;
get currentStep(): AllureStep | null;
endGroup(): void;
writeCategories(categories: Category[]): void;
endGroup(): void;
private findMessageAboutThrow;
private findAnyError;
step<T>(name: string, body?: (step: StepInterface) => T, start?: number, ...args: any[]): any;
addEnvironment(name: string, value: string): this;
writeAttachment(content: Buffer | string, type: ContentType): string;
logStep(name: string, status: Status, attachments?: [Attachment]): void;
attachment(name: string, content: Buffer | string, type: ContentType): void;
stepAttachement(name: string, content: Buffer | string, type: ContentType): void;
addPackage(value: string): this;
attachment(name: string, content: Buffer | string, type?: ContentType): void;
addParameter(name: string, value: string): this;
addParameters(...params: [string, any][]): this;
addTestPathParameter(relativeFrom: string, spec: jasmine_.CustomReporterResult): this;
addPackage(value: string): this;
addLink(options: {

@@ -62,5 +53,4 @@ name?: string;

}): this;
addAttachment(name: string, buffer: any, type: ContentType): this;
addTestAttachment(name: string, buffer: any, type: ContentType): this;
addLabel(name: string, value: string): this;
addDescription(description: string): void;
description(description: string): this;

@@ -80,2 +70,9 @@ descriptionHtml(description: string): this;

severity(severity: Severity): void;
private endSteps;
private applyGroupping;
private applyDescription;
private findMessageAboutThrow;
private findAnyError;
private getAttachFile;
private featureStoryForSuite;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AllureReporter = exports.dateStrShort = exports.dateStr = void 0;
exports.AllureReporter = void 0;
const allure_js_commons_1 = require("allure-js-commons");
const path_1 = require("path");
const test_suite_props_1 = require("./test-suite-props");
const allure_current_1 = require("./allure-current");
const utils_1 = require("./utils");
const stripAnsi = require('strip-ansi');

@@ -17,36 +19,5 @@ var SpecStatus;

})(SpecStatus || (SpecStatus = {}));
exports.dateStr = () => {
const date = new Date(Date.now());
return (date.getFullYear() +
'-' +
(date.getMonth() + 1) +
'-' +
date.getDate() +
' ' +
date.getUTCHours() +
':' +
date.getMinutes() +
':' +
date.getSeconds() +
'.' +
date.getMilliseconds());
};
exports.dateStrShort = () => {
const date = new Date(Date.now());
return (date.getFullYear() +
'-' +
(date.getMonth() + 1) +
'-' +
date.getDate() +
'T' +
date.getUTCHours() +
'-' +
date.getMinutes() +
'-' +
date.getSeconds() +
'.' +
date.getMilliseconds());
};
class AllureReporter extends allure_js_commons_1.Allure {
constructor(config) {
// todo configure
super(new allure_js_commons_1.AllureRuntime(config !== null && config !== void 0 ? config : { resultsDir: 'allure-results' }));

@@ -58,13 +29,10 @@ this.runningTest = null;

this.currentStepStatus = null;
this.featureForSuite = null;
this.storyForSuite = null;
this.featureForTest = null;
this.storyForTest = null;
this.storyProps = new test_suite_props_1.TestSuiteProps();
this.featureProps = new test_suite_props_1.TestSuiteProps();
this.environmentInfo = {};
this.test_ = new allure_current_1.AllureCurrent(this.runtime, () => this.currentTest);
this.executable = new allure_current_1.AllureCurrent(this.runtime, () => this.currentExecutable);
}
get currentGroup() {
if (this.runningGroup === null) {
throw new Error('No active group');
}
return this.runningGroup;
get test() {
return this.test_;
}

@@ -81,2 +49,14 @@ get currentTest() {

}
get currentGroup() {
if (this.runningGroup === null) {
throw new Error('No active group');
}
return this.runningGroup;
}
get currentStep() {
if (this.stepStack.length > 0) {
return this.stepStack[this.stepStack.length - 1];
}
return null;
}
startGroup(name) {

@@ -92,2 +72,3 @@ // todo check currentgroup.startgroup

this.runningTest.fullName = spec.fullName;
this.executable.initDescription();
// Capture Jest worker thread for timeline report

@@ -101,3 +82,3 @@ if (process.env.JEST_WORKER_ID) {

// todo configurable
const allureStep = this.currentExecutable.startStep(exports.dateStr() + ' | ' + name, start);
const allureStep = this.currentExecutable.startStep(utils_1.dateStr() + ' | ' + name, start);
this.stepStack.push(allureStep);

@@ -111,5 +92,2 @@ return allureStep;

}
getAttachFile(content, type) {
return this.runtime.writeAttachment(stripAnsi(content), type);
}
endStep(status, stage, details, end) {

@@ -135,3 +113,3 @@ const step = this.stepStack.pop();

const file = this.getAttachFile(details, type);
step.addAttachment('StatusDetails_' + exports.dateStrShort(), type, file);
step.addAttachment('StatusDetails_' + utils_1.dateStr(true), type, file);
}

@@ -141,30 +119,2 @@ step.endStep(end);

}
endSteps() {
while (this.currentStep !== null) {
this.endStep(allure_js_commons_1.Status.BROKEN);
}
}
applyGroupping() {
const replaceDot = (name) => {
// todo regexp with \s
if (name.substr(0, 1) === '.') {
return name.substr(1, name.length - 1);
}
if (name.substr(name.length - 1) === '.') {
return name.substr(0, name.length - 1);
}
return name;
};
const groups = this.groupNameStack.map((p) => replaceDot(p));
this.addPackage(groups.join('.'));
if (groups.length > 0) {
this.parentSuite(groups[0]);
}
if (groups.length > 1) {
this.suite(groups[1]);
}
if (groups.length > 2) {
this.subSuite(groups[2]);
}
}
endTest(spec) {

@@ -206,22 +156,7 @@ this.endSteps();

}
if (this.featureForSuite && this.featureForTest == null) {
super.feature(this.featureForSuite);
}
this.featureForTest = null;
// todo
if (this.storyForSuite && this.storyForTest == null) {
super.story(this.storyForSuite);
}
this.storyForTest = null;
this.featureProps.apply((a) => super.feature(a));
this.storyProps.apply((a) => super.story(a));
this.applyDescription();
this.currentTest.endTest();
}
get currentStep() {
if (this.stepStack.length > 0) {
return this.stepStack[this.stepStack.length - 1];
}
return null;
}
writeCategories(categories) {
super.writeCategoriesDefinitions(categories);
}
endGroup() {

@@ -241,17 +176,5 @@ if (!this.currentGroup) {

}
findMessageAboutThrow(expectations) {
for (const expectation of expectations || []) {
if (expectation.matcherName === '') {
return expectation;
}
}
return null;
writeCategories(categories) {
super.writeCategoriesDefinitions(categories);
}
findAnyError(expectations) {
expectations = expectations || [];
if (expectations.length > 0) {
return expectations[0];
}
return null;
}
step(name, body, start, ...args) {

@@ -297,5 +220,2 @@ var _a, _b, _c, _d, _e, _f;

}
writeAttachment(content, type) {
return this.runtime.writeAttachment(content, type);
}
logStep(name, status, attachments) {

@@ -314,28 +234,16 @@ // console.log('AllureImpl status:', status);

}
attachment(name, content, type) {
const file = this.runtime.writeAttachment(typeof content === 'string' ? stripAnsi(content) : content, type);
this.currentTest.addAttachment(name, type, file);
attachment(name, content, type = allure_js_commons_1.ContentType.JSON) {
return this.executable.attachment(name, content, type);
}
stepAttachement(name, content, type) {
const file = this.runtime.writeAttachment(content, type);
this.currentExecutable.addAttachment(name, type, file);
}
addPackage(value) {
this.currentTest.addLabel(allure_js_commons_1.LabelName.PACKAGE, value);
return this;
}
addParameter(name, value) {
this.currentExecutable.addParameter(name, value);
this.executable.addParameter(name, value);
return this;
}
addParameters(...params) {
params.forEach((p) => {
const value = typeof p[1] !== 'string' ? JSON.stringify(p[1]) : p[1];
this.currentExecutable.addParameter(p[0], value);
});
this.executable.addParameters(...params);
return this;
}
addTestPathParameter(relativeFrom, spec) {
const relativePath = path_1.relative(relativeFrom, spec.testPath);
this.addParameter('Test Path', relativePath);
// for test
addPackage(value) {
this.currentTest.addLabel(allure_js_commons_1.LabelName.PACKAGE, value);
return this;

@@ -373,10 +281,2 @@ }

}
addAttachment(name, buffer, type) {
this.stepAttachement(name, buffer, type);
return this;
}
addTestAttachment(name, buffer, type) {
this.attachment(name, buffer, type);
return this;
}
addLabel(name, value) {

@@ -386,33 +286,18 @@ this.currentTest.addLabel(name, value);

}
addDescription(description) {
this.test_.addDescription(description);
}
description(description) {
this.currentTest.description = description;
this.executable.description(description);
return this;
}
descriptionHtml(description) {
this.currentTest.descriptionHtml = description;
this.executable.descriptionHtml(description);
return this;
}
feature(feature) {
if (this.runningTest !== null) {
super.feature(feature);
this.featureForTest = feature;
return this;
}
if (this.featureForSuite) {
throw new Error('Feature for suite can be set only once');
}
this.featureForSuite = feature;
return this;
return this.featureStoryForSuite(this.featureProps, feature, 'FEATURE');
}
story(story) {
if (this.runningTest !== null) {
super.story(story);
this.storyForTest = story;
return this;
}
if (this.storyForSuite) {
throw new Error('Story for suite can be set only once');
}
this.storyForSuite = story;
return this;
return this.featureStoryForSuite(this.storyProps, story, 'STORY');
}

@@ -449,3 +334,66 @@ tag(tag) {

}
endSteps() {
while (this.currentStep !== null) {
this.endStep(allure_js_commons_1.Status.BROKEN);
}
}
applyGroupping() {
const replaceDot = (name) => {
// todo regexp with \s
if (name.substr(0, 1) === '.') {
return name.substr(1, name.length - 1);
}
if (name.substr(name.length - 1) === '.') {
return name.substr(0, name.length - 1);
}
return name;
};
const groups = this.groupNameStack.map((p) => replaceDot(p));
this.addPackage(groups.join('.'));
if (groups.length > 0) {
this.parentSuite(groups[0]);
}
if (groups.length > 1) {
this.suite(groups[1]);
}
if (groups.length > 2) {
this.subSuite(groups[2]);
}
}
applyDescription() {
const testDesc = this.test_.getDescription();
if (testDesc.length) {
this.test_.applyDescription();
}
}
findMessageAboutThrow(expectations) {
for (const expectation of expectations || []) {
if (expectation.matcherName === '') {
return expectation;
}
}
return null;
}
findAnyError(expectations) {
expectations = expectations || [];
if (expectations.length > 0) {
return expectations[0];
}
return null;
}
getAttachFile(content, type) {
return this.runtime.writeAttachment(utils_1.getContent(content, type), type);
}
featureStoryForSuite(prop, value, type) {
if (this.runningTest) {
prop.testProp = value;
return this;
}
if (prop.suiteProp) {
throw new Error(type + ' for suite can be set only once');
}
prop.suiteProp = value;
return this;
}
}
exports.AllureReporter = AllureReporter;
/// <reference types="node" />
/// <reference types="jest" />
import { AllureStep, Attachment, Category, ContentType, LinkType, Severity, Stage, Status, StepInterface, StatusDetails } from 'allure-js-commons';
import { AllureReporter } from './allure-reporter';
import { AllureStep, Attachment, Category, ContentType, LinkType, Severity, Stage, Status, StatusDetails, StepInterface } from 'allure-js-commons';
export declare namespace jasmine_ {

@@ -25,3 +24,13 @@ interface CustomReporter {

}
export interface AllureCurrentApi {
attachment(name: string, content: Buffer | string, type?: ContentType): void;
addParameter(name: string, value: string): void;
addParameters(...params: [string, any][]): this;
/** This is a description of the foo function. */
description(description: string): void;
descriptionHtml(description: string): void;
addDescription(description: string): void;
}
export interface AllureReporterApi {
test: AllureCurrentApi;
startGroup(name: string): void;

@@ -31,16 +40,16 @@ startTest(spec: jasmine_.CustomReporterResult): void;

stepStatus(status: Status, details?: StatusDetails | any): void;
step<T>(name: string, body?: (step: StepInterface) => T, start?: number, ...args: any[]): any;
endStep(status?: Status, stage?: Stage, details?: StatusDetails | any, end?: number): void;
endTest(spec: jasmine_.CustomReporterResult): void;
endGroup(): void;
writeCategories(categories: Category[]): void;
endGroup(): void;
step<T>(name: string, body?: (step: StepInterface) => T, start?: number, ...args: any[]): any;
addEnvironment(name: string, value: string): this;
writeAttachment(content: Buffer | string, type: ContentType): string;
logStep(name: string, status: Status, attachments?: [Attachment]): void;
attachment(name: string, content: Buffer | string, type: ContentType): void;
stepAttachement(name: string, content: Buffer | string, type: ContentType): void;
addPackage(value: string): this;
attachment(name: string, content: Buffer | string, type?: ContentType): void;
addParameter(name: string, value: string): this;
addParameters(...params: [string, any][]): this;
addTestPathParameter(relativeFrom: string, spec: jasmine_.CustomReporterResult): this;
description(description: string): this;
descriptionHtml(description: string): this;
addDescription(description: string): void;
addPackage(value: string): this;
addLink(options: {

@@ -61,7 +70,3 @@ name?: string;

}): this;
addAttachment(name: string, buffer: any, type: ContentType): this;
addTestAttachment(name: string, buffer: any, type: ContentType): this;
addLabel(name: string, value: string): this;
description(description: string): this;
descriptionHtml(description: string): this;
feature(feature: string): void;

@@ -82,3 +87,3 @@ story(story: string): void;

declare global {
export const reporter: AllureReporter;
export const reporter: AllureReporterApi;
}

@@ -85,0 +90,0 @@ declare namespace JestAllureReporter {

{
"name": "jest-allure2-adapter",
"version": "0.2.51",
"version": "0.2.52",
"description": "Allure 2 Adapter for jest",

@@ -5,0 +5,0 @@ "main": "./dist/index",

@@ -239,4 +239,16 @@ # Jest-Allure-2 reporting plugin

### Feature Notes
#### Setting feature, story to all tests in file
As far as describe is async setting feature/story under describe or in any other place in the file except test will add feature/story to all tests in this file (feature/story can be overridden in test)
Todo: add example
## Releases
#### 0.2.51:
- fix stepStatus details in case when step throws error
#### 0.2.46:

@@ -243,0 +255,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc