UNPKG

2.23 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.AllureRuntime = void 0;
4const crypto_1 = require("crypto");
5const AllureGroup_js_1 = require("./AllureGroup.js");
6const index_js_1 = require("./writers/index.js");
7const buildAttachmentFileName = (options) => {
8 if (typeof options === "string") {
9 options = { contentType: options };
10 }
11 const extension = (0, index_js_1.typeToExtension)(options);
12 return `${(0, crypto_1.randomUUID)()}-attachment${extension}`;
13};
14class AllureRuntime {
15 constructor(config) {
16 this.config = config;
17 this.writer = config.writer || new index_js_1.FileSystemAllureWriter(config);
18 }
19 startGroup(name) {
20 const allureContainer = new AllureGroup_js_1.AllureGroup(this);
21 allureContainer.name = name || "Unnamed";
22 return allureContainer;
23 }
24 writeResult(result) {
25 const modifiedResult = this.config.testMapper !== undefined ? this.config.testMapper(result) : result;
26 if (modifiedResult != null) {
27 this.writer.writeResult(modifiedResult);
28 }
29 }
30 writeGroup(result) {
31 this.writer.writeGroup(result);
32 }
33 writeAttachment(content, options, encoding) {
34 const fileName = buildAttachmentFileName(options);
35 this.writer.writeAttachment(fileName, content, encoding);
36 return fileName;
37 }
38 writeAttachmentFromPath(fromPath, options) {
39 const fileName = buildAttachmentFileName(options);
40 this.writer.writeAttachmentFromPath(fromPath, fileName);
41 return fileName;
42 }
43 writeEnvironmentInfo(info) {
44 this.writer.writeEnvironmentInfo(info || process.env);
45 }
46 writeCategoriesDefinitions(categories) {
47 const serializedCategories = categories.map((c) => {
48 if (c.messageRegex instanceof RegExp) {
49 c.messageRegex = c.messageRegex.source;
50 }
51 if (c.traceRegex instanceof RegExp) {
52 c.traceRegex = c.traceRegex.source;
53 }
54 return c;
55 });
56 this.writer.writeCategoriesDefinitions(serializedCategories);
57 }
58}
59exports.AllureRuntime = AllureRuntime;
60//# sourceMappingURL=AllureRuntime.js.map
\No newline at end of file