newman: "TypeError: Cannot read property '0' of undefined" when test fail in jenkins

  1. Newman Version (can be found via newman -v): newman -v 3.4.2

  2. OS details (type, version, and architecture): CentOS 6.8 and newman_alpine33 docker image

  3. Are you using Newman as a library, or via the CLI? CLI

  4. Did you encounter this recently, or has this bug always been there: when

  5. Expected behaviour:

  6. Command / script used to run Newman:

  7. Sample collection, and auxilliary files (minus the sensitive details):

  8. Screenshots (if applicable):

when newman in jenkins and if fail test, newman gets error in cell.js

image

but sucessful in CLI image

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 22 (4 by maintainers)

Most upvoted comments

What worked for me was not using -t in the docker run command. My exact syntax was:

docker run -v $temp_folder/postman:/etc/newman \
  postman/newman_alpine33 \
  --collection="my_collection.json" \
  --environment="my_environment.json" \
  --testReportFile="/path/to/results.xml"

@kunagpal what was the solution to close this issue?

any news here?

I’m running into this issue running the newman docker container in a Jenkins pipeline, I’ve found that adding the --reporter-cli-no-failures flag to my command gets me past the failure until this is fixed.

I was also experiencing this issue. My hypothesis is that this occurs because newman explicitly calls cli-table2 with colWidths = undefined. You can see this exact behavior for example with a free-style jenkins pipeline project with this definition:

sh """
    npm install cli-table2
    
    echo "var Table = require('cli-table2');" > script.js
    echo "var table = new Table({ head: ['TH 1 label', 'TH 2 label'], colWidths: undefined });" >> script.js
    echo "table.push(['First value', 'Second value']);" >> script.js
    echo "console.log(table.toString());" >> script.js
    
    node script.js
"""

This will provide output like this:

+ node script.js
/var/jenkins_home/workspace/test3/node_modules/cli-table2/src/cell.js:52
  var fixedWidth = tableOptions.colWidths[this.x];
                                         ^

TypeError: Cannot read property '0' of undefined
    at Cell.mergeTableOptions (/var/jenkins_home/workspace/test3/node_modules/cli-table2/src/cell.js:52:42)

I think the error is inside the parseFailures function in index.js when setting colWidths. Here’s the relevant snippet:

colWidths: cliUtils.noTTY() ? [] : (function (size, indexOrder) {
    var colWidths;

    if (size.exists && size.width && (size.width > 20)) {
        colWidths = [];
        colWidths[0] = indexOrder + 3;
        colWidths[1] = parseInt((size.width - colWidths[0]) * 0.2, 10);
        colWidths[2] = parseInt(size.width - (colWidths[0] + colWidths[1] + 5), 10);
    }

    return colWidths;
}(cliUtils.dimension(), Number(failures.length.toString().length)))

In cases where the if statement is false the colWidths will end up with the invalid value of undefined.

The fix at first sight seems to be simply to initialize the var directly with [].