Skip to content

Commit 88c26c7

Browse files
authored
[minor] added tmsWithId and issueWithId (#244)
1 parent c6a03c0 commit 88c26c7

File tree

5 files changed

+95
-1
lines changed

5 files changed

+95
-1
lines changed

docs/interface.md

+32
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,23 @@ Will be shown in Links field for test
307307
cy.allure().tms('1', 'tms-1');
308308
```
309309

310+
311+
### tmsWithId
312+
**tmsWithId(url: string, name?: string)**
313+
314+
Adds link to test of type 'tms' ('tms' will have specific icon )
315+
316+
The same as `tms` but will add tms id into description
317+
318+
When `tmsPrefix` environment variable added no need to input the whole URL
319+
320+
Will be shown in Links field for test
321+
322+
```javascript
323+
cy.allure().tmsWithId('ABC-1', 'desc'); // will have link 'ABC-1: desc' when tmsPrefix is set
324+
```
325+
326+
310327
### issue
311328
**issue(url: string, name?: string)**
312329

@@ -321,6 +338,21 @@ cy.allure().issue('1', 'issue-1');
321338
```
322339

323340

341+
### issueWithId
342+
**issueWithId(url: string, name?: string)**
343+
344+
Adds link to test of type 'issue' ('issue' will have specific icon - bug icon )
345+
346+
The same as `issue` but will add issue id into description
347+
348+
When `issuePrefix` environment variable added no need to input the whole URL
349+
350+
Will be shown in Links field for test
351+
352+
```javascript
353+
cy.allure().issueWithId('ABC-1', 'desc'); // will have link 'ABC-1: desc' when issuePrefix is set
354+
```
355+
324356
### parameter
325357
**parameter(name: string, value: string)**
326358

src/commands/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export const registerCommands = () => {
3131
feature: (allure, value) => allure.feature(value),
3232
link: (allure, value, name, type) => allure.link(value, name, type),
3333
tms: (allure, value, name) => allure.tms(value, name),
34+
tmsWithId: (allure, value, name) => allure.tmsWithId(value, name),
3435
issue: (allure, value, name) => allure.issue(value, name),
36+
issueWithId: (allure, value, name) => allure.issueWithId(value, name),
3537
story: (allure, value) => allure.story(value),
3638
suite: (allure, name) => allure.suite(name),
3739
subSuite: (allure, name) => allure.subSuite(name),

src/common/index.ts

+23
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,29 @@ export const tmsIssueUrl = (env: Record<string, string>, value: string, type: 'i
5353
return `${prefixFixed}/${value}`;
5454
};
5555

56+
export const tmsIssueId = (env: Record<string, string>, value: string, type: 'issue' | 'tms') => {
57+
if (value.startsWith('http://') || value.startsWith('https://')) {
58+
return undefined;
59+
}
60+
61+
if (type === 'issue') {
62+
return env['issuePrefix'] ? value : undefined;
63+
}
64+
65+
if (type === 'tms') {
66+
return env['tmsPrefix'] ? value : undefined;
67+
}
68+
69+
return undefined;
70+
};
71+
72+
export const descriptionId = (env: Record<string, string>, value: string, type: 'issue' | 'tms', desc?: string) => {
73+
const id = tmsIssueId(env, value, type);
74+
const idStr = id ? `${id}: ` : '';
75+
76+
return desc ? `${idStr}${desc}` : value;
77+
};
78+
5679
// needed to work in browser
5780
export const extname = (path: string): string => {
5881
return path.match(/(\.[^.\\/]+)$/)?.[0] ?? '.unknown';

src/cypress/types.ts

+21
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,16 @@ declare namespace Cypress {
305305
*/
306306
tms(urlOrId: string, name?: string): T;
307307

308+
/**
309+
* Adds link to tms = has icon tms
310+
* @param urlOrId = full url or ID of item
311+
* @param name = display text for URL in report (will add urlOrId to diplay text when it is id)
312+
* @example
313+
* cy.allure().tmsWithId('ABD-123');
314+
* cy.allure().tmsWithId('http://my.jira.com/ABD-123', 'ABD-123 description');
315+
*/
316+
tmsWithId(urlOrId: string, name?: string): T;
317+
308318
/**
309319
* Adds link to defect = has icon BUG
310320
* @param urlOrId = full url or ID of item
@@ -315,6 +325,17 @@ declare namespace Cypress {
315325
*/
316326
issue(urlOrId: string, name?: string): T;
317327

328+
/**
329+
* Adds link to defect = has icon BUG
330+
* @param urlOrId = full url or ID of item
331+
* @param name = display text for URL in report (will add urlOrId to diplay text when it is id)
332+
* @example
333+
* cy.allure().issueWithId('ABD-123'); // will add link: "ABD-123"
334+
* cy.allure().issueWithId('http://my.jira.com/ABD-123', 'ABD-123 description'); // will add link: "ABD-123 description"
335+
* cy.allure().issueWithId('ABD-123', 'description'); // will add link: "ABD-123: description"
336+
*/
337+
issueWithId(urlOrId: string, name?: string): T;
338+
318339
feature(value: string): T;
319340
story(value: string): T;
320341
allureId(value: string): T;

src/setup/allure-mocha-reporter.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { registerScreenshotHandler } from './screenshots';
1414
import StatusDetails = Cypress.StatusDetails;
1515
import { logClient } from './helper';
16-
import { packageLog, tmsIssueUrl } from '../common';
16+
import { descriptionId, packageLog, tmsIssueUrl } from '../common';
1717
import { EventEmitter } from 'events';
1818
import AllureEvents = Cypress.AllureEvents;
1919

@@ -205,6 +205,14 @@ export const allureInterface = (
205205
return fn({ task: 'link', arg: { url: fullUrl, name: linkName, type } });
206206
},
207207

208+
tmsWithId: (url: string, name?: string) => {
209+
const type: LinkType = 'tms';
210+
const fullUrl = tmsIssueUrl(env, url, type);
211+
const linkName = descriptionId(env, url, type, name);
212+
213+
return fn({ task: 'link', arg: { url: fullUrl, name: linkName, type } });
214+
},
215+
208216
issue: (url: string, name?: string) => {
209217
const type: LinkType = 'issue';
210218
const fullUrl = tmsIssueUrl(env, url, type);
@@ -213,6 +221,14 @@ export const allureInterface = (
213221
return fn({ task: 'link', arg: { url: fullUrl, name: linkName, type } });
214222
},
215223

224+
issueWithId: (url: string, name?: string) => {
225+
const type: LinkType = 'issue';
226+
const fullUrl = tmsIssueUrl(env, url, type);
227+
const linkName = descriptionId(env, url, type, name);
228+
229+
return fn({ task: 'link', arg: { url: fullUrl, name: linkName, type } });
230+
},
231+
216232
label: (name: string, value: string) => fn({ task: 'label', arg: { name, value } }),
217233
suite: (name: string) => fn({ task: 'suite', arg: { name } }),
218234
parentSuite: (name: string) => fn({ task: 'parentSuite', arg: { name } }),

0 commit comments

Comments
 (0)