diff --git a/spec/e2e.spec.ts b/spec/e2e.spec.ts index 4fbf3a4..ea89567 100644 --- a/spec/e2e.spec.ts +++ b/spec/e2e.spec.ts @@ -28,7 +28,8 @@ describe('JUnit Report builder', () => { .className('suite1.test.Class2') .name('Third test') .file('./path-to/the-test-file.coffee') - .property('property name', 'property value'); + .property('property name', 'property value') + .multilineProperty('property name 2', 'property value 2'); const suite2 = builder.testSuite().name('second.Suite'); suite2.testCase().failure('Failure message'); diff --git a/spec/expected_report.xml b/spec/expected_report.xml index d0ffe04..b9ddebf 100755 --- a/spec/expected_report.xml +++ b/spec/expected_report.xml @@ -6,6 +6,7 @@ + property value 2 diff --git a/spec/test_case.spec.ts b/spec/test_case.spec.ts index 6abed5e..797801e 100644 --- a/spec/test_case.spec.ts +++ b/spec/test_case.spec.ts @@ -127,6 +127,20 @@ describe('Test Case builder', () => { }); }); + it('should add the provided property with textContent as elements with textContent', () => { + testCase.multilineProperty('property name', 'property value'); + + testCase.build(parentElement); + + expect(propertiesElement.ele).toHaveBeenCalledWith( + 'property', + { + name: 'property name', + }, + 'property value', + ); + }); + it('should add a failure node when test failed', () => { testCase.failure(); diff --git a/spec/test_suite.spec.ts b/spec/test_suite.spec.ts index 3dfa5b3..0299315 100644 --- a/spec/test_suite.spec.ts +++ b/spec/test_suite.spec.ts @@ -132,6 +132,20 @@ describe('Test Suite builder', () => { }); }); + it('should add the provided property with textContent as element with textContent', () => { + testSuite.multilineProperty('property name', 'property value'); + + testSuite.build(parentElement); + + expect(propertiesElement.ele).toHaveBeenCalledWith( + 'property', + { + name: 'property name', + }, + 'property value', + ); + }); + it('should add all the provided properties as elements', () => { testSuite.property('name 1', 'value 1'); testSuite.property('name 2', 'value 2'); diff --git a/src/test_node.ts b/src/test_node.ts index ce18ff7..33b4cf5 100644 --- a/src/test_node.ts +++ b/src/test_node.ts @@ -1,10 +1,20 @@ import _ from 'lodash'; import xmlBuilder, { type XMLElement } from 'xmlbuilder'; +/** Helper interface to describe one property */ +interface Property { + /** name of the property */ + name: string; + /** value of the property */ + value: string; + /** if true the property will be serialized as node with textcontent */ + isPropertyWithTextContent: boolean; +} + export abstract class TestNode { private _elementName: string; protected _attributes: any; - private _properties: any[]; + private _properties: Property[]; /** * @param elementName - the name of the XML element @@ -21,7 +31,17 @@ export abstract class TestNode { * @returns this */ property(name: string, value: string): this { - this._properties.push({ name: name, value: value }); + this._properties.push({ name: name, value: value, isPropertyWithTextContent: false }); + return this; + } + + /** + * @param name + * @param value + * @returns this + */ + multilineProperty(name: string, value: string): this { + this._properties.push({ name: name, value: value, isPropertyWithTextContent: true }); return this; } @@ -122,11 +142,12 @@ export abstract class TestNode { protected buildNode(element: XMLElement): XMLElement { if (this._properties.length) { var propertiesElement = element.ele('properties'); - _.forEach(this._properties, (property: any) => { - propertiesElement.ele('property', { - name: property.name, - value: property.value, - }); + _.forEach(this._properties, (property: Property) => { + if (property.isPropertyWithTextContent) { + propertiesElement.ele('property', { name: property.name }, property.value); + } else { + propertiesElement.ele('property', { name: property.name, value: property.value }); + } }); } return element;