@testomatio/reporter 1.6.0-beta-1-artifacts → 2.0.0-beta-esm

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.
Files changed (97) hide show
  1. package/lib/adapter/codecept.js +288 -330
  2. package/lib/adapter/cucumber/current.js +195 -203
  3. package/lib/adapter/cucumber/legacy.js +130 -155
  4. package/lib/adapter/cucumber.js +5 -16
  5. package/lib/adapter/cypress-plugin/index.js +91 -105
  6. package/lib/adapter/jasmine/jasmine.js +63 -0
  7. package/lib/adapter/jasmine.js +54 -53
  8. package/lib/adapter/jest.js +97 -99
  9. package/lib/adapter/mocha/mocha.js +125 -0
  10. package/lib/adapter/mocha.js +111 -140
  11. package/lib/adapter/playwright.js +168 -200
  12. package/lib/adapter/vitest.js +144 -143
  13. package/lib/adapter/webdriver.js +113 -97
  14. package/lib/bin/reportXml.js +49 -49
  15. package/lib/bin/startTest.js +80 -97
  16. package/lib/client.js +344 -385
  17. package/lib/config.js +16 -21
  18. package/lib/constants.js +49 -43
  19. package/lib/data-storage.js +206 -188
  20. package/lib/fileUploader.js +245 -0
  21. package/lib/junit-adapter/adapter.js +17 -20
  22. package/lib/junit-adapter/csharp.js +18 -14
  23. package/lib/junit-adapter/index.js +27 -25
  24. package/lib/junit-adapter/java.js +41 -53
  25. package/lib/junit-adapter/javascript.js +30 -27
  26. package/lib/junit-adapter/python.js +38 -37
  27. package/lib/junit-adapter/ruby.js +11 -8
  28. package/lib/output.js +44 -52
  29. package/lib/package.json +1 -0
  30. package/lib/pipe/bitbucket.js +208 -227
  31. package/lib/pipe/csv.js +111 -124
  32. package/lib/pipe/github.js +184 -211
  33. package/lib/pipe/gitlab.js +164 -205
  34. package/lib/pipe/html.js +253 -312
  35. package/lib/pipe/index.js +83 -63
  36. package/lib/pipe/testomatio.js +391 -454
  37. package/lib/reporter-functions.js +16 -20
  38. package/lib/reporter.js +47 -17
  39. package/lib/services/artifacts.js +55 -51
  40. package/lib/services/index.js +14 -12
  41. package/lib/services/key-values.js +56 -53
  42. package/lib/services/logger.js +227 -245
  43. package/lib/utils/chalk.js +10 -0
  44. package/lib/utils/pipe_utils.js +91 -86
  45. package/lib/utils/utils.js +289 -273
  46. package/lib/xmlReader.js +480 -519
  47. package/package.json +57 -19
  48. package/src/adapter/codecept.js +369 -0
  49. package/src/adapter/cucumber/current.js +228 -0
  50. package/src/adapter/cucumber/legacy.js +158 -0
  51. package/src/adapter/cucumber.js +4 -0
  52. package/src/adapter/cypress-plugin/index.js +110 -0
  53. package/src/adapter/jasmine.js +60 -0
  54. package/src/adapter/jest.js +107 -0
  55. package/src/adapter/mocha.cjs +2 -0
  56. package/src/adapter/mocha.js +156 -0
  57. package/src/adapter/playwright.js +222 -0
  58. package/src/adapter/vitest.js +183 -0
  59. package/src/adapter/webdriver.js +111 -0
  60. package/src/bin/reportXml.js +67 -0
  61. package/src/bin/startTest.js +119 -0
  62. package/src/client.js +423 -0
  63. package/src/config.js +30 -0
  64. package/src/constants.js +49 -0
  65. package/src/data-storage.js +204 -0
  66. package/src/fileUploader.js +307 -0
  67. package/src/junit-adapter/adapter.js +23 -0
  68. package/src/junit-adapter/csharp.js +16 -0
  69. package/src/junit-adapter/index.js +28 -0
  70. package/src/junit-adapter/java.js +58 -0
  71. package/src/junit-adapter/javascript.js +31 -0
  72. package/src/junit-adapter/python.js +42 -0
  73. package/src/junit-adapter/ruby.js +10 -0
  74. package/src/output.js +57 -0
  75. package/src/pipe/bitbucket.js +254 -0
  76. package/src/pipe/csv.js +140 -0
  77. package/src/pipe/github.js +234 -0
  78. package/src/pipe/gitlab.js +229 -0
  79. package/src/pipe/html.js +366 -0
  80. package/src/pipe/index.js +73 -0
  81. package/src/pipe/testomatio.js +498 -0
  82. package/src/reporter-functions.js +44 -0
  83. package/src/reporter.cjs +22 -0
  84. package/src/reporter.js +24 -0
  85. package/src/services/artifacts.js +59 -0
  86. package/src/services/index.js +13 -0
  87. package/src/services/key-values.js +59 -0
  88. package/src/services/logger.js +314 -0
  89. package/src/template/emptyData.svg +23 -0
  90. package/src/template/testomatio.hbs +1421 -0
  91. package/src/utils/chalk.js +13 -0
  92. package/src/utils/pipe_utils.js +127 -0
  93. package/src/utils/utils.js +341 -0
  94. package/src/xmlReader.js +551 -0
  95. package/lib/bin/cli.js +0 -220
  96. package/lib/bin/uploadArtifacts.js +0 -91
  97. package/lib/uploader.js +0 -308
@@ -1,154 +1,125 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
1
6
  // eslint-disable-next-line global-require, import/no-extraneous-dependencies
2
- const Mocha = require('mocha');
3
- const chalk = require('chalk');
4
- const TestomatClient = require('../client');
5
- const { STATUS, TESTOMAT_TMP_STORAGE_DIR } = require('../constants');
6
- const { getTestomatIdFromTestTitle, fileSystem } = require('../utils/utils');
7
- const config = require('../config');
8
- const { services } = require('../services');
9
-
10
- const {
11
- EVENT_RUN_BEGIN,
12
- EVENT_RUN_END,
13
- EVENT_TEST_FAIL,
14
- EVENT_TEST_PASS,
15
- EVENT_TEST_PENDING,
16
- EVENT_SUITE_BEGIN,
17
- EVENT_SUITE_END,
18
- EVENT_TEST_BEGIN,
19
- EVENT_TEST_END,
20
- } = Mocha.Runner.constants;
21
-
7
+ const mocha_1 = __importDefault(require("mocha"));
8
+ const client_js_1 = __importDefault(require("../client.js"));
9
+ const constants_js_1 = require("../constants.js");
10
+ const utils_js_1 = require("../utils/utils.js");
11
+ const config_js_1 = require("../config.js");
12
+ const index_js_1 = require("../services/index.js");
13
+ const picocolors_1 = __importDefault(require("picocolors"));
14
+ const { EVENT_RUN_BEGIN, EVENT_RUN_END, EVENT_TEST_FAIL, EVENT_TEST_PASS, EVENT_TEST_PENDING, EVENT_SUITE_BEGIN, EVENT_SUITE_END, EVENT_TEST_BEGIN, EVENT_TEST_END, } = mocha_1.default.Runner.constants;
22
15
  function MochaReporter(runner, opts) {
23
- Mocha.reporters.Base.call(this, runner);
24
- let passes = 0;
25
- let failures = 0;
26
- let skipped = 0;
27
- // let artifactStore;
28
-
29
- const apiKey = opts?.reporterOptions?.apiKey || config.TESTOMATIO;
30
-
31
- const client = new TestomatClient({ apiKey });
32
-
33
- runner.on(EVENT_RUN_BEGIN, () => {
34
- client.createRun();
35
-
36
- fileSystem.clearDir(TESTOMAT_TMP_STORAGE_DIR);
37
- });
38
-
39
- runner.on(EVENT_SUITE_BEGIN, async suite => {
40
- services.setContext(suite.fullTitle());
41
- });
42
-
43
- runner.on(EVENT_SUITE_END, async () => {
44
- services.setContext(null);
45
- });
46
-
47
- runner.on(EVENT_TEST_BEGIN, async test => {
48
- services.setContext(test.fullTitle());
49
- });
50
-
51
- runner.on(EVENT_TEST_END, async () => {
52
- services.setContext(null);
53
- });
54
-
55
- runner.on(EVENT_TEST_PASS, async test => {
56
- passes += 1;
57
-
58
- console.log(chalk.bold.green('✔'), test.fullTitle());
59
- const testId = getTestomatIdFromTestTitle(test.title);
60
-
61
- const logs = getTestLogs(test);
62
- const artifacts = services.artifacts.get(test.fullTitle());
63
- const keyValues = services.keyValues.get(test.fullTitle());
64
-
65
- client.addTestRun(STATUS.PASSED, {
66
- test_id: testId,
67
- suite_title: getSuiteTitle(test),
68
- title: getTestName(test),
69
- code: test.body.toString(),
70
- file: getFile(test),
71
- time: test.duration,
72
- logs,
73
- manuallyAttachedArtifacts: artifacts,
74
- meta: keyValues,
16
+ mocha_1.default.reporters.Base.call(this, runner);
17
+ let passes = 0;
18
+ let failures = 0;
19
+ let skipped = 0;
20
+ // let artifactStore;
21
+ const apiKey = opts?.reporterOptions?.apiKey || config_js_1.config.TESTOMATIO;
22
+ const client = new client_js_1.default({ apiKey });
23
+ runner.on(EVENT_RUN_BEGIN, () => {
24
+ client.createRun();
25
+ utils_js_1.fileSystem.clearDir(constants_js_1.TESTOMAT_TMP_STORAGE_DIR);
75
26
  });
76
- });
77
-
78
- runner.on(EVENT_TEST_PENDING, test => {
79
- skipped += 1;
80
- console.log('skip: %s', test.fullTitle());
81
- const testId = getTestomatIdFromTestTitle(test.title);
82
- client.addTestRun(STATUS.SKIPPED, {
83
- title: getTestName(test),
84
- suite_title: getSuiteTitle(test),
85
- code: test.body.toString(),
86
- file: getFile(test),
87
- test_id: testId,
88
- time: test.duration,
27
+ runner.on(EVENT_SUITE_BEGIN, async (suite) => {
28
+ index_js_1.services.setContext(suite.fullTitle());
89
29
  });
90
- });
91
-
92
- runner.on(EVENT_TEST_FAIL, async (test, err) => {
93
- failures += 1;
94
- console.log(chalk.bold.red('✖'), test.fullTitle(), chalk.gray(err.message));
95
- const testId = getTestomatIdFromTestTitle(test.title);
96
-
97
- const logs = getTestLogs(test);
98
-
99
- client.addTestRun(STATUS.FAILED, {
100
- error: err,
101
- suite_title: getSuiteTitle(test),
102
- file: getFile(test),
103
- test_id: testId,
104
- title: getTestName(test),
105
- code: test.body.toString(),
106
- time: test.duration,
107
- logs,
30
+ runner.on(EVENT_SUITE_END, async () => {
31
+ index_js_1.services.setContext(null);
32
+ });
33
+ runner.on(EVENT_TEST_BEGIN, async (test) => {
34
+ index_js_1.services.setContext(test.fullTitle());
35
+ });
36
+ runner.on(EVENT_TEST_END, async () => {
37
+ index_js_1.services.setContext(null);
38
+ });
39
+ runner.on(EVENT_TEST_PASS, async (test) => {
40
+ passes += 1;
41
+ console.log(picocolors_1.default.bold(picocolors_1.default.green('✔')), test.fullTitle());
42
+ const testId = (0, utils_js_1.getTestomatIdFromTestTitle)(test.title);
43
+ const logs = getTestLogs(test);
44
+ const artifacts = index_js_1.services.artifacts.get(test.fullTitle());
45
+ const keyValues = index_js_1.services.keyValues.get(test.fullTitle());
46
+ client.addTestRun(constants_js_1.STATUS.PASSED, {
47
+ test_id: testId,
48
+ suite_title: getSuiteTitle(test),
49
+ title: getTestName(test),
50
+ code: test.body.toString(),
51
+ file: getFile(test),
52
+ time: test.duration,
53
+ logs,
54
+ manuallyAttachedArtifacts: artifacts,
55
+ meta: keyValues,
56
+ });
57
+ });
58
+ runner.on(EVENT_TEST_PENDING, test => {
59
+ skipped += 1;
60
+ console.log('skip: %s', test.fullTitle());
61
+ const testId = (0, utils_js_1.getTestomatIdFromTestTitle)(test.title);
62
+ client.addTestRun(constants_js_1.STATUS.SKIPPED, {
63
+ title: getTestName(test),
64
+ suite_title: getSuiteTitle(test),
65
+ code: test.body.toString(),
66
+ file: getFile(test),
67
+ test_id: testId,
68
+ time: test.duration,
69
+ });
70
+ });
71
+ runner.on(EVENT_TEST_FAIL, async (test, err) => {
72
+ failures += 1;
73
+ console.log(picocolors_1.default.bold(picocolors_1.default.red('✖')), test.fullTitle(), picocolors_1.default.gray(err.message));
74
+ const testId = (0, utils_js_1.getTestomatIdFromTestTitle)(test.title);
75
+ const logs = getTestLogs(test);
76
+ client.addTestRun(constants_js_1.STATUS.FAILED, {
77
+ error: err,
78
+ suite_title: getSuiteTitle(test),
79
+ file: getFile(test),
80
+ test_id: testId,
81
+ title: getTestName(test),
82
+ code: test.body.toString(),
83
+ time: test.duration,
84
+ logs,
85
+ });
86
+ });
87
+ runner.on(EVENT_RUN_END, () => {
88
+ const status = failures === 0 ? constants_js_1.STATUS.PASSED : constants_js_1.STATUS.FAILED;
89
+ console.log(picocolors_1.default.bold(status), `${passes} passed, ${failures} failed, ${skipped} skipped`);
90
+ // @ts-ignore
91
+ client.updateRunStatus(status);
108
92
  });
109
- });
110
-
111
- runner.on(EVENT_RUN_END, () => {
112
- const status = failures === 0 ? STATUS.PASSED : STATUS.FAILED;
113
- console.log(chalk.bold(status), `${passes} passed, ${failures} failed, ${skipped} skipped`);
114
- client.updateRunStatus(status);
115
- });
116
93
  }
117
-
118
94
  function getTestLogs(test) {
119
- const suiteLogsArr = services.logger.getLogs(test.parent.fullTitle());
120
- const suiteLogs = suiteLogsArr ? suiteLogsArr.join('\n').trim() : '';
121
- const testLogsArr = services.logger.getLogs(test.fullTitle());
122
- const testLogs = testLogsArr ? testLogsArr.join('\n').trim() : '';
123
-
124
- let logs = '';
125
- if (suiteLogs) {
126
- logs += `${chalk.bold('\t--- BeforeSuite ---')}\n${suiteLogs}`;
127
- }
128
- if (testLogs) {
129
- logs += `\n${chalk.bold('\t--- Test ---')}\n${testLogs}`;
130
- }
131
- return logs;
95
+ const suiteLogsArr = index_js_1.services.logger.getLogs(test.parent.fullTitle());
96
+ const suiteLogs = suiteLogsArr ? suiteLogsArr.join('\n').trim() : '';
97
+ const testLogsArr = index_js_1.services.logger.getLogs(test.fullTitle());
98
+ const testLogs = testLogsArr ? testLogsArr.join('\n').trim() : '';
99
+ let logs = '';
100
+ if (suiteLogs) {
101
+ logs += `${picocolors_1.default.bold('\t--- BeforeSuite ---')}\n${suiteLogs}`;
102
+ }
103
+ if (testLogs) {
104
+ logs += `\n${picocolors_1.default.bold('\t--- Test ---')}\n${testLogs}`;
105
+ }
106
+ return logs;
132
107
  }
133
-
134
- // To have this reporter "extend" a built-in reporter uncomment the following line:
135
- Mocha.utils.inherits(MochaReporter, Mocha.reporters.Spec);
136
-
137
- module.exports = MochaReporter;
138
-
139
108
  function getSuiteTitle(test, pathArr = []) {
140
- if (test.parent.parent) getSuiteTitle(test.parent, pathArr);
141
-
142
- pathArr.push(test.parent.title);
143
-
144
- return pathArr.filter(t => !!t)[0];
109
+ if (test.parent.parent)
110
+ getSuiteTitle(test.parent, pathArr);
111
+ pathArr.push(test.parent.title);
112
+ return pathArr.filter(t => !!t)[0];
145
113
  }
146
-
147
114
  function getFile(test) {
148
- return test.parent.file?.replace(process.cwd(), '');
115
+ return test.parent.file?.replace(process.cwd(), '');
149
116
  }
150
-
151
117
  function getTestName(test) {
152
- if (process.env.TESTOMATIO_CREATE === 'fulltitle') return test.fullTitle();
153
- return test.title;
118
+ if (process.env.TESTOMATIO_CREATE === 'fulltitle')
119
+ return test.fullTitle();
120
+ return test.title;
154
121
  }
122
+ // To have this reporter "extend" a built-in reporter uncomment the following line:
123
+ // @ts-ignore
124
+ mocha_1.default.utils.inherits(MochaReporter, mocha_1.default.reporters.Spec);
125
+ module.exports = MochaReporter;
@@ -1,226 +1,194 @@
1
- const chalk = require('chalk');
2
- const crypto = require('crypto');
3
- const os = require('os');
4
- const path = require('path');
5
- const { v4: uuidv4 } = require('uuid');
6
- const fs = require('fs');
7
- const { APP_PREFIX, STATUS: Status, TESTOMAT_TMP_STORAGE_DIR } = require('../constants');
8
- const TestomatioClient = require('../client');
9
- const { getTestomatIdFromTestTitle, fileSystem } = require('../utils/utils');
10
- // const debug = require('debug')('@testomatio/reporter:adapter:playwright');
11
- const { services } = require('../services');
12
- const { dataStorage } = require('../data-storage');
13
-
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.initPlaywrightForStorage = initPlaywrightForStorage;
7
+ const picocolors_1 = __importDefault(require("picocolors"));
8
+ const crypto_1 = __importDefault(require("crypto"));
9
+ const os_1 = __importDefault(require("os"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const uuid_1 = require("uuid");
12
+ const fs_1 = __importDefault(require("fs"));
13
+ const constants_js_1 = require("../constants.js");
14
+ const client_js_1 = __importDefault(require("../client.js"));
15
+ const fileUploader_js_1 = require("../fileUploader.js");
16
+ const utils_js_1 = require("../utils/utils.js");
17
+ const index_js_1 = require("../services/index.js");
18
+ const data_storage_js_1 = require("../data-storage.js");
14
19
  const reportTestPromises = [];
15
-
16
20
  class PlaywrightReporter {
17
- constructor(config = {}) {
18
- this.client = new TestomatioClient({ apiKey: config?.apiKey });
19
-
20
- this.uploads = [];
21
- }
22
-
23
- onBegin(config, suite) {
24
- // clean data storage
25
- fileSystem.clearDir(TESTOMAT_TMP_STORAGE_DIR);
26
- if (!this.client) return;
27
- this.suite = suite;
28
- this.config = config;
29
- this.client.createRun();
30
- }
31
-
32
- onTestBegin(testInfo) {
33
- const fullTestTitle = getTestContextName(testInfo);
34
- dataStorage.setContext(fullTestTitle);
35
- }
36
-
37
- onTestEnd(test, result) {
38
- if (!this.client) return;
39
-
40
- const { title } = test;
41
- const { error, duration } = result;
42
- const suite_title = test.parent ? test.parent?.title : path.basename(test?.location?.file);
43
-
44
- const steps = [];
45
- for (const step of result.steps) {
46
- const appendedStep = appendStep(step);
47
- if (appendedStep) {
48
- steps.push(appendedStep);
49
- }
21
+ constructor(config = {}) {
22
+ this.client = new client_js_1.default({ apiKey: config?.apiKey });
23
+ this.uploads = [];
50
24
  }
51
-
52
- const fullTestTitle = getTestContextName(test);
53
- let logs = '';
54
- if (result.stderr.length || result.stdout.length) {
55
- logs = `\n\n${chalk.bold('Logs:')}\n${chalk.red(result.stderr.join(''))}\n${result.stdout.join('')}`;
25
+ onBegin(config, suite) {
26
+ // clean data storage
27
+ utils_js_1.fileSystem.clearDir(constants_js_1.TESTOMAT_TMP_STORAGE_DIR);
28
+ if (!this.client)
29
+ return;
30
+ this.suite = suite;
31
+ this.config = config;
32
+ this.client.createRun();
56
33
  }
57
- const manuallyAttachedArtifacts = services.artifacts.get(fullTestTitle);
58
- const keyValues = services.keyValues.get(fullTestTitle);
59
- const rid = test.id || test.testId || uuidv4();
60
-
61
- const reportTestPromise = this.client.addTestRun(checkStatus(result.status), {
62
- rid,
63
- error,
64
- test_id: getTestomatIdFromTestTitle(`${title} ${test.tags?.join(' ')}`),
65
- suite_title,
66
- title,
67
- steps: steps.length ? steps : undefined,
68
- time: duration,
69
- logs,
70
- manuallyAttachedArtifacts,
71
- meta: keyValues,
72
- file: test.location?.file,
73
- });
74
-
75
- this.uploads.push({
76
- rid,
77
- title: test.title,
78
- files: result.attachments.filter(a => a.body || a.path),
79
- file: test.location?.file,
80
- });
81
- // remove empty uploads
82
- this.uploads = this.uploads.filter(upload => upload.files.length);
83
-
84
- reportTestPromises.push(reportTestPromise);
85
- }
86
-
87
- #getArtifactPath(artifact) {
88
- if (artifact.path) {
89
- if (path.isAbsolute(artifact.path)) return artifact.path;
90
-
91
- return path.join(this.config.outputDir || this.config.projects[0].outputDir, artifact.path);
34
+ onTestBegin(testInfo) {
35
+ const fullTestTitle = getTestContextName(testInfo);
36
+ data_storage_js_1.dataStorage.setContext(fullTestTitle);
92
37
  }
93
-
94
- if (artifact.body) {
95
- const fileName = tmpFile();
96
- fs.writeFileSync(fileName, artifact.body);
97
- return fileName;
38
+ onTestEnd(test, result) {
39
+ // test.parent.project().__projectId
40
+ if (!this.client)
41
+ return;
42
+ const { title } = test;
43
+ const { error, duration } = result;
44
+ const suite_title = test.parent ? test.parent?.title : path_1.default.basename(test?.location?.file);
45
+ const steps = [];
46
+ for (const step of result.steps) {
47
+ const appendedStep = appendStep(step);
48
+ if (appendedStep) {
49
+ steps.push(appendedStep);
50
+ }
51
+ }
52
+ const fullTestTitle = getTestContextName(test);
53
+ let logs = '';
54
+ if (result.stderr.length || result.stdout.length) {
55
+ logs = `\n\n${picocolors_1.default.bold('Logs:')}\n${picocolors_1.default.red(result.stderr.join(''))}\n${result.stdout.join('')}`;
56
+ }
57
+ const manuallyAttachedArtifacts = index_js_1.services.artifacts.get(fullTestTitle);
58
+ const keyValues = index_js_1.services.keyValues.get(fullTestTitle);
59
+ const rid = test.id || test.testId || (0, uuid_1.v4)();
60
+ const reportTestPromise = this.client.addTestRun(checkStatus(result.status), {
61
+ rid,
62
+ error,
63
+ test_id: (0, utils_js_1.getTestomatIdFromTestTitle)(`${title} ${test.tags?.join(' ')}`),
64
+ suite_title,
65
+ title,
66
+ steps: steps.length ? steps : undefined,
67
+ time: duration,
68
+ logs,
69
+ manuallyAttachedArtifacts,
70
+ meta: keyValues,
71
+ file: test.location?.file,
72
+ });
73
+ this.uploads.push({
74
+ rid,
75
+ title: test.title,
76
+ files: result.attachments.filter(a => a.body || a.path),
77
+ file: test.location?.file,
78
+ });
79
+ // remove empty uploads
80
+ this.uploads = this.uploads.filter(anUpload => anUpload.files.length);
81
+ reportTestPromises.push(reportTestPromise);
98
82
  }
99
-
100
- return null;
101
- }
102
-
103
- async onEnd(result) {
104
- if (!this.client) return;
105
-
106
- await Promise.all(reportTestPromises);
107
-
108
- if (!this.uploads.length) return;
109
-
110
- if (this.client.uploader.isEnabled) console.log(APP_PREFIX, `🎞️ Uploading ${this.uploads.length} files...`);
111
-
112
- const promises = [];
113
-
114
- for (const upload of this.uploads) {
115
- const { rid, file, title } = upload;
116
-
117
- const files = upload.files.map(attachment => ({
118
- path: this.#getArtifactPath(attachment),
119
- title,
120
- type: attachment.contentType,
121
- }));
122
-
123
- if (!this.client.uploader.isEnabled) {
124
- files.forEach(f => this.client.uploader.storeUploadedFile(f, this.client.runId, rid, false));
125
- continue;
126
- }
127
-
128
- promises.push(
129
- this.client.addTestRun(undefined, {
130
- rid,
131
- title,
132
- files,
133
- file,
134
- }),
135
- );
83
+ #getArtifactPath(artifact) {
84
+ if (artifact.path) {
85
+ if (path_1.default.isAbsolute(artifact.path))
86
+ return artifact.path;
87
+ return path_1.default.join(this.config.outputDir || this.config.projects[0].outputDir, artifact.path);
88
+ }
89
+ if (artifact.body) {
90
+ const fileName = tmpFile();
91
+ fs_1.default.writeFileSync(fileName, artifact.body);
92
+ return fileName;
93
+ }
94
+ return null;
95
+ }
96
+ async onEnd(result) {
97
+ if (!this.client)
98
+ return;
99
+ await Promise.all(reportTestPromises);
100
+ if (this.uploads.length && fileUploader_js_1.upload.isArtifactsEnabled()) {
101
+ console.log(constants_js_1.APP_PREFIX, `🎞️ Uploading ${this.uploads.length} files...`);
102
+ const promises = [];
103
+ for (const anUpload of this.uploads) {
104
+ const { rid, file, title } = anUpload;
105
+ const files = anUpload.files.map(attachment => ({
106
+ path: this.#getArtifactPath(attachment),
107
+ title,
108
+ type: attachment.contentType,
109
+ }));
110
+ promises.push(this.client.addTestRun(undefined, {
111
+ rid,
112
+ title,
113
+ files,
114
+ file,
115
+ }));
116
+ }
117
+ await Promise.all(promises);
118
+ }
119
+ await this.client.updateRunStatus(checkStatus(result.status));
136
120
  }
137
- await Promise.all(promises);
138
-
139
-
140
- await this.client.updateRunStatus(checkStatus(result.status));
141
- }
142
121
  }
143
-
144
122
  function checkStatus(status) {
145
- return (
146
- {
147
- skipped: Status.SKIPPED,
148
- timedOut: Status.FAILED,
149
- passed: Status.PASSED,
150
- }[status] || Status.FAILED
151
- );
123
+ return ({
124
+ skipped: constants_js_1.STATUS.SKIPPED,
125
+ timedOut: constants_js_1.STATUS.FAILED,
126
+ passed: constants_js_1.STATUS.PASSED,
127
+ }[status] || constants_js_1.STATUS.FAILED);
152
128
  }
153
-
154
129
  function appendStep(step, shift = 0) {
155
- // nesting too deep, ignore those steps
156
- if (shift >= 10) return;
157
-
158
- let newCategory = step.category;
159
- switch (newCategory) {
160
- case 'test.step':
161
- newCategory = 'user';
162
- break;
163
- case 'hook':
164
- newCategory = 'hook';
165
- break;
166
- case 'attach':
167
- return null; // Skip steps with category 'attach'
168
- default:
169
- newCategory = 'framework';
170
- }
171
-
172
- const formattedSteps = [];
173
- for (const child of step.steps || []) {
174
- const appendedChild = appendStep(child, shift + 2);
175
- if (appendedChild) {
176
- formattedSteps.push(appendedChild);
130
+ // nesting too deep, ignore those steps
131
+ if (shift >= 10)
132
+ return;
133
+ let newCategory = step.category;
134
+ switch (newCategory) {
135
+ case 'test.step':
136
+ newCategory = 'user';
137
+ break;
138
+ case 'hook':
139
+ newCategory = 'hook';
140
+ break;
141
+ case 'attach':
142
+ return null; // Skip steps with category 'attach'
143
+ default:
144
+ newCategory = 'framework';
177
145
  }
178
- }
179
-
180
- const resultStep = {
181
- category: newCategory,
182
- title: step.title,
183
- duration: step.duration,
184
- };
185
-
186
- if (formattedSteps.length) {
187
- resultStep.steps = formattedSteps.filter(s => !!s);
188
- }
189
-
190
- if (step.error !== undefined) {
191
- resultStep.error = step.error;
192
- }
193
-
194
- return resultStep;
146
+ const formattedSteps = [];
147
+ for (const child of step.steps || []) {
148
+ const appendedChild = appendStep(child, shift + 2);
149
+ if (appendedChild) {
150
+ formattedSteps.push(appendedChild);
151
+ }
152
+ }
153
+ const resultStep = {
154
+ category: newCategory,
155
+ title: step.title,
156
+ duration: step.duration,
157
+ };
158
+ if (formattedSteps.length) {
159
+ resultStep.steps = formattedSteps.filter(s => !!s);
160
+ }
161
+ if (step.error !== undefined) {
162
+ resultStep.error = step.error;
163
+ }
164
+ return resultStep;
195
165
  }
196
-
197
166
  function tmpFile(prefix = 'tmp.') {
198
- const tmpdir = os.tmpdir();
199
- return path.join(tmpdir, prefix + crypto.randomBytes(16).toString('hex'));
167
+ const tmpdir = os_1.default.tmpdir();
168
+ return path_1.default.join(tmpdir, prefix + crypto_1.default.randomBytes(16).toString('hex'));
200
169
  }
201
-
202
170
  /**
203
171
  * Returns filename + test title
204
172
  * @param {*} test - testInfo object from Playwright
205
173
  * @returns
206
174
  */
207
175
  function getTestContextName(test) {
208
- return `${test._requireFile || ''}_${test.title}`;
176
+ return `${test._requireFile || ''}_${test.title}`;
209
177
  }
210
-
211
178
  function initPlaywrightForStorage() {
212
- try {
213
- // @ts-ignore-next-line
214
- // eslint-disable-next-line import/no-unresolved
215
- const { test } = require('@playwright/test');
216
- // eslint-disable-next-line no-empty-pattern
217
- test.beforeEach(async ({}, testInfo) => {
218
- global.testomatioTestTitle = `${testInfo.file || ''}_${testInfo.title}`;
219
- });
220
- } catch (e) {
221
- // ignore
222
- }
179
+ try {
180
+ // @ts-ignore-next-line
181
+ // eslint-disable-next-line import/no-extraneous-dependencies
182
+ const { test } = require('@playwright/test');
183
+ // eslint-disable-next-line no-empty-pattern
184
+ test.beforeEach(async ({}, testInfo) => {
185
+ global.testomatioTestTitle = `${testInfo.file || ''}_${testInfo.title}`;
186
+ });
187
+ }
188
+ catch (e) {
189
+ // ignore
190
+ }
223
191
  }
224
-
225
192
  module.exports = PlaywrightReporter;
193
+
226
194
  module.exports.initPlaywrightForStorage = initPlaywrightForStorage;