Skip to content

Commit 53cd070

Browse files
committed
added helper
1 parent 937d335 commit 53cd070

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export { parseAllure } from './parser/parse';
22
export type { AllureTest, AllureContainer, AllureTestStatus } from './types';
3-
export { getSummary, getRootSuite } from './parser/helpers';
3+
export { getSummary, getRootSuite, getParentsArray } from './parser/helpers';

src/parser/helpers.ts

+19
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,22 @@ export const getSummary = (
3636
{ passed: 0, failed: 0, skipped: 0, broken: 0, unknown: 0 },
3737
);
3838
};
39+
40+
/**
41+
* Get parents into array, first - closes parent of the test
42+
* @param node - test or container
43+
* @param res - results
44+
*/
45+
export const getParentsArray = (node?: AllureNode, res: Parent[] = []): Parent[] => {
46+
if (node?.parent) {
47+
res.push(node.parent);
48+
49+
return getParentsArray(node.parent, res);
50+
}
51+
52+
if (node && !isContainer(node)) {
53+
return res;
54+
}
55+
56+
return res;
57+
};

src/tests/unit/helpers.test.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getRootSuite, getSummary } from '../../parser/helpers';
1+
import { getParentsArray, getRootSuite, getSummary } from '../../parser/helpers';
22
import { AllureTest } from '../../types';
33
import { parseAllure } from '../../parser/parse';
44
import path from 'path';
@@ -22,6 +22,29 @@ describe('helpers', () => {
2222
});
2323
});
2424

25+
it('getParentsArray', () => {
26+
const counts = res.map(t => ({ name: t.name, parents: getParentsArray(t).map(p => p.name) }));
27+
28+
expect(counts).toEqual([
29+
{
30+
name: 'should be red',
31+
parents: ['tomato', 'fruits'],
32+
},
33+
{
34+
name: 'should have stick',
35+
parents: ['apples', 'fruits'],
36+
},
37+
{
38+
name: 'no suite test',
39+
parents: [],
40+
},
41+
{
42+
name: 'should wight ~100-400 gramms',
43+
parents: ['apples', 'fruits'],
44+
},
45+
]);
46+
});
47+
2548
it('summaryNumbers with filter', () => {
2649
const counts = getSummary(res, t => t.name?.indexOf('should have') !== -1);
2750

0 commit comments

Comments
 (0)