Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
sertal70 opened this issue Jan 12, 2024 · 3 comments
Closed
1 task done
Labels
state: needs-triage This issue needs to be triaged type: bug Something isn't working

Comments

@sertal70
Copy link

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

@sertal70 sertal70 added state: needs-triage This issue needs to be triaged type: bug Something isn't working labels Jan 12, 2024
Copy link

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 sertal70 changed the title TypeError "cannot read propertied of undefined" when using Collection object TypeError "cannot read properties of undefined" when using Collection object Jan 12, 2024
@sertal70
Copy link
Author

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());

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
state: needs-triage This issue needs to be triaged type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant