@allurereport/web-commons 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
+ # Allure Web Commons
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 package includes utilities which are used in web-implementations of Allure reports.
16
+
17
+ ## Install
18
+
19
+ Use your favorite package manager to install the package:
20
+
21
+ ```shell
22
+ npm add @allurereport/web-commons
23
+ yarn add @allurereport/web-commons
24
+ pnpm add @allurereport/web-commons
25
+ ```
package/dist/data.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export declare const ALLURE_LIVE_RELOAD_HASH_STORAGE_KEY = "__allure_report_live_reload_hash__";
2
+ export declare const createReportDataScript: (reportFiles?: {
3
+ name: string;
4
+ value: string;
5
+ }[]) => string;
6
+ export declare const ensureReportDataReady: () => Promise<unknown>;
7
+ export declare const loadReportData: (name: string) => Promise<string>;
8
+ export declare const reportDataUrl: (path: string, contentType?: string) => Promise<string>;
9
+ export declare const fetchReportJsonData: <T>(path: string) => Promise<T>;
10
+ export declare const fetchReportAttachment: (path: string, contentType: string) => Promise<Response>;
11
+ export declare const getReportOptions: <T>() => T;
package/dist/data.js ADDED
@@ -0,0 +1,81 @@
1
+ export const ALLURE_LIVE_RELOAD_HASH_STORAGE_KEY = "__allure_report_live_reload_hash__";
2
+ export const createReportDataScript = (reportFiles = []) => {
3
+ if (reportFiles.length === 0) {
4
+ return `
5
+ <script async>
6
+ window.allureReportDataReady = true;
7
+ </script>
8
+ `;
9
+ }
10
+ const reportFilesDeclaration = reportFiles.map(({ name, value }) => `d('${name}','${value}')`).join(",");
11
+ return `
12
+ <script async>
13
+ window.allureReportDataReady = false;
14
+ window.allureReportData = window.allureReportData || {};
15
+
16
+ function d(name, value){
17
+ return new Promise(function (resolve) {
18
+ window.allureReportData[name] = value;
19
+
20
+ return resolve(true);
21
+ });
22
+ }
23
+ </script>
24
+ <script defer>
25
+ Promise.allSettled([${reportFilesDeclaration}])
26
+ .then(function(){
27
+ window.allureReportDataReady = true;
28
+ })
29
+ </script>
30
+ `;
31
+ };
32
+ export const ensureReportDataReady = () => new Promise((resolve) => {
33
+ const waitForReady = () => {
34
+ if (globalThis.allureReportDataReady) {
35
+ return resolve(true);
36
+ }
37
+ setTimeout(waitForReady, 30);
38
+ };
39
+ waitForReady();
40
+ });
41
+ export const loadReportData = async (name) => {
42
+ await ensureReportDataReady();
43
+ return new Promise((resolve, reject) => {
44
+ if (globalThis.allureReportData[name]) {
45
+ return resolve(globalThis.allureReportData[name]);
46
+ }
47
+ else {
48
+ return reject(new Error(`Data "${name}" not found!`));
49
+ }
50
+ });
51
+ };
52
+ export const reportDataUrl = async (path, contentType = "application/octet-stream") => {
53
+ if (globalThis.allureReportData) {
54
+ const dataKey = path.replace(/\?attachment$/, "");
55
+ const value = await loadReportData(dataKey);
56
+ return `data:${contentType};base64,${value}`;
57
+ }
58
+ const baseEl = globalThis.document.head.querySelector("base")?.href ?? "https://localhost";
59
+ const url = new URL(path, baseEl);
60
+ const liveReloadHash = globalThis.localStorage.getItem(ALLURE_LIVE_RELOAD_HASH_STORAGE_KEY);
61
+ if (liveReloadHash) {
62
+ url.searchParams.set("live_reload_hash", liveReloadHash);
63
+ }
64
+ return url.pathname + url.search + url.hash;
65
+ };
66
+ export const fetchReportJsonData = async (path) => {
67
+ const url = await reportDataUrl(path);
68
+ const res = await globalThis.fetch(url);
69
+ if (!res.ok) {
70
+ throw new Error(`Failed to fetch ${url}, response status: ${res.status}`);
71
+ }
72
+ const data = res.json();
73
+ return data;
74
+ };
75
+ export const fetchReportAttachment = async (path, contentType) => {
76
+ const url = await reportDataUrl(path, contentType);
77
+ return globalThis.fetch(url);
78
+ };
79
+ export const getReportOptions = () => {
80
+ return globalThis.allureReportOptions;
81
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./data.js";
2
+ export * from "./static.js";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./data.js";
2
+ export * from "./static.js";
@@ -0,0 +1,8 @@
1
+ export declare const createScriptTag: (src: string, options?: {
2
+ async?: false;
3
+ defer?: false;
4
+ }) => string;
5
+ export declare const createStylesLinkTag: (src: string) => string;
6
+ export declare const createFontLinkTag: (src: string) => string;
7
+ export declare const createFaviconLinkTag: (src: string) => string;
8
+ export declare const createBaseUrlScript: () => string;
package/dist/static.js ADDED
@@ -0,0 +1,25 @@
1
+ export const createScriptTag = (src, options) => {
2
+ return `<script ${options?.async ? "async" : ""} ${options?.defer ? "defer" : ""} src="${src}"></script>`;
3
+ };
4
+ export const createStylesLinkTag = (src) => {
5
+ return `<link rel="stylesheet" type="text/css" href="${src}">`;
6
+ };
7
+ export const createFontLinkTag = (src) => {
8
+ return `<link rel="preload" href="${src}" as="font" type="font/woff" crossorigin /> `;
9
+ };
10
+ export const createFaviconLinkTag = (src) => {
11
+ return `<link rel="icon" href="${src}">`;
12
+ };
13
+ export const createBaseUrlScript = () => {
14
+ return `
15
+ <script>
16
+ const { origin, pathname } = window.location;
17
+ const url = new URL(pathname, origin);
18
+ const baseEl = document.createElement("base");
19
+
20
+ baseEl.href = url.toString();
21
+
22
+ window.document.head.appendChild(baseEl);
23
+ </script>
24
+ `;
25
+ };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@allurereport/web-commons",
3
+ "version": "3.0.0-beta.3",
4
+ "description": "Collection of utilities used across the web Allure reports",
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
+ "module": "dist/index.js",
17
+ "types": "dist/index.d.ts",
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "scripts": {
22
+ "build": "run clean && tsc --project ./tsconfig.json",
23
+ "clean": "rimraf ./dist"
24
+ },
25
+ "dependencies": {
26
+ "@allurereport/core-api": "3.0.0-beta.3"
27
+ },
28
+ "devDependencies": {
29
+ "@stylistic/eslint-plugin": "^2.6.1",
30
+ "@types/eslint": "^8.56.11",
31
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
32
+ "@typescript-eslint/parser": "^8.0.0",
33
+ "@vitest/runner": "^2.1.8",
34
+ "allure-js-commons": "^3.0.7",
35
+ "allure-vitest": "^3.0.7",
36
+ "eslint": "^8.57.0",
37
+ "eslint-config-prettier": "^9.1.0",
38
+ "eslint-plugin-import": "^2.29.1",
39
+ "eslint-plugin-jsdoc": "^50.0.0",
40
+ "eslint-plugin-n": "^17.10.1",
41
+ "eslint-plugin-no-null": "^1.0.2",
42
+ "eslint-plugin-prefer-arrow": "^1.2.3",
43
+ "rimraf": "^6.0.1",
44
+ "tslib": "^2.7.0",
45
+ "typescript": "^5.6.3",
46
+ "vitest": "^2.1.8"
47
+ }
48
+ }