Skip to content

Commit 51287ae

Browse files
committed
Added in (configurable). Thanks to [@kschillz](https://github.com/kschillz)
Added CHANGELOG.md file Fixed typo in scenarioAsSuite. Thanks again to [@kschillz](https://github.com/kschillz) Removed obsolete .npmignore Changed package.json
1 parent 0d9f33f commit 51287ae

File tree

7 files changed

+167
-32
lines changed

7 files changed

+167
-32
lines changed

.npmignore

Lines changed: 0 additions & 9 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
5+
## [0.1.3] - 2019-03-25
6+
### Added
7+
- `<properties...>` in `<testcase...>` (configurable). Thanks to [@kschillz](https://github.com/kschillz)
8+
- this file
9+
10+
### Fixed
11+
- typo in scenarioAsSuite. Thanks again to [@kschillz](https://github.com/kschillz)
12+
13+
### Removed
14+
- obsolte .npmignore

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ You can configure formatter via `--format-options <JSON-OPTIONS>`:
2424
| --- | ---- | ----------- |
2525
| `scenarioAsStep` | `false` | If set to true means that feature is an testsuite and scenario is a step in test suite. Default value false (means that scenario is testsuite)
2626
|`withPackage` | `false` | If set then formatter add `package` attribute to `testsuite` element. Default value `false`.
27+
| `propertiesInTestcase` | `false` | Add `<properties...>` to `<testcase...>`. Works only with `scenarioAsStep=true`
2728

2829

2930
## References

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class JUnitFormatter extends Formatter {
138138
}
139139
];
140140

141-
if (pickle.tags.length) {
141+
if (pickle.tags.length && options.propertiesInTestcase) {
142142
testCaseTag.push({properties:pickle.tags.map(tag=>createProperty("tag",tag.name))});
143143
}
144144

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"author": "Vasyl Moskalov <vasyl@h2i.sg>",
4343
"license": "MIT",
4444
"main": "index.js",
45+
"files": [],
4546
"dependencies": {
4647
"xml": "^1.0.1"
4748
},

test/testAsStep.js

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,3 +474,131 @@ describe('JunitFormatter with scenarioAsStep=true', () => {
474474

475475

476476
});
477+
478+
describe('JunitFormatter with scenarioAsStep=true, propertiesInTestcase=true', () => {
479+
beforeEach(function() {
480+
this.eventBroadcaster = new EventEmitter()
481+
this.output = ''
482+
const logFn = data => {
483+
this.output += data
484+
}
485+
this.junitFormatter = new JunitFormatter({
486+
eventBroadcaster: this.eventBroadcaster,
487+
eventDataCollector: new formatterHelpers.EventDataCollector(this.eventBroadcaster),
488+
log: logFn,
489+
scenarioAsStep:true,
490+
propertiesInTestcase:true
491+
})
492+
})
493+
494+
describe('one scenario with one step', () => {
495+
beforeEach(function() {
496+
const events = Gherkin.generateEvents(
497+
'@tag1 @tag2\n' +
498+
'Feature: my feature\n' +
499+
'my feature description\n' +
500+
'Scenario: my scenario\n' +
501+
'my scenario description\n' +
502+
'Given my step',
503+
'a.feature'
504+
)
505+
events.forEach(event => {
506+
this.eventBroadcaster.emit(event.type, event)
507+
if (event.type === 'pickle') {
508+
this.eventBroadcaster.emit('pickle-accepted', {
509+
type: 'pickle-accepted',
510+
pickle: event.pickle,
511+
uri: event.uri,
512+
})
513+
}
514+
})
515+
this.testCase = { sourceLocation: { uri: 'a.feature', line: 4 } }
516+
})
517+
518+
describe('passed', () => {
519+
beforeEach(function() {
520+
this.eventBroadcaster.emit('test-case-prepared', {
521+
sourceLocation: this.testCase.sourceLocation,
522+
steps: [
523+
{
524+
sourceLocation: { uri: 'a.feature', line: 6 },
525+
},
526+
],
527+
})
528+
this.eventBroadcaster.emit('test-step-finished', {
529+
index: 0,
530+
testCase: this.testCase,
531+
result: { duration: 1, status: Status.PASSED },
532+
})
533+
this.eventBroadcaster.emit('test-case-finished', {
534+
sourceLocation: this.testCase.sourceLocation,
535+
result: { duration: 1, status: Status.PASSED },
536+
})
537+
this.eventBroadcaster.emit('test-run-finished')
538+
})
539+
540+
it('outputs the feature', function() {
541+
expect(this.output).to.equal('<?xml version="1.0" encoding="UTF-8"?>\n'+
542+
'<testsuites>\n'+
543+
' <testsuite name="my-feature" tests="1" failures="0" skipped="0" errors="0" time="0.001">\n'+
544+
' <testcase classname="my-scenario" name="my scenario" time="0.001">\n'+
545+
' <properties>\n'+
546+
' <property name="tag" value="@tag1">\n'+
547+
' </property>\n'+
548+
' <property name="tag" value="@tag2">\n'+
549+
' </property>\n'+
550+
' </properties>\n'+
551+
' </testcase>\n'+
552+
' </testsuite>\n'+
553+
'</testsuites>'
554+
);
555+
})
556+
})
557+
558+
describe('failed', () => {
559+
beforeEach(function() {
560+
this.eventBroadcaster.emit('test-case-prepared', {
561+
sourceLocation: this.testCase.sourceLocation,
562+
steps: [
563+
{
564+
sourceLocation: { uri: 'a.feature', line: 6 },
565+
},
566+
],
567+
})
568+
this.eventBroadcaster.emit('test-step-finished', {
569+
index: 0,
570+
testCase: this.testCase,
571+
result: { duration: 1, exception: 'my error', status: Status.FAILED },
572+
})
573+
this.eventBroadcaster.emit('test-case-finished', {
574+
sourceLocation: this.testCase.sourceLocation,
575+
result: { duration: 1, status: Status.FAILED },
576+
})
577+
this.eventBroadcaster.emit('test-run-finished')
578+
})
579+
580+
it('includes the error message', function() {
581+
expect(this.output).to.equal('<?xml version="1.0" encoding="UTF-8"?>\n'+
582+
'<testsuites>\n'+
583+
' <testsuite name="my-feature" tests="1" failures="1" skipped="0" errors="0" time="0.001">\n'+
584+
' <testcase classname="my-scenario" name="my scenario" time="0.001">\n'+
585+
' <properties>\n'+
586+
' <property name="tag" value="@tag1">\n'+
587+
' </property>\n'+
588+
' <property name="tag" value="@tag2">\n'+
589+
' </property>\n'+
590+
' </properties>\n'+
591+
' <failure message="undefined">my error</failure>\n'+
592+
' </testcase>\n'+
593+
' </testsuite>\n'+
594+
'</testsuites>'
595+
);
596+
597+
598+
})
599+
})
600+
601+
})
602+
603+
604+
})

test/testAsSuite.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ describe('JunitFormatter with scenarioAsStep=false', () => {
8383
expect(this.output).to.equal('<?xml version="1.0" encoding="UTF-8"?>\n'+
8484
'<testsuites>\n'+
8585
' <testsuite name="my-feature;my-scenario" tests="1" failures="0" skipped="0" errors="0" time="0.001">\n'+
86-
' <properites>\n'+
86+
' <properties>\n'+
8787
' <property name="tag" value="@tag1">\n'+
8888
' </property>\n'+
8989
' <property name="tag" value="@tag2">\n'+
9090
' </property>\n'+
91-
' </properites>\n'+
91+
' </properties>\n'+
9292
' <testcase classname="my-step" name="my step" time="0.001">\n'+
9393
' </testcase>\n'+
9494
' </testsuite>\n'+
@@ -123,12 +123,12 @@ describe('JunitFormatter with scenarioAsStep=false', () => {
123123
expect(this.output).to.equal('<?xml version="1.0" encoding="UTF-8"?>\n'+
124124
'<testsuites>\n'+
125125
' <testsuite name="my-feature;my-scenario" tests="1" failures="1" skipped="0" errors="0" time="0.001">\n'+
126-
' <properites>\n'+
126+
' <properties>\n'+
127127
' <property name="tag" value="@tag1">\n'+
128128
' </property>\n'+
129129
' <property name="tag" value="@tag2">\n'+
130130
' </property>\n'+
131-
' </properites>\n'+
131+
' </properties>\n'+
132132
' <testcase classname="my-step" name="my step" time="0.001">\n'+
133133
' <failure message="undefined">my error</failure>\n'+
134134
' </testcase>\n'+
@@ -172,12 +172,12 @@ describe('JunitFormatter with scenarioAsStep=false', () => {
172172
expect(this.output).to.equal('<?xml version="1.0" encoding="UTF-8"?>\n'+
173173
'<testsuites>\n'+
174174
' <testsuite name="my-feature;my-scenario" tests="1" failures="0" skipped="0" errors="1" time="0.001">\n'+
175-
' <properites>\n'+
175+
' <properties>\n'+
176176
' <property name="tag" value="@tag1">\n'+
177177
' </property>\n'+
178178
' <property name="tag" value="@tag2">\n'+
179179
' </property>\n'+
180-
' </properites>\n'+
180+
' </properties>\n'+
181181
' <testcase classname="my-step" name="my step" time="0.001">\n'+
182182
' <error message="undefined">Multiple step definitions match:\n' +
183183
' pattern1 - steps.js:3\n' +
@@ -225,12 +225,12 @@ describe('JunitFormatter with scenarioAsStep=false', () => {
225225
expect(this.output).to.equal('<?xml version="1.0" encoding="UTF-8"?>\n'+
226226
'<testsuites>\n'+
227227
' <testsuite name="my-feature;my-scenario" tests="1" failures="0" skipped="0" errors="0" time="0.001">\n'+
228-
' <properites>\n'+
228+
' <properties>\n'+
229229
' <property name="tag" value="@tag1">\n'+
230230
' </property>\n'+
231231
' <property name="tag" value="@tag2">\n'+
232232
' </property>\n'+
233-
' </properites>\n'+
233+
' </properties>\n'+
234234
' <testcase classname="my-step" name="my step" time="0.000">\n'+
235235
' </testcase>\n'+
236236
' </testsuite>\n'+
@@ -262,12 +262,12 @@ describe('JunitFormatter with scenarioAsStep=false', () => {
262262
expect(this.output).to.equal('<?xml version="1.0" encoding="UTF-8"?>\n'+
263263
'<testsuites>\n'+
264264
' <testsuite name="my-feature;my-scenario" tests="1" failures="0" skipped="0" errors="1" time="0.001">\n'+
265-
' <properites>\n'+
265+
' <properties>\n'+
266266
' <property name="tag" value="@tag1">\n'+
267267
' </property>\n'+
268268
' <property name="tag" value="@tag2">\n'+
269269
' </property>\n'+
270-
' </properites>\n'+
270+
' </properties>\n'+
271271
' <testcase classname="my-scenario-before" name="my scenario before" time="0.001">\n'+
272272
' <error message="undefined">my error</error>\n'+
273273
' </testcase>\n'+
@@ -308,12 +308,12 @@ describe('JunitFormatter with scenarioAsStep=false', () => {
308308
expect(this.output).to.equal('<?xml version="1.0" encoding="UTF-8"?>\n'+
309309
'<testsuites>\n'+
310310
' <testsuite name="my-feature;my-scenario" tests="2" failures="0" skipped="0" errors="1" time="0.001">\n'+
311-
' <properites>\n'+
311+
' <properties>\n'+
312312
' <property name="tag" value="@tag1">\n'+
313313
' </property>\n'+
314314
' <property name="tag" value="@tag2">\n'+
315315
' </property>\n'+
316-
' </properites>\n'+
316+
' </properties>\n'+
317317
' <testcase classname="my-step" name="my step" time="0.000">\n'+
318318
' </testcase>\n'+
319319
' <testcase classname="my-scenario-after" name="my scenario after" time="0.001">\n'+
@@ -357,12 +357,12 @@ describe('JunitFormatter with scenarioAsStep=false', () => {
357357
expect(this.output).to.equal('<?xml version="1.0" encoding="UTF-8"?>\n'+
358358
'<testsuites>\n'+
359359
' <testsuite name="my-feature;my-scenario" tests="1" failures="1" skipped="0" errors="0" time="0.001">\n'+
360-
' <properites>\n'+
360+
' <properties>\n'+
361361
' <property name="tag" value="@tag1">\n'+
362362
' </property>\n'+
363363
' <property name="tag" value="@tag2">\n'+
364364
' </property>\n'+
365-
' </properites>\n'+
365+
' </properties>\n'+
366366
' <testcase classname="my-step" name="my step" time="0.000">\n'+
367367
' <failure message="Pending">Pending</failure>\n'+
368368
' </testcase>\n'+
@@ -403,12 +403,12 @@ describe('JunitFormatter with scenarioAsStep=false', () => {
403403
expect(this.output).to.equal('<?xml version="1.0" encoding="UTF-8"?>\n'+
404404
'<testsuites>\n'+
405405
' <testsuite name="my-feature;my-scenario" tests="1" failures="1" skipped="0" errors="0" time="0.001">\n'+
406-
' <properites>\n'+
406+
' <properties>\n'+
407407
' <property name="tag" value="@tag1">\n'+
408408
' </property>\n'+
409409
' <property name="tag" value="@tag2">\n'+
410410
' </property>\n'+
411-
' </properites>\n'+
411+
' </properties>\n'+
412412
' <testcase classname="my-step" name="my step" time="0.000">\n'+
413413
' <failure message="Undefined step. Implement with the following snippet:">Undefined step. Implement with the following snippet:\n'+
414414
' Given(/^my step$/, function(callback) {\n'+
@@ -453,12 +453,12 @@ describe('JunitFormatter with scenarioAsStep=false', () => {
453453
expect(this.output).to.equal('<?xml version="1.0" encoding="UTF-8"?>\n'+
454454
'<testsuites>\n'+
455455
' <testsuite name="my-feature;my-scenario" tests="1" failures="0" skipped="1" errors="0" time="0.001">\n'+
456-
' <properites>\n'+
456+
' <properties>\n'+
457457
' <property name="tag" value="@tag1">\n'+
458458
' </property>\n'+
459459
' <property name="tag" value="@tag2">\n'+
460460
' </property>\n'+
461-
' </properites>\n'+
461+
' </properties>\n'+
462462
' <testcase classname="my-step" name="my step" time="0.000">\n'+
463463
' <skipped>\n'+
464464
' </skipped>\n'+
@@ -555,22 +555,22 @@ describe('JunitFormatter with scenarioAsStep=false', () => {
555555
expect(this.output).to.equal('<?xml version="1.0" encoding="UTF-8"?>\n'+
556556
'<testsuites>\n'+
557557
' <testsuite name="my-feature;my-scenario" tests="1" failures="0" skipped="0" errors="0" time="0.001">\n'+
558-
' <properites>\n'+
558+
' <properties>\n'+
559559
' <property name="tag" value="@tag1">\n'+
560560
' </property>\n'+
561561
' <property name="tag" value="@tag2">\n'+
562562
' </property>\n'+
563-
' </properites>\n'+
563+
' </properties>\n'+
564564
' <testcase classname="my-step" name="my step" time="0.001">\n'+
565565
' </testcase>\n'+
566566
' </testsuite>\n'+
567567
' <testsuite name="my-feature-1;my-scenario-1" tests="1" failures="0" skipped="0" errors="0" time="0.001">\n'+
568-
' <properites>\n'+
568+
' <properties>\n'+
569569
' <property name="tag" value="@tag1">\n'+
570570
' </property>\n'+
571571
' <property name="tag" value="@tag2">\n'+
572572
' </property>\n'+
573-
' </properites>\n'+
573+
' </properties>\n'+
574574
' <testcase classname="my-step-1" name="my step 1" time="0.001">\n'+
575575
' </testcase>\n'+
576576
' </testsuite>\n'+

0 commit comments

Comments
 (0)