@@ -8,21 +8,7 @@ function getTestCase(rawCase) {
88 const test_case = new TestCase ( ) ;
99 test_case . name = rawCase [ "name" ] ;
1010 test_case . duration = rawCase [ "duration" ] ;
11- if ( rawCase . tags && rawCase . tags . length > 0 ) {
12- const tagsArray = rawCase . tags ;
13- let tags = [ ] ;
14- let rawTags = [ ] ;
15- for ( let i = 0 ; i < tagsArray . length ; i ++ ) {
16- let rawTagName = tagsArray [ i ] [ "name" ] ;
17- let tag = rawTagName . substring ( 1 ) . split ( "=" ) ;
18- let tagName = tag [ 0 ] ;
19- test_case . meta_data . set ( tagName , tag [ 1 ] ?? "" )
20- tags . push ( tagName ) ;
21- rawTags . push ( rawTagName ) ;
22- }
23- test_case . meta_data . set ( "tags" , tags . join ( "," ) ) ;
24- test_case . meta_data . set ( "tagsRaw" , rawTags . join ( "," ) ) ;
25- }
11+ setMetaData ( rawCase , test_case ) ;
2612 if ( rawCase . state && rawCase . state === "failed" ) {
2713 test_case . status = 'FAIL' ;
2814 test_case . setFailure ( rawCase . errorStack ) ;
@@ -33,6 +19,30 @@ function getTestCase(rawCase) {
3319 return test_case ;
3420}
3521
22+ /**
23+ *
24+ * @param {import('./cucumber.result').CucumberElement } element
25+ * @param {TestCase | TestSuite } test_element
26+ */
27+ function setMetaData ( element , test_element ) {
28+ const meta_tags = [ ] ;
29+ const meta_raw_tags = [ ] ;
30+ const tags = element . tags ;
31+ if ( tags && tags . length > 0 ) {
32+ for ( const tag of tags ) {
33+ const [ name , value ] = tag [ "name" ] . substring ( 1 ) . split ( "=" ) ;
34+ if ( value ) {
35+ test_element . meta_data . set ( name , value ) ;
36+ } else {
37+ meta_tags . push ( name ) ;
38+ meta_raw_tags . push ( tag [ "name" ] ) ;
39+ }
40+ }
41+ test_element . meta_data . set ( "tags" , meta_tags . join ( "," ) ) ;
42+ test_element . meta_data . set ( "tagsRaw" , meta_raw_tags . join ( "," ) ) ;
43+ }
44+ }
45+
3646function getTestSuite ( rawSuite ) {
3747 const suite = new TestSuite ( ) ;
3848 suite . name = rawSuite [ "name" ] ;
@@ -41,6 +51,7 @@ function getTestSuite(rawSuite) {
4151 suite . failed = rawSuite [ "failures" ] ;
4252 suite . duration = rawSuite [ "duration" ] ;
4353 suite . status = suite . total === suite . passed ? 'PASS' : 'FAIL' ;
54+ setMetaData ( rawSuite , suite ) ;
4455 const raw_test_cases = rawSuite . elements ;
4556 if ( raw_test_cases ) {
4657 for ( let i = 0 ; i < raw_test_cases . length ; i ++ ) {
@@ -50,6 +61,9 @@ function getTestSuite(rawSuite) {
5061 return suite ;
5162}
5263
64+ /**
65+ * @param {import("./cucumber.result").CucumberJsonResult } json
66+ */
5367function getTestResult ( json ) {
5468 const result = new TestResult ( ) ;
5569 const { stats, suites } = preprocess ( json ) ;
@@ -74,13 +88,13 @@ function getTestResult(json) {
7488
7589/**
7690 * Function to format the raw json report
77- * @param {* } rawjson
91+ * @param {import("./cucumber.result").CucumberJsonResult } json
7892 * @returns formatted json object
7993 */
80- function preprocess ( rawjson ) {
94+ function preprocess ( json ) {
8195 const formattedResult = { stats : { } , suites : [ ] } ;
8296
83- rawjson . forEach ( testSuite => {
97+ json . forEach ( testSuite => {
8498 testSuite . elements . forEach ( testCase => {
8599 testCase . state = testCase . steps . every ( step => step . result . status === "passed" ) ? "passed" : "failed" ;
86100 testCase . duration = testCase . steps . map ( step => step . result . duration ) . reduce ( ( total , currVal ) => total + currVal , 0 ) / 1000000 ;
0 commit comments