bhecquet / newman-reporter-xunit

A Newman JUnit Reporter providing full reports (without aggregation of results)
Apache License 2.0
2 stars 3 forks source link

Error: Missing attribute value. attribute: {value}, parent: <property> when a used environment variable is not set #7

Closed naasse closed 2 years ago

naasse commented 2 years ago

This stems from the original repo: https://github.com/martijnvandervlag/newman-reporter-junitfull/issues/2

I have a collection suite to test my API where I often will run pre-request scripts to setup some data before my request and tests. Sometimes, I set an environment variable inside my prerequest script that gets used in the request URL. Most notably, if I create an API resource, I might take the GUID from the response and request a PUT or DELETE to that resource in my test.

If for some reason the pre-request were to fail, the entire report crashes. Rather than getting a failure report for that test, I get an empty report back due to the null pointer.

`C:\Users\naasse\AppData\Roaming\npm\node_modules\newman-reporter-xunit\lib\index.js:121 property.att('value', propertyItem.value.substring(0, 70)); ^

TypeError: Cannot read properties of null (reading 'substring') at C:\Users\naasse\AppData\Roaming\npm\node_modules\newman-reporter-xunit\lib\index.js:121:47 at arrayEach (C:\Users\naasse\AppData\Roaming\npm\node_modules\newman-reporter-xunit\node_modules\lodash\lodash.js:530:11) at Function.forEach (C:\Users\naasse\AppData\Roaming\npm\node_modules\newman-reporter-xunit\node_modules\lodash\lodash.js:9410:14) at C:\Users\naasse\AppData\Roaming\npm\node_modules\newman-reporter-xunit\lib\index.js:89:7 at arrayEach (C:\Users\naasse\AppData\Roaming\npm\node_modules\newman-reporter-xunit\node_modules\lodash\lodash.js:530:11) at Function.forEach (C:\Users\naasse\AppData\Roaming\npm\node_modules\newman-reporter-xunit\node_modules\lodash\lodash.js:9410:14) at EventEmitter. (C:\Users\naasse\AppData\Roaming\npm\node_modules\newman-reporter-xunit\lib\index.js:72:5) at EventEmitter.emit (C:\Users\naasse\AppData\Roaming\npm\node_modules\newman\node_modules\eventemitter3\index.js:203:33) at done (C:\Users\naasse\AppData\Roaming\npm\node_modules\newman\lib\run\index.js:314:29) at C:\Users\naasse\AppData\Roaming\npm\node_modules\newman\node_modules\postman-runtime\lib\backpack\index.js:58:34 at PostmanCollectionRun._process (C:\Users\naasse\AppData\Roaming\npm\node_modules\newman\node_modules\postman-runtime\lib\runner\run.js:163:13) at PostmanCollectionRun. (C:\Users\naasse\AppData\Roaming\npm\node_modules\newman\node_modules\postman-runtime\lib\runner\run.js:169:76) at listOnTimeout (node:internal/timers:557:17) at processTimers (node:internal/timers:500:7)`

It's an easy fix, we just need a null check there. If it's set to the empty string instead of null, XMLAttribute will parse it fine and the reporter will carry on.

naasse commented 2 years ago

Please consider merging in my PR. Thanks!

bhecquet commented 2 years ago

Thank you for your PR, this is a case I did not see