testbeats 2.1.7 → 2.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testbeats",
3
- "version": "2.1.7",
3
+ "version": "2.2.1",
4
4
  "description": "Publish test results to Microsoft Teams, Google Chat, Slack and InfluxDB",
5
5
  "main": "src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -8,6 +8,7 @@ const { ConfigBuilder } = require('../utils/config.builder');
8
8
  const target_manager = require('../targets');
9
9
  const logger = require('../utils/logger');
10
10
  const { processData } = require('../helpers/helper');
11
+ const { ExtensionsSetup } = require('../setups/extensions.setup');
11
12
  const pkg = require('../../package.json');
12
13
  const { MIN_NODE_VERSION } = require('../helpers/constants');
13
14
 
@@ -32,6 +33,7 @@ class PublishCommand {
32
33
  this.#processConfig();
33
34
  this.#validateConfig();
34
35
  this.#processResults();
36
+ await this.#setupExtensions();
35
37
  await this.#publishResults();
36
38
  await this.#publishErrors();
37
39
  }
@@ -209,6 +211,19 @@ class PublishCommand {
209
211
  }
210
212
  }
211
213
 
214
+ async #setupExtensions() {
215
+ logger.info('⚙️ Setting up extensions...');
216
+ try {
217
+ for (const config of this.configs) {
218
+ const extensions = config.extensions || [];
219
+ const setup = new ExtensionsSetup(extensions, this.results ? this.results[0] : null);
220
+ await setup.run();
221
+ }
222
+ } catch (error) {
223
+ logger.error(`❌ Error setting up extensions: ${error.message}`);
224
+ }
225
+ }
226
+
212
227
  async #publishResults() {
213
228
  if (!this.results.length) {
214
229
  logger.warn('⚠️ No results to publish');
@@ -1,3 +1,4 @@
1
+ const TestResult = require('test-results-parser/src/models/TestResult');
1
2
  const logger = require('../utils/logger');
2
3
  const { addChatExtension, addSlackExtension, addTeamsExtension } = require('../helpers/extension.helper');
3
4
 
@@ -7,13 +8,15 @@ class BaseExtension {
7
8
  *
8
9
  * @param {import('..').ITarget} target
9
10
  * @param {import('..').IExtension} extension
10
- * @param {import('..').TestResult} result
11
+ * @param {TestResult} result
11
12
  * @param {any} payload
12
13
  * @param {any} root_payload
13
14
  */
14
15
  constructor(target, extension, result, payload, root_payload) {
15
16
  this.target = target;
16
17
  this.extension = extension;
18
+
19
+ /** @type {TestResult} */
17
20
  this.result = result;
18
21
  this.payload = payload;
19
22
  this.root_payload = root_payload;
@@ -0,0 +1,30 @@
1
+ const { HOOK, STATUS } = require("../helpers/constants");
2
+ const { getMetaDataText } = require("../helpers/metadata.helper");
3
+ const { BaseExtension } = require("./base.extension");
4
+
5
+
6
+ class BrowserstackExtension extends BaseExtension {
7
+ constructor(target, extension, result, payload, root_payload) {
8
+ super(target, extension, result, payload, root_payload);
9
+ this.#setDefaultOptions();
10
+ }
11
+
12
+ #setDefaultOptions() {
13
+ this.default_options.hook = HOOK.AFTER_SUMMARY;
14
+ this.default_options.condition = STATUS.PASS_OR_FAIL;
15
+ }
16
+
17
+ async run() {
18
+ this.extension.inputs = Object.assign({}, this.extension.inputs);
19
+ /** @type {import('../index').BrowserstackInputs} */
20
+ const inputs = this.extension.inputs;
21
+ if (inputs.automation_build) {
22
+ const element = { label: 'Browserstack', key: inputs.automation_build.name, value: inputs.automation_build.public_url, type: 'hyperlink' }
23
+ const text = await getMetaDataText({ elements: [element], target: this.target, extension: this.extension, result: this.result, default_condition: this.default_options.condition });
24
+ this.text = text;
25
+ this.attach();
26
+ }
27
+ }
28
+ }
29
+
30
+ module.exports = { BrowserstackExtension };
@@ -14,6 +14,7 @@ const { checkCondition } = require('../helpers/helper');
14
14
  const logger = require('../utils/logger');
15
15
  const { ErrorClustersExtension } = require('./error-clusters.extension');
16
16
  const { FailureAnalysisExtension } = require('./failure-analysis.extension');
17
+ const { BrowserstackExtension } = require('./browserstack.extension');
17
18
 
18
19
  async function run(options) {
19
20
  const { target, result, hook } = options;
@@ -72,6 +73,8 @@ function getExtensionRunner(extension, options) {
72
73
  return new SmartAnalysisExtension(options.target, extension, options.result, options.payload, options.root_payload);
73
74
  case EXTENSION.ERROR_CLUSTERS:
74
75
  return new ErrorClustersExtension(options.target, extension, options.result, options.payload, options.root_payload);
76
+ case EXTENSION.BROWSERSTACK:
77
+ return new BrowserstackExtension(options.target, extension, options.result, options.payload, options.root_payload);
75
78
  default:
76
79
  return require(extension.name);
77
80
  }
@@ -0,0 +1,45 @@
1
+ const request = require('phin-retry');
2
+ const { URLS } = require('./constants');
3
+
4
+
5
+ /**
6
+ *
7
+ * @param {import('../index').BrowserstackInputs} inputs
8
+ */
9
+ function getBaseUrl(inputs) {
10
+ return inputs.url || URLS.BROWSERSTACK;
11
+ }
12
+
13
+ /**
14
+ *
15
+ * @param {import('../index').BrowserstackInputs} inputs
16
+ */
17
+ async function getAutomationBuilds(inputs) {
18
+ return request.get({
19
+ url: `${getBaseUrl(inputs)}/automate/builds.json?limit=100`,
20
+ auth: {
21
+ username: inputs.username,
22
+ password: inputs.password
23
+ },
24
+ });
25
+ }
26
+
27
+ /**
28
+ *
29
+ * @param {import('../index').BrowserstackInputs} inputs
30
+ * @param {string} build_id
31
+ */
32
+ async function getAutomationBuildSessions(inputs, build_id) {
33
+ return request.get({
34
+ url: `${getBaseUrl(inputs)}/automate/builds/${build_id}/sessions.json`,
35
+ auth: {
36
+ username: inputs.username,
37
+ password: inputs.password
38
+ },
39
+ });
40
+ }
41
+
42
+ module.exports = {
43
+ getAutomationBuilds,
44
+ getAutomationBuildSessions
45
+ }
@@ -1,37 +1,37 @@
1
+ const { BaseCI } = require('./base.ci');
2
+
1
3
  const ENV = process.env;
2
4
 
3
- /**
4
- * @returns {import('../../extensions/extensions').ICIInfo}
5
- */
6
- function info() {
7
- const azure_devops = {
8
- ci: 'AZURE_DEVOPS_PIPELINES',
9
- git: 'AZURE_DEVOPS_REPOS',
10
- repository_url: ENV.BUILD_REPOSITORY_URI,
11
- repository_name: ENV.BUILD_REPOSITORY_NAME,
12
- repository_ref: ENV.BUILD_SOURCEBRANCH,
13
- repository_commit_sha: ENV.BUILD_SOURCEVERSION,
14
- branch_url: '',
15
- branch_name: '',
16
- pull_request_url:'',
17
- pull_request_name: '',
18
- build_url: ENV.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI + ENV.SYSTEM_TEAMPROJECT + '/_build/results?buildId=' + ENV.BUILD_BUILDID,
19
- build_number: ENV.BUILD_BUILDNUMBER,
20
- build_name: ENV.BUILD_DEFINITIONNAME,
21
- build_reason: ENV.BUILD_REASON,
22
- user: ENV.BUILD_REQUESTEDFOR
5
+ class AzureDevOpsCI extends BaseCI {
6
+ constructor() {
7
+ super();
8
+ this.init();
23
9
  }
24
10
 
25
- azure_devops.branch_url = azure_devops.repository_url + azure_devops.repository_ref.replace('refs/heads/', '/tree/');
26
- azure_devops.branch_name = azure_devops.repository_ref.replace('refs/heads/', '');
11
+ init() {
12
+ this.setInfo(this.targets.ci, 'AZURE_DEVOPS_PIPELINES');
13
+ this.setInfo(this.targets.git, 'AZURE_DEVOPS_REPOS');
14
+ this.setInfo(this.targets.repository_url, ENV.BUILD_REPOSITORY_URI);
15
+ this.setInfo(this.targets.repository_name, ENV.BUILD_REPOSITORY_NAME);
16
+ this.setInfo(this.targets.repository_ref, ENV.BUILD_SOURCEBRANCH);
17
+ this.setInfo(this.targets.repository_commit_sha, ENV.BUILD_SOURCEVERSION);
18
+ this.setInfo(this.targets.build_url, ENV.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI + ENV.SYSTEM_TEAMPROJECT + '/_build/results?buildId=' + ENV.BUILD_BUILDID);
19
+ this.setInfo(this.targets.build_number, ENV.BUILD_BUILDNUMBER);
20
+ this.setInfo(this.targets.build_name, ENV.BUILD_DEFINITIONNAME);
21
+ this.setInfo(this.targets.build_reason, ENV.BUILD_REASON);
22
+
23
+ this.setInfo(this.targets.branch_url, this.repository_url + this.repository_ref.replace('refs/heads/', '/tree/'));
24
+ this.setInfo(this.targets.branch_name, this.repository_ref.replace('refs/heads/', ''));
25
+
26
+ if (this.repository_ref.includes('refs/pull')) {
27
+ this.setInfo(this.targets.pull_request_url, this.repository_url + this.repository_ref.replace('refs/pull/', '/pull/'));
28
+ this.setInfo(this.targets.pull_request_name, this.repository_ref.replace('refs/pull/', '').replace('/merge', ''));
29
+ }
27
30
 
28
- if (azure_devops.repository_ref.includes('refs/pull')) {
29
- azure_devops.pull_request_url = azure_devops.repository_url + azure_devops.repository_ref.replace('refs/pull/', '/pull/');
30
- azure_devops.pull_request_name = azure_devops.repository_ref.replace('refs/pull/', '').replace('/merge', '');
31
+ this.setInfo(this.targets.user, ENV.BUILD_REQUESTEDFOR, true);
31
32
  }
32
- return azure_devops;
33
33
  }
34
34
 
35
35
  module.exports = {
36
- info
36
+ AzureDevOpsCI
37
37
  }
@@ -0,0 +1,134 @@
1
+ const os = require('os');
2
+ const pkg = require('../../../package.json');
3
+
4
+ const ENV = process.env;
5
+
6
+ class BaseCI {
7
+ ci = '';
8
+ git = '';
9
+ repository_url = '';
10
+ repository_name = '';
11
+ repository_ref = '';
12
+ repository_commit_sha = '';
13
+ branch_url = '';
14
+ branch_name = '';
15
+ pull_request_url = '';
16
+ pull_request_name = '';
17
+ build_url = '';
18
+ build_number = '';
19
+ build_name = '';
20
+ build_reason = '';
21
+ user = '';
22
+ runtime = '';
23
+ runtime_version = '';
24
+ os = '';
25
+ os_version = '';
26
+ testbeats_version = '';
27
+
28
+ targets = {
29
+ ci: 'ci',
30
+ git: 'git',
31
+ repository_url: 'repository_url',
32
+ repository_name: 'repository_name',
33
+ repository_ref: 'repository_ref',
34
+ repository_commit_sha: 'repository_commit_sha',
35
+ branch_url: 'branch_url',
36
+ branch_name: 'branch_name',
37
+ pull_request_url: 'pull_request_url',
38
+ pull_request_name: 'pull_request_name',
39
+ build_url: 'build_url',
40
+ build_number: 'build_number',
41
+ build_name: 'build_name',
42
+ build_reason: 'build_reason',
43
+ user: 'user',
44
+ runtime: 'runtime',
45
+ runtime_version: 'runtime_version',
46
+ os: 'os',
47
+ os_version: 'os_version',
48
+ testbeats_version: 'testbeats_version'
49
+ }
50
+
51
+ constructor() {
52
+ this.setDefaultInformation();
53
+ }
54
+
55
+ setDefaultInformation() {
56
+ this.ci = ENV.TEST_BEATS_CI_NAME;
57
+ this.git = ENV.TEST_BEATS_CI_GIT;
58
+ this.repository_url = ENV.TEST_BEATS_CI_REPOSITORY_URL;
59
+ this.repository_name = ENV.TEST_BEATS_CI_REPOSITORY_NAME;
60
+ this.repository_ref = ENV.TEST_BEATS_CI_REPOSITORY_REF;
61
+ this.repository_commit_sha = ENV.TEST_BEATS_CI_REPOSITORY_COMMIT_SHA;
62
+ this.branch_url = ENV.TEST_BEATS_BRANCH_URL;
63
+ this.branch_name = ENV.TEST_BEATS_BRANCH_NAME;
64
+ this.pull_request_url = ENV.TEST_BEATS_PULL_REQUEST_URL;
65
+ this.pull_request_name = ENV.TEST_BEATS_PULL_REQUEST_NAME;
66
+ this.build_url = ENV.TEST_BEATS_CI_BUILD_URL;
67
+ this.build_number = ENV.TEST_BEATS_CI_BUILD_NUMBER;
68
+ this.build_name = ENV.TEST_BEATS_CI_BUILD_NAME;
69
+ this.build_reason = ENV.TEST_BEATS_CI_BUILD_REASON;
70
+ this.user = ENV.TEST_BEATS_CI_USER || os.userInfo().username;
71
+
72
+ const runtime = this.#getRuntimeInfo();
73
+ this.runtime = runtime.name;
74
+ this.runtime_version = runtime.version;
75
+ this.os = os.platform();
76
+ this.os_version = os.release();
77
+ this.testbeats_version = pkg.version;
78
+
79
+ }
80
+
81
+ #getRuntimeInfo() {
82
+ if (typeof process !== 'undefined' && process.versions && process.versions.node) {
83
+ return { name: 'node', version: process.versions.node };
84
+ } else if (typeof Deno !== 'undefined') {
85
+ return { name: 'deno', version: Deno.version.deno };
86
+ } else if (typeof Bun !== 'undefined') {
87
+ return { name: 'bun', version: Bun.version };
88
+ } else {
89
+ return { name: 'unknown', version: 'unknown' };
90
+ }
91
+ }
92
+
93
+ setInfo(target, value, force = false) {
94
+ if (force && value) {
95
+ this[target] = value;
96
+ return;
97
+ }
98
+ if (!this[target]) {
99
+ this[target] = value;
100
+ }
101
+ }
102
+
103
+ /**
104
+ *
105
+ * @returns {import('../../extensions/extensions').ICIInfo}
106
+ */
107
+ info() {
108
+ return {
109
+ ci: this.ci,
110
+ git: this.git,
111
+ repository_url: this.repository_url,
112
+ repository_name: this.repository_name,
113
+ repository_ref: this.repository_ref,
114
+ repository_commit_sha: this.repository_commit_sha,
115
+ branch_url: this.branch_url,
116
+ branch_name: this.branch_name,
117
+ pull_request_url: this.pull_request_url,
118
+ pull_request_name: this.pull_request_name,
119
+ build_url: this.build_url,
120
+ build_number: this.build_number,
121
+ build_name: this.build_name,
122
+ build_reason: this.build_reason,
123
+ user: this.user,
124
+ runtime: this.runtime,
125
+ runtime_version: this.runtime_version,
126
+ os: this.os,
127
+ os_version: this.os_version,
128
+ testbeats_version: this.testbeats_version
129
+ }
130
+ }
131
+
132
+ }
133
+
134
+ module.exports = { BaseCI };
@@ -0,0 +1,32 @@
1
+ const { BaseCI } = require('./base.ci');
2
+
3
+ const ENV = process.env;
4
+
5
+ class CircleCI extends BaseCI {
6
+ constructor() {
7
+ super();
8
+ this.init();
9
+ }
10
+
11
+ init() {
12
+ this.setInfo(this.targets.ci, 'CIRCLE_CI');
13
+ this.setInfo(this.targets.git, '');
14
+ this.setInfo(this.targets.repository_url, ENV.CIRCLE_REPOSITORY_URL);
15
+ this.setInfo(this.targets.repository_name, ENV.CIRCLE_PROJECT_REPONAME);
16
+ this.setInfo(this.targets.repository_ref, ENV.CIRCLE_BRANCH);
17
+ this.setInfo(this.targets.repository_commit_sha, ENV.CIRCLE_SHA1);
18
+ this.setInfo(this.targets.branch_url, '');
19
+ this.setInfo(this.targets.branch_name, ENV.CIRCLE_BRANCH);
20
+ this.setInfo(this.targets.pull_request_url,'');
21
+ this.setInfo(this.targets.pull_request_name, '');
22
+ this.setInfo(this.targets.build_url, ENV.CIRCLE_BUILD_URL);
23
+ this.setInfo(this.targets.build_number, ENV.CIRCLE_BUILD_NUM);
24
+ this.setInfo(this.targets.build_name, ENV.CIRCLE_JOB);
25
+ this.setInfo(this.targets.build_reason, 'Push');
26
+ this.setInfo(this.targets.user, ENV.CIRCLE_USERNAME, true);
27
+ }
28
+ }
29
+
30
+ module.exports = {
31
+ CircleCI
32
+ }
@@ -1,38 +1,36 @@
1
+ const { BaseCI } = require('./base.ci');
2
+
1
3
  const ENV = process.env;
2
4
 
3
- /**
4
- * @returns {import('../../extensions/extensions').ICIInfo}
5
- */
6
- function info() {
7
- const github = {
8
- ci: 'GITHUB_ACTIONS',
9
- git: 'GITHUB',
10
- repository_url: ENV.GITHUB_SERVER_URL + '/' + ENV.GITHUB_REPOSITORY,
11
- repository_name: ENV.GITHUB_REPOSITORY,
12
- repository_ref: ENV.GITHUB_REF,
13
- repository_commit_sha: ENV.GITHUB_SHA,
14
- branch_url: '',
15
- branch_name: '',
16
- pull_request_url:'',
17
- pull_request_name: '',
18
- build_url: ENV.GITHUB_SERVER_URL + '/' + ENV.GITHUB_REPOSITORY + '/actions/runs/' + ENV.GITHUB_RUN_ID,
19
- build_number: ENV.GITHUB_RUN_NUMBER,
20
- build_name: ENV.GITHUB_WORKFLOW,
21
- build_reason: ENV.GITHUB_EVENT_NAME,
22
- user: ENV.GITHUB_ACTOR,
5
+ class GitHubCI extends BaseCI {
6
+ constructor() {
7
+ super();
8
+ this.init();
23
9
  }
24
10
 
25
- github.branch_url = github.repository_url + github.repository_ref.replace('refs/heads/', '/tree/');
26
- github.branch_name = github.repository_ref.replace('refs/heads/', '');
11
+ init() {
12
+ this.setInfo(this.targets.ci, 'GITHUB_ACTIONS');
13
+ this.setInfo(this.targets.git, 'GITHUB');
14
+ this.setInfo(this.targets.repository_url, ENV.GITHUB_SERVER_URL + '/' + ENV.GITHUB_REPOSITORY);
15
+ this.setInfo(this.targets.repository_name, ENV.GITHUB_REPOSITORY);
16
+ this.setInfo(this.targets.repository_ref, ENV.GITHUB_REF);
17
+ this.setInfo(this.targets.repository_commit_sha, ENV.GITHUB_SHA);
18
+ this.setInfo(this.targets.build_url, ENV.GITHUB_SERVER_URL + '/' + ENV.GITHUB_REPOSITORY + '/actions/runs/' + ENV.GITHUB_RUN_ID);
19
+ this.setInfo(this.targets.build_number, ENV.GITHUB_RUN_NUMBER);
20
+ this.setInfo(this.targets.build_name, ENV.GITHUB_WORKFLOW);
21
+ this.setInfo(this.targets.build_reason, ENV.GITHUB_EVENT_NAME);
22
+ this.setInfo(this.targets.user, ENV.GITHUB_ACTOR, true);
27
23
 
28
- if (github.repository_ref.includes('refs/pull')) {
29
- github.pull_request_url = github.repository_url + github.repository_ref.replace('refs/pull/', '/pull/');
30
- github.pull_request_name = github.repository_ref.replace('refs/pull/', '').replace('/merge', '');
31
- }
24
+ this.setInfo(this.targets.branch_url, this.repository_url + this.repository_ref.replace('refs/heads/', '/tree/'));
25
+ this.setInfo(this.targets.branch_name, this.repository_ref.replace('refs/heads/', ''));
32
26
 
33
- return github
27
+ if (this.repository_ref.includes('refs/pull')) {
28
+ this.setInfo(this.targets.pull_request_url, this.repository_url + this.repository_ref.replace('refs/pull/', '/pull/'));
29
+ this.setInfo(this.targets.pull_request_name, this.repository_ref.replace('refs/pull/', '').replace('/merge', ''));
30
+ }
31
+ }
34
32
  }
35
33
 
36
34
  module.exports = {
37
- info
35
+ GitHubCI
38
36
  }
@@ -1,36 +1,37 @@
1
+ const { BaseCI } = require('./base.ci');
2
+
1
3
  const ENV = process.env;
2
4
 
3
- /**
4
- * @returns {import('../../extensions/extensions').ICIInfo}
5
- */
6
- function info() {
7
- const gitlab = {
8
- ci: 'GITLAB',
9
- git: 'GITLAB',
10
- repository_url: ENV.CI_PROJECT_URL,
11
- repository_name: ENV.CI_PROJECT_NAME,
12
- repository_ref: '/-/tree/' + (ENV.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME || ENV.CI_COMMIT_REF_NAME),
13
- repository_commit_sha: ENV.CI_MERGE_REQUEST_SOURCE_BRANCH_SHA || ENV.CI_COMMIT_SHA,
14
- branch_url: ENV.CI_PROJECT_URL + '/-/tree/' + (ENV.CI_COMMIT_REF_NAME || ENV.CI_COMMIT_BRANCH),
15
- branch_name: ENV.CI_COMMIT_REF_NAME || ENV.CI_COMMIT_BRANCH,
16
- pull_request_url:'',
17
- pull_request_name: '',
18
- build_url: ENV.CI_JOB_URL,
19
- build_number: ENV.CI_JOB_ID,
20
- build_name: ENV.CI_JOB_NAME,
21
- build_reason: ENV.CI_PIPELINE_SOURCE,
22
- user: ENV.GITLAB_USER_LOGIN || ENV.CI_COMMIT_AUTHOR
5
+ class GitLabCI extends BaseCI {
6
+ constructor() {
7
+ super();
8
+ this.init();
23
9
  }
24
10
 
25
- if (ENV.CI_OPEN_MERGE_REQUESTS) {
26
- const pr_number = ENV.CI_OPEN_MERGE_REQUESTS.split("!")[1];
27
- gitlab.pull_request_name = "#" + pr_number;
28
- gitlab.pull_request_url = ENV.CI_PROJECT_URL + "/-/merge_requests/" + pr_number;
29
- }
11
+ init() {
12
+ this.setInfo(this.targets.ci, 'GITLAB');
13
+ this.setInfo(this.targets.git, 'GITLAB');
14
+ this.setInfo(this.targets.repository_url, ENV.CI_PROJECT_URL);
15
+ this.setInfo(this.targets.repository_name, ENV.CI_PROJECT_NAME);
16
+ this.setInfo(this.targets.repository_ref, '/-/tree/' + (ENV.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME || ENV.CI_COMMIT_REF_NAME));
17
+ this.setInfo(this.targets.repository_commit_sha, ENV.CI_MERGE_REQUEST_SOURCE_BRANCH_SHA || ENV.CI_COMMIT_SHA);
18
+ this.setInfo(this.targets.branch_url, ENV.CI_PROJECT_URL + '/-/tree/' + (ENV.CI_COMMIT_REF_NAME || ENV.CI_COMMIT_BRANCH));
19
+ this.setInfo(this.targets.branch_name, ENV.CI_COMMIT_REF_NAME || ENV.CI_COMMIT_BRANCH);
20
+ this.setInfo(this.targets.pull_request_url,'');
21
+ this.setInfo(this.targets.pull_request_name, '');
22
+ this.setInfo(this.targets.build_url, ENV.CI_JOB_URL);
23
+ this.setInfo(this.targets.build_number, ENV.CI_JOB_ID);
24
+ this.setInfo(this.targets.build_name, ENV.CI_JOB_NAME);
25
+ this.setInfo(this.targets.build_reason, ENV.CI_PIPELINE_SOURCE);
30
26
 
31
- return gitlab
27
+ if (ENV.CI_OPEN_MERGE_REQUESTS) {
28
+ const pr_number = ENV.CI_OPEN_MERGE_REQUESTS.split("!")[1];
29
+ this.setInfo(this.targets.pull_request_name, "#" + pr_number);
30
+ this.setInfo(this.targets.pull_request_url, ENV.CI_PROJECT_URL + "/-/merge_requests/" + pr_number);
31
+ }
32
+ }
32
33
  }
33
34
 
34
35
  module.exports = {
35
- info
36
+ GitLabCI
36
37
  }
@@ -1,9 +1,9 @@
1
- const os = require('os');
2
- const github = require('./github');
3
- const gitlab = require('./gitlab');
4
- const jenkins = require('./jenkins');
5
- const azure_devops = require('./azure-devops');
6
- const system = require('./system');
1
+ const { GitHubCI } = require('./github');
2
+ const { GitLabCI } = require('./gitlab');
3
+ const { JenkinsCI } = require('./jenkins');
4
+ const { AzureDevOpsCI } = require('./azure-devops');
5
+ const { CircleCI } = require('./circle-ci');
6
+ const { BaseCI } = require('./base.ci');
7
7
 
8
8
  const ENV = process.env;
9
9
 
@@ -11,48 +11,33 @@ const ENV = process.env;
11
11
  * @returns {import('../../extensions/extensions').ICIInfo}
12
12
  */
13
13
  function getCIInformation() {
14
- const ci_info = getBaseCIInfo();
15
- const system_info = system.info();
16
- return {
17
- ...ci_info,
18
- ...system_info
19
- }
20
- }
21
-
22
- function getBaseCIInfo() {
23
14
  if (ENV.GITHUB_ACTIONS) {
24
- return github.info();
15
+ const ci = new GitHubCI();
16
+ return ci.info();
25
17
  }
18
+
26
19
  if (ENV.GITLAB_CI) {
27
- return gitlab.info();
20
+ const ci = new GitLabCI();
21
+ return ci.info();
28
22
  }
23
+
29
24
  if (ENV.JENKINS_URL) {
30
- return jenkins.info();
25
+ const ci = new JenkinsCI();
26
+ return ci.info();
31
27
  }
28
+
32
29
  if (ENV.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI) {
33
- return azure_devops.info();
30
+ const ci = new AzureDevOpsCI();
31
+ return ci.info();
34
32
  }
35
- return getDefaultInformation();
36
- }
37
33
 
38
- function getDefaultInformation() {
39
- return {
40
- ci: ENV.TEST_BEATS_CI_NAME,
41
- git: ENV.TEST_BEATS_CI_GIT,
42
- repository_url: ENV.TEST_BEATS_CI_REPOSITORY_URL,
43
- repository_name: ENV.TEST_BEATS_CI_REPOSITORY_NAME,
44
- repository_ref: ENV.TEST_BEATS_CI_REPOSITORY_REF,
45
- repository_commit_sha: ENV.TEST_BEATS_CI_REPOSITORY_COMMIT_SHA,
46
- branch_url: ENV.TEST_BEATS_BRANCH_URL,
47
- branch_name: ENV.TEST_BEATS_BRANCH_NAME,
48
- pull_request_url: ENV.TEST_BEATS_PULL_REQUEST_URL,
49
- pull_request_name: ENV.TEST_BEATS_PULL_REQUEST_NAME,
50
- build_url: ENV.TEST_BEATS_CI_BUILD_URL,
51
- build_number: ENV.TEST_BEATS_CI_BUILD_NUMBER,
52
- build_name: ENV.TEST_BEATS_CI_BUILD_NAME,
53
- build_reason: ENV.TEST_BEATS_CI_BUILD_REASON,
54
- user: ENV.TEST_BEATS_CI_USER || os.userInfo().username
34
+ if (ENV.CIRCLECI) {
35
+ const ci = new CircleCI();
36
+ return ci.info();
55
37
  }
38
+
39
+ const ci = new BaseCI();
40
+ return ci.info();
56
41
  }
57
42
 
58
43
  module.exports = {
@@ -1,38 +1,36 @@
1
+ const { BaseCI } = require('./base.ci');
2
+
1
3
  const ENV = process.env;
2
4
 
3
- /**
4
- * @returns {import('../../extensions/extensions').ICIInfo}
5
- */
6
- function info() {
7
- const jenkins = {
8
- ci: 'JENKINS',
9
- git: '',
10
- repository_url: ENV.GIT_URL || ENV.GITHUB_URL || ENV.BITBUCKET_URL,
11
- repository_name: ENV.JOB_NAME,
12
- repository_ref: ENV.BRANCH || ENV.BRANCH_NAME,
13
- repository_commit_sha: ENV.GIT_COMMIT || ENV.GIT_COMMIT_SHA || ENV.GITHUB_SHA || ENV.BITBUCKET_COMMIT,
14
- branch_url: '',
15
- branch_name: '',
16
- pull_request_url:'',
17
- pull_request_name: '',
18
- build_url: ENV.BUILD_URL,
19
- build_number: ENV.BUILD_NUMBER,
20
- build_name: ENV.JOB_NAME,
21
- build_reason: ENV.BUILD_CAUSE,
22
- user: ENV.USER || ENV.USERNAME
5
+ class JenkinsCI extends BaseCI {
6
+ constructor() {
7
+ super();
8
+ this.init();
23
9
  }
24
10
 
25
- jenkins.branch_url = jenkins.repository_url + jenkins.repository_ref.replace('refs/heads/', '/tree/');
26
- jenkins.branch_name = jenkins.repository_ref.replace('refs/heads/', '');
11
+ init() {
12
+ this.setInfo(this.targets.ci, 'JENKINS');
13
+ this.setInfo(this.targets.git, '');
14
+ this.setInfo(this.targets.repository_url, ENV.GIT_URL || ENV.GITHUB_URL || ENV.BITBUCKET_URL);
15
+ this.setInfo(this.targets.repository_name, ENV.JOB_NAME);
16
+ this.setInfo(this.targets.repository_ref, ENV.BRANCH || ENV.BRANCH_NAME);
17
+ this.setInfo(this.targets.repository_commit_sha, ENV.GIT_COMMIT || ENV.GIT_COMMIT_SHA || ENV.GITHUB_SHA || ENV.BITBUCKET_COMMIT);
18
+ this.setInfo(this.targets.branch_url, this.repository_url + this.repository_ref.replace('refs/heads/', '/tree/'));
19
+ this.setInfo(this.targets.branch_name, this.repository_ref.replace('refs/heads/', ''));
27
20
 
28
- if (jenkins.repository_ref.includes('refs/pull')) {
29
- jenkins.pull_request_url = jenkins.repository_url + jenkins.repository_ref.replace('refs/pull/', '/pull/');
30
- jenkins.pull_request_name = jenkins.repository_ref.replace('refs/pull/', '').replace('/merge', '');
31
- }
21
+ if (this.repository_ref.includes('refs/pull')) {
22
+ this.setInfo(this.targets.pull_request_url, this.repository_url + this.repository_ref.replace('refs/pull/', '/pull/'));
23
+ this.setInfo(this.targets.pull_request_name, this.repository_ref.replace('refs/pull/', '').replace('/merge', ''));
24
+ }
32
25
 
33
- return jenkins_info;
26
+ this.setInfo(this.targets.build_url, ENV.BUILD_URL);
27
+ this.setInfo(this.targets.build_number, ENV.BUILD_NUMBER);
28
+ this.setInfo(this.targets.build_name, ENV.JOB_NAME);
29
+ this.setInfo(this.targets.build_reason, ENV.BUILD_CAUSE);
30
+ this.setInfo(this.targets.user, ENV.USER || ENV.USERNAME, true);
31
+ }
34
32
  }
35
33
 
36
34
  module.exports = {
37
- info
35
+ JenkinsCI
38
36
  }
@@ -24,6 +24,7 @@ const EXTENSION = Object.freeze({
24
24
  FAILURE_ANALYSIS: 'failure-analysis',
25
25
  SMART_ANALYSIS: 'smart-analysis',
26
26
  ERROR_CLUSTERS: 'error-clusters',
27
+ BROWSERSTACK: 'browserstack',
27
28
  HYPERLINKS: 'hyperlinks',
28
29
  MENTIONS: 'mentions',
29
30
  REPORT_PORTAL_ANALYSIS: 'report-portal-analysis',
@@ -37,7 +38,8 @@ const EXTENSION = Object.freeze({
37
38
 
38
39
  const URLS = Object.freeze({
39
40
  PERCY: 'https://percy.io',
40
- QUICK_CHART: 'https://quickchart.io'
41
+ QUICK_CHART: 'https://quickchart.io',
42
+ BROWSERSTACK: 'https://api.browserstack.com'
41
43
  });
42
44
 
43
45
  const PROCESS_STATUS = Object.freeze({
@@ -14,18 +14,11 @@ function getPercentage(x, y) {
14
14
  function processText(raw) {
15
15
  const dataRefMatches = raw.match(DATA_REF_PATTERN);
16
16
  if (dataRefMatches) {
17
- const values = [];
18
17
  for (let i = 0; i < dataRefMatches.length; i++) {
19
18
  const dataRefMatch = dataRefMatches[i];
20
19
  const content = dataRefMatch.slice(1, -1);
21
- if (process.env[content]) {
22
- values.push(process.env[content]);
23
- } else {
24
- values.push(content);
25
- }
26
- }
27
- for (let i = 0; i < dataRefMatches.length; i++) {
28
- raw = raw.replace(dataRefMatches[i], values[i]);
20
+ const envValue = process.env[content] || content;
21
+ raw = raw.replace(dataRefMatch, envValue);
29
22
  }
30
23
  }
31
24
  return raw;
package/src/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { PerformanceParseOptions } from 'performance-results-parser';
2
2
  import PerformanceTestResult from 'performance-results-parser/src/models/PerformanceTestResult';
3
3
  import { Schedule, User } from 'rosters';
4
4
  import { ParseOptions } from 'test-results-parser';
5
- import TestResult from 'test-results-parser/src/models/TestResult';
5
+ export import TestResult from 'test-results-parser/src/models/TestResult';
6
6
 
7
7
  export interface ITarget {
8
8
  name: TargetName;
@@ -17,7 +17,7 @@ export interface IExtension {
17
17
  enable?: string | boolean;
18
18
  condition?: Condition;
19
19
  hook?: Hook;
20
- inputs?: ReportPortalAnalysisInputs | ReportPortalHistoryInputs | HyperlinkInputs | MentionInputs | QuickChartTestSummaryInputs | PercyAnalysisInputs | CustomExtensionInputs | MetadataInputs | CIInfoInputs | AIFailureSummaryInputs;
20
+ inputs?: ReportPortalAnalysisInputs | ReportPortalHistoryInputs | HyperlinkInputs | MentionInputs | QuickChartTestSummaryInputs | PercyAnalysisInputs | CustomExtensionInputs | MetadataInputs | CIInfoInputs | AIFailureSummaryInputs | BrowserstackInputs;
21
21
  }
22
22
 
23
23
  export type ExtensionName = 'report-portal-analysis' | 'hyperlinks' | 'mentions' | 'report-portal-history' | 'quick-chart-test-summary' | 'metadata' | 'ci-info' | 'custom' | 'ai-failure-summary';
@@ -83,7 +83,51 @@ export interface AIFailureSummaryInputs extends ExtensionInputs {
83
83
  failure_summary: string;
84
84
  }
85
85
 
86
+ export interface BrowserStackAutomationBuild {
87
+ name: string;
88
+ hashed_id: string;
89
+ duration: number;
90
+ status: string;
91
+ build_tag: string;
92
+ public_url: string;
93
+ }
86
94
 
95
+ export interface BrowserStackAutomationSession {
96
+ name: string;
97
+ duration: number;
98
+ os: string;
99
+ os_version: string;
100
+ browser_version: string;
101
+ browser: string;
102
+ device: string;
103
+ status: string;
104
+ hashed_id: string;
105
+ reason: string;
106
+ build_name: string;
107
+ project_name: string;
108
+ build_hashed_id: string;
109
+ test_priority: string;
110
+ logs: string;
111
+ browserstack_status: string;
112
+ created_at: string;
113
+ browser_url: string;
114
+ public_url: string;
115
+ video_url: string;
116
+ browser_console_logs_url: string;
117
+ har_logs_url: string;
118
+ selenium_logs_url: string;
119
+ session_terminal_logs_url: string;
120
+ build_terminal_logs_url: string;
121
+ }
122
+
123
+ export interface BrowserstackInputs extends ExtensionInputs {
124
+ url?: string;
125
+ username?: string;
126
+ access_key?: string;
127
+ automation_build_name?: string;
128
+ automation_build?: BrowserStackAutomationBuild;
129
+ automation_sessions?: BrowserStackAutomationSession[];
130
+ }
87
131
 
88
132
  export interface PercyAnalysisInputs extends ExtensionInputs {
89
133
  url?: string;
@@ -0,0 +1,62 @@
1
+ const { getAutomationBuilds, getAutomationBuildSessions } = require('../helpers/browserstack.helper');
2
+
3
+ class ExtensionsSetup {
4
+ constructor(extensions, result) {
5
+ this.extensions = extensions;
6
+ this.result = result;
7
+ }
8
+
9
+ async run() {
10
+ for (const extension of this.extensions) {
11
+ if (extension.name === 'browserstack') {
12
+ const browserStackExtensionSetup = new BrowserStackExtensionSetup(extension.inputs, this.result);
13
+ await browserStackExtensionSetup.setup();
14
+ }
15
+ }
16
+ }
17
+ }
18
+
19
+ class BrowserStackExtensionSetup {
20
+ constructor(inputs, result) {
21
+ /** @type {import('../index').BrowserstackInputs} */
22
+ this.inputs = inputs;
23
+ this.result = result;
24
+ }
25
+
26
+ async setup() {
27
+ const build_rows = await getAutomationBuilds(this.inputs);
28
+ if (!Array.isArray(build_rows) || build_rows.length === 0) {
29
+ throw new Error('No builds found');
30
+ }
31
+ const automation_build = build_rows.find(_ => _.automation_build.name === this.inputs.automation_build_name);
32
+ if (!automation_build) {
33
+ throw new Error(`Build ${this.inputs.automation_build_name} not found`);
34
+ }
35
+ this.inputs.automation_build = automation_build.automation_build;
36
+ if (this.result) {
37
+ this.result.metadata = this.result.metadata || {};
38
+ this.result.metadata.ext_browserstack_automation_build = automation_build.automation_build;
39
+ }
40
+ this.inputs.automation_sessions = [];
41
+ const session_rows = await getAutomationBuildSessions(this.inputs, automation_build.automation_build.hashed_id);
42
+ if (!Array.isArray(session_rows) || session_rows.length === 0) {
43
+ throw new Error('No sessions found');
44
+ }
45
+ for (const session_row of session_rows) {
46
+ this.inputs.automation_sessions.push(session_row.automation_session);
47
+ }
48
+ if (this.result && this.result.suites && this.result.suites.length > 0) {
49
+ for (const suite of this.result.suites) {
50
+ const automation_session = this.inputs.automation_sessions.filter(_ => { _.name === suite.name })[0];
51
+ if (automation_session) {
52
+ suite.metadata = suite.metadata || {};
53
+ suite.metadata.ext_browserstack_automation_session = automation_session;
54
+ }
55
+ }
56
+ }
57
+ }
58
+ }
59
+
60
+ module.exports = {
61
+ ExtensionsSetup
62
+ }
@@ -1,30 +0,0 @@
1
- const os = require('os');
2
- const pkg = require('../../../package.json');
3
-
4
- function info() {
5
- function getRuntimeInfo() {
6
- if (typeof process !== 'undefined' && process.versions && process.versions.node) {
7
- return { name: 'node', version: process.versions.node };
8
- } else if (typeof Deno !== 'undefined') {
9
- return { name: 'deno', version: Deno.version.deno };
10
- } else if (typeof Bun !== 'undefined') {
11
- return { name: 'bun', version: Bun.version };
12
- } else {
13
- return { name: 'unknown', version: 'unknown' };
14
- }
15
- }
16
-
17
- const runtime = getRuntimeInfo();
18
-
19
- return {
20
- runtime: runtime.name,
21
- runtime_version: runtime.version,
22
- os: os.platform(),
23
- os_version: os.release(),
24
- testbeats_version: pkg.version
25
- }
26
- }
27
-
28
- module.exports = {
29
- info
30
- }