DannyDainton / newman-reporter-htmlextra

A HTML reporter for Postman's Command Line Runner, Newman. Includes Non Aggregated Runs broken down by Iterations, Skipped Tests, Console Logs and the handlebars helpers module for better custom templates.
Apache License 2.0
357 stars 140 forks source link

TypeError "cannot read properties of undefined" when using Collection object #427

Closed sertal70 closed 10 months ago

sertal70 commented 10 months ago

Is There An Existing Issue

What Are You Seeing

Hi, I'm trying to execute runs with newman as library by loading a collection via SDK, in a way similar to:

const newman = require('newman');
const Collection = require('postman-collection').Collection;

const myCollection = new Collection(fs.readFileSync('./my-collection.json').toString());
newman
   .run({
     collection: myCollection,
     reporters: ['htmlextra'],
     reporter: {
       htmlextra: {
         export: './report.html',
       },
     },
  })
  .on('done', function (err, summary) {
     if (err) {
       console.err(err);
     }
     console.log(summary);
  });

When executed, this code generates the following error:

./newman-test/node_modules/newman-reporter-htmlextra/lib/index.js:377
            default: (this.summary.collection.name).match(pattern) ?
                                                    ^

TypeError: Cannot read properties of undefined (reading 'match')

If the collection is passed to newman.run() as filename:

...
newman
   .run({
     collection: require('./my-collection.json'),
...

the run completes ok and the report is produced as expected.

Is there any compatibility issue with the Postman Collection objects?

Steps To Reproduce The Issue

  1. Copy the script I posted in VSCode and save it with a name of your choice.
  2. Install needed libraries: newman, postman-collection, 'newman-reporter-htmlextra`
  3. Get the JSON file of a collection of your choice from Postman.
  4. Run the code two times: one using the Collection object in newman.run, the other using the collection file name.
  5. Observe the results

Full Newman Command Or Node Script

node <scriptname>.js

HTMLEXTRA Version

1.23.0

Newman Version

6.1.0

Additional Context

No response

github-actions[bot] commented 10 months ago

Hey @sertal70: 👋 - Thanks for helping to make the reporter better by raising this ticket. I will take a look as soon as I can and get back to you. Cheers, Danny.

sertal70 commented 10 months ago

I'm going to close this because the error was due to a missing JSON.parse() when creating the Collection object:

// right
const myCollection = new Collection(JSON.parse(fs.readFileSync('./my-collection.json').toString()));

//wrong
const myCollection = new Collection(fs.readFileSync('./my-collection.json').toString());
github-actions[bot] commented 9 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.