@decaf-ts/utils 0.9.6 → 0.10.0

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.
@@ -0,0 +1,260 @@
1
+ import path from "path";
2
+ import fs from "fs";
3
+ import { installIfNotAvailable } from "./../utils/fs.js";
4
+ /**
5
+ * @description Environment variable key for Jest HTML reporters temporary directory path
6
+ * @summary Constant defining the environment variable key for Jest HTML reporters
7
+ * @const JestReportersTempPathEnvKey
8
+ * @memberOf module:utils
9
+ */
10
+ export const JestReportersTempPathEnvKey = "JEST_HTML_REPORTERS_TEMP_DIR_PATH";
11
+ /**
12
+ * @description Array of dependencies required by the test reporter
13
+ * @summary List of npm packages needed for reporting functionality
14
+ * @const dependencies
15
+ * @memberOf module:utils
16
+ */
17
+ const dependencies = ["jest-html-reporters", "json2md", "chartjs-node-canvas"];
18
+ /**
19
+ * @description Normalizes imports to handle both CommonJS and ESModule formats
20
+ * @summary Utility function to handle module import differences between formats
21
+ * @template T - Type of the imported module
22
+ * @param {Promise<T>} importPromise - Promise returned by dynamic import
23
+ * @return {Promise<T>} Normalized module
24
+ * @function normalizeImport
25
+ * @memberOf module:utils
26
+ */
27
+ async function normalizeImport(importPromise) {
28
+ // CommonJS's `module.exports` is wrapped as `default` in ESModule.
29
+ return importPromise.then((m) => (m.default || m));
30
+ }
31
+ /**
32
+ * @description Test reporting utility class for managing test results and evidence
33
+ * @summary A comprehensive test reporter that handles various types of test artifacts including messages,
34
+ * attachments, data, images, tables, and graphs. It provides methods to report and store test evidence
35
+ * in different formats and manages dependencies for reporting functionality.
36
+ *
37
+ * @template T - Type of data being reported
38
+ * @param {string} [testCase="tests"] - Name of the test case
39
+ * @param {string} [basePath] - Base path for storing test reports
40
+ * @class
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const reporter = new TestReporter('login-test');
45
+ *
46
+ * // Report test messages
47
+ * await reporter.reportMessage('Test Started', 'Login flow initiated');
48
+ *
49
+ * // Report test data
50
+ * await reporter.reportData('user-credentials', { username: 'test' }, 'json');
51
+ *
52
+ * // Report test results table
53
+ * await reporter.reportTable('test-results', {
54
+ * headers: ['Step', 'Status'],
55
+ * rows: [
56
+ * { Step: 'Login', Status: 'Pass' },
57
+ * { Step: 'Validation', Status: 'Pass' }
58
+ * ]
59
+ * });
60
+ *
61
+ * // Report test evidence
62
+ * await reporter.reportAttachment('Screenshot', screenshotBuffer);
63
+ * ```
64
+ *
65
+ * @mermaid
66
+ * sequenceDiagram
67
+ * participant Client
68
+ * participant TestReporter
69
+ * participant FileSystem
70
+ * participant Dependencies
71
+ *
72
+ * Client->>TestReporter: new TestReporter(testCase, basePath)
73
+ * TestReporter->>FileSystem: Create report directory
74
+ *
75
+ * alt Report Message
76
+ * Client->>TestReporter: reportMessage(title, message)
77
+ * TestReporter->>Dependencies: Import helpers
78
+ * TestReporter->>FileSystem: Store message
79
+ * else Report Data
80
+ * Client->>TestReporter: reportData(reference, data, type)
81
+ * TestReporter->>Dependencies: Process data
82
+ * TestReporter->>FileSystem: Store formatted data
83
+ * else Report Table
84
+ * Client->>TestReporter: reportTable(reference, tableDef)
85
+ * TestReporter->>Dependencies: Convert to MD format
86
+ * TestReporter->>FileSystem: Store table
87
+ * end
88
+ */
89
+ export class TestReporter {
90
+ constructor(testCase = "tests", basePath = path.join(process.cwd(), "workdocs", "reports", "evidences")) {
91
+ this.testCase = testCase;
92
+ this.basePath = basePath;
93
+ this.basePath = path.join(basePath, this.testCase);
94
+ if (!fs.existsSync(this.basePath)) {
95
+ fs.mkdirSync(basePath, { recursive: true });
96
+ }
97
+ }
98
+ /**
99
+ * @description Imports required helper functions
100
+ * @summary Ensures all necessary dependencies are available and imports helper functions
101
+ * @return {Promise<void>} Promise that resolves when helpers are imported
102
+ */
103
+ async importHelpers() {
104
+ this.deps = await installIfNotAvailable([dependencies[0]], this.deps);
105
+ // if (!process.env[JestReportersTempPathEnvKey])
106
+ // process.env[JestReportersTempPathEnvKey] = './workdocs/reports';
107
+ const { addMsg, addAttach } = await normalizeImport(import(`${dependencies[0]}/helper`));
108
+ TestReporter.addMsgFunction = addMsg;
109
+ TestReporter.addAttachFunction = addAttach;
110
+ }
111
+ /**
112
+ * @description Reports a message to the test report
113
+ * @summary Adds a formatted message to the test report with an optional title
114
+ * @param {string} title - Title of the message
115
+ * @param {string | object} message - Content of the message
116
+ * @return {Promise<void>} Promise that resolves when the message is reported
117
+ */
118
+ async reportMessage(title, message) {
119
+ if (!TestReporter.addMsgFunction)
120
+ await this.importHelpers();
121
+ const msg = `${title}${message ? `\n${message}` : ""}`;
122
+ await TestReporter.addMsgFunction({ message: msg });
123
+ }
124
+ /**
125
+ * @description Reports an attachment to the test report
126
+ * @summary Adds a formatted message to the test report with an optional title
127
+ * @param {string} title - Title of the message
128
+ * @param {string | Buffer} attachment - Content of the message
129
+ * @return {Promise<void>} Promise that resolves when the message is reported
130
+ */
131
+ async reportAttachment(title, attachment) {
132
+ if (!TestReporter.addAttachFunction)
133
+ await this.importHelpers();
134
+ await TestReporter.addAttachFunction({
135
+ attach: attachment,
136
+ description: title,
137
+ });
138
+ }
139
+ /**
140
+ * @description Reports data with specified type
141
+ * @summary Processes and stores data in the test report with formatting
142
+ * @param {string} reference - Reference identifier for the data
143
+ * @param {string | number | object} data - Data to be reported
144
+ * @param {PayloadType} type - Type of the payload
145
+ * @param {boolean} [trim=false] - Whether to trim the data
146
+ * @return {Promise<void>} Promise that resolves when data is reported
147
+ */
148
+ async report(reference, data, type, trim = false) {
149
+ try {
150
+ let attachFunction = this.reportMessage.bind(this);
151
+ let extension = ".txt";
152
+ switch (type) {
153
+ case "image":
154
+ data = Buffer.from(data);
155
+ extension = ".png";
156
+ attachFunction = this.reportAttachment.bind(this);
157
+ break;
158
+ case "json":
159
+ if (trim) {
160
+ if (data.request)
161
+ delete data["request"];
162
+ if (data.config)
163
+ delete data["config"];
164
+ }
165
+ data = JSON.stringify(data, null, 2);
166
+ extension = ".json";
167
+ break;
168
+ case "md":
169
+ extension = ".md";
170
+ break;
171
+ case "text":
172
+ extension = ".txt";
173
+ break;
174
+ default:
175
+ console.log(`Unsupported type ${type}. assuming text`);
176
+ }
177
+ reference = reference.includes("\n")
178
+ ? reference
179
+ : `${reference}${extension}`;
180
+ await attachFunction(reference, data);
181
+ }
182
+ catch (e) {
183
+ throw new Error(`Could not store attach artifact ${reference} under to test report ${this.testCase} - ${e}`);
184
+ }
185
+ }
186
+ /**
187
+ * @description Reports data with a specified type
188
+ * @summary Wrapper method for reporting various types of data
189
+ * @param {string} reference - Reference identifier for the data
190
+ * @param {string | number | object} data - Data to be reported
191
+ * @param {PayloadType} [type="json"] - Type of the payload
192
+ * @param {boolean} [trim=false] - Whether to trim the data
193
+ * @return {Promise<void>} Promise that resolves when data is reported
194
+ */
195
+ async reportData(reference, data, type = "json", trim = false) {
196
+ return this.report(reference, data, type, trim);
197
+ }
198
+ /**
199
+ * @description Reports a JSON object
200
+ * @summary Convenience method for reporting JSON objects
201
+ * @param {string} reference - Reference identifier for the object
202
+ * @param {object} json - JSON object to be reported
203
+ * @param {boolean} [trim=false] - Whether to trim the object
204
+ * @return {Promise<void>} Promise that resolves when object is reported
205
+ */
206
+ async reportObject(reference, json, trim = false) {
207
+ return this.report(reference, json, "json", trim);
208
+ }
209
+ /**
210
+ * @description Reports a table in markdown format
211
+ * @summary Converts and stores a table definition in markdown format
212
+ * @param {string} reference - Reference identifier for the table
213
+ * @param {MdTableDefinition} tableDef - Table definition object
214
+ * @return {Promise<void>} Promise that resolves when table is reported
215
+ */
216
+ async reportTable(reference, tableDef) {
217
+ this.deps = await installIfNotAvailable([dependencies[1]], this.deps);
218
+ let txt;
219
+ try {
220
+ const json2md = await normalizeImport(import(`${dependencies[1]}`));
221
+ txt = json2md(tableDef);
222
+ }
223
+ catch (e) {
224
+ throw new Error(`Could not convert JSON to Markdown - ${e}`);
225
+ }
226
+ return this.report(reference, txt, "md");
227
+ }
228
+ /**
229
+ * @description Reports a graph using Chart.js
230
+ * @summary Generates and stores a graph visualization
231
+ * @param {string} reference - Reference identifier for the graph
232
+ * @param {any} config - Chart.js configuration object
233
+ * @return {Promise<void>} Promise that resolves when graph is reported
234
+ */
235
+ async reportGraph(reference, config) {
236
+ this.deps = await installIfNotAvailable([dependencies[2]], this.deps);
237
+ const { ChartJSNodeCanvas } = await normalizeImport(import(dependencies[2]));
238
+ const width = 600; //px
239
+ const height = 800; //px
240
+ const backgroundColour = "white"; // Uses https://www.w3schools.com/tags/canvas_fillstyle.asp
241
+ const chartJSNodeCanvas = new ChartJSNodeCanvas({
242
+ width,
243
+ height,
244
+ backgroundColour,
245
+ });
246
+ const image = await chartJSNodeCanvas.renderToBuffer(config);
247
+ return await this.reportImage(reference, image);
248
+ }
249
+ /**
250
+ * @description Reports an image to the test report
251
+ * @summary Stores an image buffer in the test report
252
+ * @param {string} reference - Reference identifier for the image
253
+ * @param {Buffer} buffer - Image data buffer
254
+ * @return {Promise<void>} Promise that resolves when image is reported
255
+ */
256
+ async reportImage(reference, buffer) {
257
+ return this.report(reference, buffer, "image");
258
+ }
259
+ }
260
+ //# sourceMappingURL=TestReporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TestReporter.js","sourceRoot":"","sources":["../../../src/tests/TestReporter.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,yBAAoB;AAoCpD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,mCAAmC,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,YAAY,GAAG,CAAC,qBAAqB,EAAE,SAAS,EAAE,qBAAqB,CAAC,CAAC;AAE/E;;;;;;;;GAQG;AACH,KAAK,UAAU,eAAe,CAAI,aAAyB;IACzD,mEAAmE;IACnE,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,IAA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0,0 +1,2 @@
1
+ export * from "./TestReporter";
2
+ export * from "./Consumer";
@@ -0,0 +1,3 @@
1
+ export * from "./TestReporter.js";
2
+ export * from "./Consumer.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tests/index.ts"],"names":[],"mappings":"AAAA,kCAA+B;AAC/B,8BAA2B"}
@@ -1,193 +1 @@
1
- import { MdTableDefinition } from "./md";
2
- /**
3
- * @interface AddAttachParams
4
- * @description Parameters for adding an attachment to a report
5
- * @summary Interface for attachment parameters
6
- * @memberOf module:utils
7
- */
8
- export interface AddAttachParams {
9
- attach: string | Buffer;
10
- description: string | object;
11
- context?: any;
12
- bufferFormat?: string;
13
- }
14
- /**
15
- * @interface AddMsgParams
16
- * @description Parameters for adding a message to a report
17
- * @summary Interface for message parameters
18
- * @memberOf module:utils
19
- */
20
- export interface AddMsgParams {
21
- message: string | object;
22
- context?: any;
23
- }
24
- /**
25
- * @typedef {("json"|"image"|"text"|"md")} PayloadType
26
- * @description Types of payloads that can be handled
27
- * @summary Union type for payload types
28
- * @memberOf module:utils
29
- */
30
- export type PayloadType = "json" | "image" | "text" | "md";
31
- /**
32
- * @description Environment variable key for Jest HTML reporters temporary directory path
33
- * @summary Constant defining the environment variable key for Jest HTML reporters
34
- * @const JestReportersTempPathEnvKey
35
- * @memberOf module:utils
36
- */
37
- export declare const JestReportersTempPathEnvKey = "JEST_HTML_REPORTERS_TEMP_DIR_PATH";
38
- /**
39
- * @description Test reporting utility class for managing test results and evidence
40
- * @summary A comprehensive test reporter that handles various types of test artifacts including messages,
41
- * attachments, data, images, tables, and graphs. It provides methods to report and store test evidence
42
- * in different formats and manages dependencies for reporting functionality.
43
- *
44
- * @template T - Type of data being reported
45
- * @param {string} [testCase="tests"] - Name of the test case
46
- * @param {string} [basePath] - Base path for storing test reports
47
- * @class
48
- *
49
- * @example
50
- * ```typescript
51
- * const reporter = new TestReporter('login-test');
52
- *
53
- * // Report test messages
54
- * await reporter.reportMessage('Test Started', 'Login flow initiated');
55
- *
56
- * // Report test data
57
- * await reporter.reportData('user-credentials', { username: 'test' }, 'json');
58
- *
59
- * // Report test results table
60
- * await reporter.reportTable('test-results', {
61
- * headers: ['Step', 'Status'],
62
- * rows: [
63
- * { Step: 'Login', Status: 'Pass' },
64
- * { Step: 'Validation', Status: 'Pass' }
65
- * ]
66
- * });
67
- *
68
- * // Report test evidence
69
- * await reporter.reportAttachment('Screenshot', screenshotBuffer);
70
- * ```
71
- *
72
- * @mermaid
73
- * sequenceDiagram
74
- * participant Client
75
- * participant TestReporter
76
- * participant FileSystem
77
- * participant Dependencies
78
- *
79
- * Client->>TestReporter: new TestReporter(testCase, basePath)
80
- * TestReporter->>FileSystem: Create report directory
81
- *
82
- * alt Report Message
83
- * Client->>TestReporter: reportMessage(title, message)
84
- * TestReporter->>Dependencies: Import helpers
85
- * TestReporter->>FileSystem: Store message
86
- * else Report Data
87
- * Client->>TestReporter: reportData(reference, data, type)
88
- * TestReporter->>Dependencies: Process data
89
- * TestReporter->>FileSystem: Store formatted data
90
- * else Report Table
91
- * Client->>TestReporter: reportTable(reference, tableDef)
92
- * TestReporter->>Dependencies: Convert to MD format
93
- * TestReporter->>FileSystem: Store table
94
- * end
95
- */
96
- export declare class TestReporter {
97
- protected testCase: string;
98
- protected basePath: string;
99
- /**
100
- * @description Function for adding messages to the test report
101
- * @summary Static handler for processing and storing test messages
102
- * @type {function(AddMsgParams): Promise<void>}
103
- */
104
- protected static addMsgFunction: (params: AddMsgParams) => Promise<void>;
105
- /**
106
- * @description Function for adding attachments to the test report
107
- * @summary Static handler for processing and storing test attachments
108
- * @type {function(AddAttachParams): Promise<void>}
109
- */
110
- protected static addAttachFunction: (params: AddAttachParams) => Promise<void>;
111
- /**
112
- * @description Map of dependencies required by the reporter
113
- * @summary Stores the current state of dependencies
114
- * @type {SimpleDependencyMap}
115
- */
116
- private deps?;
117
- constructor(testCase?: string, basePath?: string);
118
- /**
119
- * @description Imports required helper functions
120
- * @summary Ensures all necessary dependencies are available and imports helper functions
121
- * @return {Promise<void>} Promise that resolves when helpers are imported
122
- */
123
- private importHelpers;
124
- /**
125
- * @description Reports a message to the test report
126
- * @summary Adds a formatted message to the test report with an optional title
127
- * @param {string} title - Title of the message
128
- * @param {string | object} message - Content of the message
129
- * @return {Promise<void>} Promise that resolves when the message is reported
130
- */
131
- reportMessage(title: string, message: string | object): Promise<void>;
132
- /**
133
- * @description Reports an attachment to the test report
134
- * @summary Adds a formatted message to the test report with an optional title
135
- * @param {string} title - Title of the message
136
- * @param {string | Buffer} attachment - Content of the message
137
- * @return {Promise<void>} Promise that resolves when the message is reported
138
- */
139
- reportAttachment(title: string, attachment: string | Buffer): Promise<void>;
140
- /**
141
- * @description Reports data with specified type
142
- * @summary Processes and stores data in the test report with formatting
143
- * @param {string} reference - Reference identifier for the data
144
- * @param {string | number | object} data - Data to be reported
145
- * @param {PayloadType} type - Type of the payload
146
- * @param {boolean} [trim=false] - Whether to trim the data
147
- * @return {Promise<void>} Promise that resolves when data is reported
148
- */
149
- protected report(reference: string, data: string | number | object | Buffer, type: PayloadType, trim?: boolean): Promise<void>;
150
- /**
151
- * @description Reports data with a specified type
152
- * @summary Wrapper method for reporting various types of data
153
- * @param {string} reference - Reference identifier for the data
154
- * @param {string | number | object} data - Data to be reported
155
- * @param {PayloadType} [type="json"] - Type of the payload
156
- * @param {boolean} [trim=false] - Whether to trim the data
157
- * @return {Promise<void>} Promise that resolves when data is reported
158
- */
159
- reportData(reference: string, data: string | number | object, type?: PayloadType, trim?: boolean): Promise<void>;
160
- /**
161
- * @description Reports a JSON object
162
- * @summary Convenience method for reporting JSON objects
163
- * @param {string} reference - Reference identifier for the object
164
- * @param {object} json - JSON object to be reported
165
- * @param {boolean} [trim=false] - Whether to trim the object
166
- * @return {Promise<void>} Promise that resolves when object is reported
167
- */
168
- reportObject(reference: string, json: object, trim?: boolean): Promise<void>;
169
- /**
170
- * @description Reports a table in markdown format
171
- * @summary Converts and stores a table definition in markdown format
172
- * @param {string} reference - Reference identifier for the table
173
- * @param {MdTableDefinition} tableDef - Table definition object
174
- * @return {Promise<void>} Promise that resolves when table is reported
175
- */
176
- reportTable(reference: string, tableDef: MdTableDefinition): Promise<void>;
177
- /**
178
- * @description Reports a graph using Chart.js
179
- * @summary Generates and stores a graph visualization
180
- * @param {string} reference - Reference identifier for the graph
181
- * @param {any} config - Chart.js configuration object
182
- * @return {Promise<void>} Promise that resolves when graph is reported
183
- */
184
- reportGraph(reference: string, config: any): Promise<void>;
185
- /**
186
- * @description Reports an image to the test report
187
- * @summary Stores an image buffer in the test report
188
- * @param {string} reference - Reference identifier for the image
189
- * @param {Buffer} buffer - Image data buffer
190
- * @return {Promise<void>} Promise that resolves when image is reported
191
- */
192
- reportImage(reference: string, buffer: Buffer): Promise<void>;
193
- }
1
+ export * from "../tests";