Skip to content

Commit 0f46f6d

Browse files
authored
chore: enable target and extension (#255)
1 parent 5df0703 commit 0f46f6d

11 files changed

+150
-66
lines changed

src/commands/publish.command.js

+6
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ class PublishCommand {
158158
throw new Error('targets must be an array');
159159
}
160160
for (const target of config.targets) {
161+
if (target.enable === false || target.enable === 'false') {
162+
continue;
163+
}
161164
if (!target.name) {
162165
throw new Error(`'config.targets[*].name' is missing`);
163166
}
@@ -219,6 +222,9 @@ class PublishCommand {
219222
await beats.run(config, result);
220223
if (config.targets) {
221224
for (const target of config.targets) {
225+
if (target.enable === false || target.enable === 'false') {
226+
continue;
227+
}
222228
target.extensions = target.extensions || [];
223229
target.extensions = config.extensions.concat(target.extensions);
224230
await target_manager.run(target, result);

src/extensions/base.extension.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ class BaseExtension {
55

66
/**
77
*
8-
* @param {import('..').Target} target
9-
* @param {import('..').Extension} extension
8+
* @param {import('..').ITarget} target
9+
* @param {import('..').IExtension} extension
1010
* @param {import('..').TestResult} result
1111
* @param {any} payload
1212
* @param {any} root_payload

src/extensions/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ const { FailureAnalysisExtension } = require('./failure-analysis.extension');
1717

1818
async function run(options) {
1919
const { target, result, hook } = options;
20+
/**
21+
* @type {import("..").IExtension[]}
22+
*/
2023
const extensions = target.extensions || [];
2124
for (let i = 0; i < extensions.length; i++) {
2225
const extension = extensions[i];
26+
if (extension.enable === false || extension.enable === 'false') {
27+
continue;
28+
}
2329
const extension_runner = getExtensionRunner(extension, options);
2430
const extension_options = Object.assign({}, extension_runner.default_options, extension);
2531
if (extension_options.hook === hook) {

src/extensions/metadata.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { getTeamsMetaDataText, getSlackMetaDataText, getChatMetaDataText } = requ
44

55
/**
66
* @param {object} param0
7-
* @param {import('..').Target} param0.target
7+
* @param {import('..').ITarget} param0.target
88
* @param {import('..').MetadataExtension} param0.extension
99
*/
1010
async function run({ target, extension, result, payload, root_payload }) {

src/helpers/extension.helper.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
*
44
* @param {object} param0 - the payload object
55
* @param {object} param0.payload - the payload object
6-
* @param {import("..").Extension} param0.extension - the extension to add
6+
* @param {import("..").IExtension} param0.extension - the extension to add
77
* @param {string} param0.text - the text to include
8-
* @return {void}
8+
* @return {void}
99
*/
1010
function addSlackExtension({ payload, extension, text }) {
1111
if (extension.inputs.separator) {
@@ -44,9 +44,9 @@ function addSlackExtension({ payload, extension, text }) {
4444
*
4545
* @param {object} param0 - the payload object
4646
* @param {object} param0.payload - the payload object
47-
* @param {import("..").Extension} param0.extension - the extension to add
47+
* @param {import("..").IExtension} param0.extension - the extension to add
4848
* @param {string} param0.text - the text to include
49-
* @return {void}
49+
* @return {void}
5050
*/
5151
function addTeamsExtension({ payload, extension, text }) {
5252
if (extension.inputs.title) {
@@ -79,9 +79,9 @@ function addTeamsExtension({ payload, extension, text }) {
7979
*
8080
* @param {object} param0 - the payload object
8181
* @param {object} param0.payload - the payload object
82-
* @param {import("..").Extension} param0.extension - the extension to add
82+
* @param {import("..").IExtension} param0.extension - the extension to add
8383
* @param {string} param0.text - the text to include
84-
* @return {void}
84+
* @return {void}
8585
*/
8686
function addChatExtension({ payload, extension, text }) {
8787
let updated_text = text;

src/helpers/metadata.helper.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ function getMetaDataText(params) {
1818
*
1919
* @param {object} param0 - the payload object
2020
* @param {Object} param0.elements - The elements to generate metadata text from
21-
* @param {import('..').Target} param0.target - The result object
22-
* @param {import('..').Extension} param0.extension - The result object
21+
* @param {import('..').ITarget} param0.target - The result object
22+
* @param {import('..').IExtension} param0.extension - The result object
2323
* @param {Object} param0.result - The result object
2424
* @param {string} param0.default_condition - The default condition object
2525
* @return {string} The generated metadata text
@@ -50,8 +50,8 @@ async function getSlackMetaDataText({ elements, target, extension, result, defau
5050
*
5151
* @param {object} param0 - the payload object
5252
* @param {Object} param0.elements - The elements to generate metadata text from
53-
* @param {import('..').Target} param0.target - The result object
54-
* @param {import('..').Extension} param0.extension - The result object
53+
* @param {import('..').ITarget} param0.target - The result object
54+
* @param {import('..').IExtension} param0.extension - The result object
5555
* @param {Object} param0.result - The result object
5656
* @param {string} param0.default_condition - The default condition object
5757
* @return {string} The generated metadata text
@@ -82,8 +82,8 @@ async function getTeamsMetaDataText({ elements, target, extension, result, defau
8282
*
8383
* @param {object} param0 - the payload object
8484
* @param {Object} param0.elements - The elements to generate metadata text from
85-
* @param {import('..').Target} param0.target - The result object
86-
* @param {import('..').Extension} param0.extension - The result object
85+
* @param {import('..').ITarget} param0.target - The result object
86+
* @param {import('..').IExtension} param0.extension - The result object
8787
* @param {Object} param0.result - The result object
8888
* @param {string} param0.default_condition - The default condition object
8989
* @return {string} The generated metadata text

src/index.d.ts

+32-26
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,30 @@ import { Schedule, User } from 'rosters';
44
import { ParseOptions } from 'test-results-parser';
55
import TestResult from 'test-results-parser/src/models/TestResult';
66

7+
export interface ITarget {
8+
name: TargetName;
9+
enable?: string | boolean;
10+
condition?: Condition;
11+
inputs?: SlackInputs | TeamsInputs | ChatInputs | CustomTargetInputs | InfluxDBTargetInputs;
12+
extensions?: IExtension[];
13+
}
14+
15+
export interface IExtension {
16+
name: ExtensionName;
17+
enable?: string | boolean;
18+
condition?: Condition;
19+
hook?: Hook;
20+
inputs?: ReportPortalAnalysisInputs | ReportPortalHistoryInputs | HyperlinkInputs | MentionInputs | QuickChartTestSummaryInputs | PercyAnalysisInputs | CustomExtensionInputs | MetadataInputs | CIInfoInputs | AIFailureSummaryInputs;
21+
}
22+
723
export type ExtensionName = 'report-portal-analysis' | 'hyperlinks' | 'mentions' | 'report-portal-history' | 'quick-chart-test-summary' | 'metadata' | 'ci-info' | 'custom' | 'ai-failure-summary';
824
export type Hook = 'start' | 'end' | 'after-summary';
925
export type TargetName = 'slack' | 'teams' | 'chat' | 'custom' | 'delay';
1026
export type PublishReportType = 'test-summary' | 'test-summary-slim' | 'failure-details';
1127

1228
export interface ConditionFunctionContext {
13-
target: Target;
14-
extension?: Extension,
29+
target: ITarget;
30+
extension?: IExtension,
1531
result: TestResult;
1632
}
1733
export type ConditionFunction = (ctx: ConditionFunctionContext) => boolean | Promise<boolean>;
@@ -67,12 +83,7 @@ export interface AIFailureSummaryInputs extends ExtensionInputs {
6783
failure_summary: string;
6884
}
6985

70-
export interface Extension {
71-
name: ExtensionName;
72-
condition?: Condition;
73-
hook?: Hook;
74-
inputs?: ReportPortalAnalysisInputs | ReportPortalHistoryInputs | HyperlinkInputs | MentionInputs | QuickChartTestSummaryInputs | PercyAnalysisInputs | CustomExtensionInputs | MetadataInputs | CIInfoInputs | AIFailureSummaryInputs;
75-
}
86+
7687

7788
export interface PercyAnalysisInputs extends ExtensionInputs {
7889
url?: string;
@@ -90,14 +101,14 @@ export interface PercyAnalysisOutputs {
90101
project?: object;
91102
}
92103

93-
export interface PercyAnalysisExtension extends Extension {
104+
export interface PercyAnalysisExtension extends IExtension {
94105
inputs?: PercyAnalysisInputs;
95106
outputs?: PercyAnalysisOutputs;
96107
}
97108

98109
export interface CustomExtensionFunctionContext {
99-
target: Target;
100-
extension: Extension,
110+
target: ITarget;
111+
extension: IExtension,
101112
result: TestResult;
102113
payload: any;
103114
root_payload: any;
@@ -109,13 +120,13 @@ export interface CustomExtensionInputs extends ExtensionInputs {
109120
load: string | CustomExtensionFunction;
110121
}
111122

112-
export interface CustomExtension extends Extension {
123+
export interface CustomExtension extends IExtension {
113124
inputs?: CustomExtensionInputs;
114125
outputs?: any;
115126
}
116127

117128
export interface LinkUrlFunctionContext {
118-
target: Target;
129+
target: ITarget;
119130
extension: HyperlinksExtension,
120131
result: TestResult;
121132
}
@@ -132,7 +143,7 @@ export interface HyperlinkInputs extends ExtensionInputs {
132143
links: Link[];
133144
}
134145

135-
export interface HyperlinksExtension extends Extension {
146+
export interface HyperlinksExtension extends IExtension {
136147
inputs?: HyperlinkInputs;
137148
}
138149

@@ -148,7 +159,7 @@ export interface MetadataInputs extends ExtensionInputs {
148159
data?: Metadata[];
149160
}
150161

151-
export interface MetadataExtension extends Extension {
162+
export interface MetadataExtension extends IExtension {
152163
inputs?: MetadataInputs;
153164
}
154165

@@ -202,7 +213,7 @@ export interface InfluxDBTargetInputs {
202213
}
203214

204215
export interface CustomTargetFunctionContext {
205-
target: Target;
216+
target: ITarget;
206217
result: TestResult;
207218
}
208219

@@ -212,12 +223,7 @@ export interface CustomTargetInputs {
212223
load: string | CustomTargetFunction;
213224
}
214225

215-
export interface Target {
216-
name: TargetName;
217-
condition?: Condition;
218-
inputs?: SlackInputs | TeamsInputs | ChatInputs | CustomTargetInputs | InfluxDBTargetInputs;
219-
extensions?: Extension[];
220-
}
226+
221227

222228
export interface CustomResultOptions {
223229
type: string;
@@ -232,17 +238,17 @@ export interface PublishReport {
232238
show_failure_analysis?: boolean;
233239
show_smart_analysis?: boolean;
234240
show_error_clusters?: boolean;
235-
targets?: Target[];
236-
extensions?: Extension[];
241+
targets?: ITarget[];
242+
extensions?: IExtension[];
237243
results?: ParseOptions[] | PerformanceParseOptions[] | CustomResultOptions[];
238244
}
239245

240246
export interface PublishConfig {
241247
api_key?: string;
242248
project?: string;
243249
run?: string;
244-
targets?: Target[];
245-
extensions?: Extension[];
250+
targets?: ITarget[];
251+
extensions?: IExtension[];
246252
results?: ParseOptions[] | PerformanceParseOptions[] | CustomResultOptions[];
247253
}
248254

src/platforms/base.platform.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class BasePlatform {
1515

1616
/**
1717
*
18-
* @param {import('..').Target} target
18+
* @param {import('..').ITarget} target
1919
* @param {import('test-results-parser').ITestSuite} suite
2020
*/
2121
getSuiteSummaryText(target, suite) {
@@ -74,7 +74,7 @@ class BasePlatform {
7474

7575
/**
7676
*
77-
* @param {import('..').Target} target
77+
* @param {import('..').ITarget} target
7878
* @param {import('test-results-parser').ITestSuite} suite
7979
*/
8080
#getSuiteDurationText(target, suite) {
@@ -84,7 +84,7 @@ class BasePlatform {
8484

8585
/**
8686
*
87-
* @param {import('..').Target} target
87+
* @param {import('..').ITarget} target
8888
* @param {import('test-results-parser').ITestSuite} suite
8989
*/
9090
getSuiteDuration(target, suite) {

src/targets/custom.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ const path = require('path');
22
const { STATUS } = require('../helpers/constants');
33

44
/**
5-
*
6-
* @param {object} param0
7-
* @param {import('../index').Target} param0.target
5+
*
6+
* @param {object} param0
7+
* @param {import('../index').ITarget} param0.target
88
*/
99
async function run({result, target}) {
1010
if (typeof target.inputs.load === 'string') {

0 commit comments

Comments
 (0)