Skip to content

Commit

Permalink
added helper
Browse files Browse the repository at this point in the history
  • Loading branch information
mmisty committed Jun 2, 2023
1 parent 937d335 commit 53cd070
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { parseAllure } from './parser/parse';
export type { AllureTest, AllureContainer, AllureTestStatus } from './types';
export { getSummary, getRootSuite } from './parser/helpers';
export { getSummary, getRootSuite, getParentsArray } from './parser/helpers';
19 changes: 19 additions & 0 deletions src/parser/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,22 @@ export const getSummary = (
{ passed: 0, failed: 0, skipped: 0, broken: 0, unknown: 0 },
);
};

/**
* Get parents into array, first - closes parent of the test
* @param node - test or container
* @param res - results
*/
export const getParentsArray = (node?: AllureNode, res: Parent[] = []): Parent[] => {
if (node?.parent) {
res.push(node.parent);

return getParentsArray(node.parent, res);
}

if (node && !isContainer(node)) {
return res;
}

return res;
};
25 changes: 24 additions & 1 deletion src/tests/unit/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getRootSuite, getSummary } from '../../parser/helpers';
import { getParentsArray, getRootSuite, getSummary } from '../../parser/helpers';
import { AllureTest } from '../../types';
import { parseAllure } from '../../parser/parse';
import path from 'path';
Expand All @@ -22,6 +22,29 @@ describe('helpers', () => {
});
});

it('getParentsArray', () => {
const counts = res.map(t => ({ name: t.name, parents: getParentsArray(t).map(p => p.name) }));

expect(counts).toEqual([
{
name: 'should be red',
parents: ['tomato', 'fruits'],
},
{
name: 'should have stick',
parents: ['apples', 'fruits'],
},
{
name: 'no suite test',
parents: [],
},
{
name: 'should wight ~100-400 gramms',
parents: ['apples', 'fruits'],
},
]);
});

it('summaryNumbers with filter', () => {
const counts = getSummary(res, t => t.name?.indexOf('should have') !== -1);

Expand Down

0 comments on commit 53cd070

Please sign in to comment.