@allurereport/reader-api 3.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Reader API
2
+
3
+ [<img src="https://allurereport.org/public/img/allure-report.svg" height="85px" alt="Allure Report logo" align="right" />](https://allurereport.org "Allure Report")
4
+
5
+ - Learn more about Allure Report at https://allurereport.org
6
+ - 📚 [Documentation](https://allurereport.org/docs/) – discover official documentation for Allure Report
7
+ - ❓ [Questions and Support](https://github.com/orgs/allure-framework/discussions/categories/questions-support) – get help from the team and community
8
+ - 📢 [Official announcements](https://github.com/orgs/allure-framework/discussions/categories/announcements) – be in touch with the latest updates
9
+ - 💬 [General Discussion ](https://github.com/orgs/allure-framework/discussions/categories/general-discussion) – engage in casual conversations, share insights and ideas with the community
10
+
11
+ ---
12
+
13
+ ## Overview
14
+
15
+ The interfaces in the package describe the entities used for building Allure Readers.
16
+
17
+ ## Install
18
+
19
+ Use your favorite package manager to install the package:
20
+
21
+ ```shell
22
+ npm add @allurereport/reader-api
23
+ yarn add @allurereport/reader-api
24
+ pnpm add @allurereport/reader-api
25
+ ```
@@ -0,0 +1,3 @@
1
+ export * from "./model.js";
2
+ export * from "./reader.js";
3
+ export * from "./resultFile.js";
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./model.js";
2
+ export * from "./reader.js";
3
+ export * from "./resultFile.js";
@@ -0,0 +1,86 @@
1
+ export type RawTestStatus = "failed" | "broken" | "passed" | "skipped" | "unknown";
2
+ export type RawMetadata = {
3
+ [key: string]: any;
4
+ };
5
+ export interface RawFixtureResult {
6
+ uuid?: string;
7
+ testResults?: string[];
8
+ type: "before" | "after";
9
+ name?: string;
10
+ start?: number;
11
+ stop?: number;
12
+ duration?: number;
13
+ status?: RawTestStatus;
14
+ message?: string;
15
+ trace?: string;
16
+ steps?: RawStep[];
17
+ }
18
+ export interface RawTestResult {
19
+ uuid?: string;
20
+ name?: string;
21
+ status?: RawTestStatus;
22
+ fullName?: string;
23
+ testId?: string;
24
+ testCaseName?: string;
25
+ historyId?: string;
26
+ description?: string;
27
+ descriptionHtml?: string;
28
+ precondition?: string;
29
+ preconditionHtml?: string;
30
+ expectedResult?: string;
31
+ expectedResultHtml?: string;
32
+ start?: number;
33
+ stop?: number;
34
+ duration?: number;
35
+ message?: string;
36
+ trace?: string;
37
+ flaky?: boolean;
38
+ muted?: boolean;
39
+ known?: boolean;
40
+ hostId?: string;
41
+ threadId?: string;
42
+ parameters?: RawTestParameter[];
43
+ steps?: RawStep[];
44
+ labels?: RawTestLabel[];
45
+ links?: RawTestLink[];
46
+ }
47
+ export interface RawTestLabel {
48
+ name?: string;
49
+ value?: string;
50
+ }
51
+ export interface RawTestLink {
52
+ name?: string;
53
+ url?: string;
54
+ type?: string;
55
+ }
56
+ export interface RawTestParameter {
57
+ name?: string;
58
+ value?: string;
59
+ hidden?: boolean;
60
+ excluded?: boolean;
61
+ masked?: boolean;
62
+ }
63
+ export type RawStep = RawTestStepResult | RawTestAttachment;
64
+ export interface RawTestStepResult {
65
+ name?: string;
66
+ status?: RawTestStatus;
67
+ message?: string;
68
+ trace?: string;
69
+ start?: number;
70
+ stop?: number;
71
+ duration?: number;
72
+ parameters?: RawTestParameter[];
73
+ steps?: RawStep[];
74
+ type: "step";
75
+ }
76
+ export interface RawTestAttachment {
77
+ name?: string;
78
+ originalFileName?: string;
79
+ contentType?: string;
80
+ contentLength?: number;
81
+ optional?: boolean;
82
+ start?: number;
83
+ stop?: number;
84
+ duration?: number;
85
+ type: "attachment";
86
+ }
package/dist/model.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { ResultFile } from "@allurereport/plugin-api";
2
+ import { RawFixtureResult, RawMetadata, RawTestResult } from "./model.js";
3
+ export interface ReaderContext {
4
+ readerId: string;
5
+ metadata?: RawMetadata;
6
+ }
7
+ export interface ResultsVisitor {
8
+ visitTestResult(result: RawTestResult, context: ReaderContext): Promise<void>;
9
+ visitTestFixtureResult(result: RawFixtureResult, context: ReaderContext): Promise<void>;
10
+ visitAttachmentFile(result: ResultFile, context: ReaderContext): Promise<void>;
11
+ visitMetadata(metadata: RawMetadata, context: ReaderContext): Promise<void>;
12
+ }
13
+ export interface ResultsReader {
14
+ read(visitor: ResultsVisitor, data: ResultFile): Promise<boolean>;
15
+ readerId(): string;
16
+ }
package/dist/reader.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ import type { ResultFile } from "@allurereport/plugin-api";
2
+ import { ReadStream } from "node:fs";
3
+ import "node:fs/promises";
4
+ import { Readable } from "node:stream";
5
+ export declare abstract class BaseResultFile implements ResultFile {
6
+ fileName: string;
7
+ protected constructor(fileName: string);
8
+ protected abstract getContent(): ReadStream | undefined;
9
+ abstract getContentLength(): number | undefined;
10
+ getContentType(): string | undefined;
11
+ getOriginalFileName(): string;
12
+ asJson<T>(): Promise<T | undefined>;
13
+ asUtf8String(): Promise<string | undefined>;
14
+ asBuffer(): Promise<Buffer | undefined>;
15
+ writeTo(path: string): Promise<void>;
16
+ readContent<T>(transform: (stream: ReadStream) => Promise<T | undefined>): Promise<T | undefined>;
17
+ }
18
+ export declare class BufferResultFile extends BaseResultFile {
19
+ buffer: Buffer;
20
+ constructor(buffer: Buffer, fileName: string);
21
+ protected getContent(): ReadStream | undefined;
22
+ getContentLength(): number | undefined;
23
+ }
24
+ export declare class PathResultFile extends BaseResultFile {
25
+ path: string;
26
+ constructor(path: string, fileName?: string);
27
+ protected getContent(): ReadStream | undefined;
28
+ getContentLength(): number | undefined;
29
+ }
30
+ export declare const readSteamToJson: <T extends unknown>(stream: Readable) => Promise<T | undefined>;
31
+ export declare const readStreamToString: (stream: Readable) => Promise<string>;
32
+ export declare const readStreamToBuffer: (stream: Readable) => Promise<Buffer>;
@@ -0,0 +1,82 @@
1
+ import { lookup } from "mime-types";
2
+ import { ReadStream, createReadStream, createWriteStream, existsSync, statSync } from "node:fs";
3
+ import "node:fs/promises";
4
+ import { basename } from "node:path";
5
+ import { pipeline } from "node:stream/promises";
6
+ export class BaseResultFile {
7
+ constructor(fileName) {
8
+ this.fileName = fileName;
9
+ }
10
+ getContentType() {
11
+ const res = lookup(this.getOriginalFileName());
12
+ if (res === false) {
13
+ return undefined;
14
+ }
15
+ return res;
16
+ }
17
+ getOriginalFileName() {
18
+ return this.fileName;
19
+ }
20
+ async asJson() {
21
+ return await this.readContent(readSteamToJson);
22
+ }
23
+ async asUtf8String() {
24
+ return await this.readContent(readStreamToString);
25
+ }
26
+ async asBuffer() {
27
+ return await this.readContent(readStreamToBuffer);
28
+ }
29
+ async writeTo(path) {
30
+ await this.readContent(async (stream) => {
31
+ await pipeline(stream, createWriteStream(path));
32
+ });
33
+ }
34
+ async readContent(transform) {
35
+ const content = this.getContent();
36
+ return content ? await transform(content) : undefined;
37
+ }
38
+ }
39
+ export class BufferResultFile extends BaseResultFile {
40
+ constructor(buffer, fileName) {
41
+ super(basename(fileName));
42
+ this.buffer = buffer;
43
+ }
44
+ getContent() {
45
+ return ReadStream.from(this.buffer, { encoding: "utf8" });
46
+ }
47
+ getContentLength() {
48
+ return this.buffer.length;
49
+ }
50
+ }
51
+ export class PathResultFile extends BaseResultFile {
52
+ constructor(path, fileName = basename(path)) {
53
+ super(fileName);
54
+ this.path = path;
55
+ }
56
+ getContent() {
57
+ if (existsSync(this.path)) {
58
+ return createReadStream(this.path);
59
+ }
60
+ else {
61
+ return undefined;
62
+ }
63
+ }
64
+ getContentLength() {
65
+ return statSync(this.path, { throwIfNoEntry: false })?.size;
66
+ }
67
+ }
68
+ export const readSteamToJson = async (stream) => {
69
+ const text = await readStreamToString(stream);
70
+ return JSON.parse(text);
71
+ };
72
+ export const readStreamToString = async (stream) => {
73
+ const res = await readStreamToBuffer(stream);
74
+ return res.toString("utf-8");
75
+ };
76
+ export const readStreamToBuffer = async (stream) => {
77
+ const chunks = [];
78
+ for await (const chunk of stream) {
79
+ chunks.push(Buffer.from(chunk));
80
+ }
81
+ return Buffer.concat(chunks);
82
+ };
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@allurereport/reader-api",
3
+ "version": "3.0.0-beta.3",
4
+ "description": "Allure Reader API",
5
+ "keywords": [
6
+ "allure",
7
+ "testing"
8
+ ],
9
+ "repository": "https://github.com/allure-framework/allure3",
10
+ "license": "Apache-2.0",
11
+ "author": "Qameta Software",
12
+ "type": "module",
13
+ "exports": {
14
+ ".": "./dist/index.js"
15
+ },
16
+ "main": "./dist/index.js",
17
+ "module": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "scripts": {
23
+ "build": "run clean && tsc --project ./tsconfig.json",
24
+ "clean": "rimraf ./dist",
25
+ "test": "rimraf ./out && vitest run"
26
+ },
27
+ "dependencies": {
28
+ "@allurereport/core-api": "3.0.0-beta.3",
29
+ "@allurereport/plugin-api": "3.0.0-beta.3",
30
+ "mime-types": "^2.1.35"
31
+ },
32
+ "devDependencies": {
33
+ "@stylistic/eslint-plugin": "^2.6.1",
34
+ "@types/eslint": "^8.56.11",
35
+ "@types/mime-types": "^2.1.4",
36
+ "@types/node": "^20.17.9",
37
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
38
+ "@typescript-eslint/parser": "^8.0.0",
39
+ "@vitest/runner": "^2.1.8",
40
+ "allure-vitest": "^3.0.7",
41
+ "eslint": "^8.57.0",
42
+ "eslint-config-prettier": "^9.1.0",
43
+ "eslint-plugin-import": "^2.29.1",
44
+ "eslint-plugin-jsdoc": "^50.0.0",
45
+ "eslint-plugin-n": "^17.10.1",
46
+ "eslint-plugin-no-null": "^1.0.2",
47
+ "eslint-plugin-prefer-arrow": "^1.2.3",
48
+ "rimraf": "^6.0.1",
49
+ "ts-node": "^10.9.2",
50
+ "tslib": "^2.7.0",
51
+ "typescript": "^5.6.3",
52
+ "vitest": "^2.1.8"
53
+ }
54
+ }