mocha-parallel-tests icon indicating copy to clipboard operation
mocha-parallel-tests copied to clipboard

Mocha-parallel-tests doesn't show full AssertionError message for nested objects

Open thespecial opened this issue 6 years ago • 4 comments

Stack: mocha, nodejs, chai (expect) Mac OS X, Linux (Jenkins)

Code to run tests in parallel programmatically:

const fs = require('fs');
const Mocha = require('mocha-parallel-tests').default

const mocha = new Mocha({
  ui: 'bdd',
  reporter: 'mocha-spec-json-output-reporter',
  timeout: 200000
});

files = fs.readdirSync(`${__dirname}/test1`);
files.forEach((file) => {
  if (file.match(/(\S+.js)$/)) {
    mocha.addFile(`${__dirname}/test1/${file}`);
  }
})

mocha.run((failures) => {
  process.on('exit', () => {
    process.exit(failures);
  });
});

Test itself:

const expect = require('chai').expect;

describe('Test 2', function () {
    it(`is expected response`, () => {
        expect({a:3, b:4, c: [ {a: "b", c: "d"}, {a: "b", c: "d"}]}).to.eql({a:1, b:2});
    });
});

For example, if in my tests I assert using chai objects expect({a:3, b:4, c: [ {a: "b", c: "d"}, {a: "b", c: "d"}]}).to.eql({a:1, b:2});, then I get such log (2) so for nested objects assertion error is cut (the same goes to json output).

   Test 1
      1) is expected pprod response to equal prod response


    Test 2
      2) is expected pprod response to equal prod response


  0 passing (6s)
  2 failing

  1)
       Test 1
         is expected pprod response to equal prod response:
     AssertionError: expected { a: 3, b: 4 } to deeply equal { a: 1, b: 2 }
      at Context.it (test1/test1.js:23:31)

  2)
       Test 2
         is expected pprod response to equal prod response:
     AssertionError: expected { Object (a, b, ...) } to deeply equal { a: 1, b: 2 }
      at Context.it (test1/test2.js:22:73)

I would expect getting normal log as when run sequentially:

Test 2
    1) is expected pprod response to equal prod response


  0 passing (1s)
  1 failing

  1) Test 2
       is expected pprod response to equal prod response:

      AssertionError: expected { Object (a, b, ...) } to deeply equal { a: 1, b: 2 }
      + expected - actual

       {
      -  "a": 3
      -  "b": 4
      -  "c": [
      -    {
      -      "a": "b"
      -      "c": "d"
      -    }
      -    {
      -      "a": "b"
      -      "c": "d"
      -    }
      -  ]
      +  "a": 1
      +  "b": 2
       }

Could someone suggest what to do in such case? Thanks in advance.

thespecial avatar Feb 06 '19 22:02 thespecial

@thespecial did you try --full-trace option?

1999 avatar Feb 14 '19 20:02 1999

@1999 yes, that didn't help.

I did smth like this:

node_modules/.bin/mocha-parallel-tests --full-trace test1.js

thespecial avatar Feb 15 '19 12:02 thespecial

@1999 please, check the PR.

thespecial avatar Feb 15 '19 23:02 thespecial

Hi there, how do i get a new mocha-parallel-tests version which got this issue fixed?

richard-hor-bgl avatar Jun 08 '21 00:06 richard-hor-bgl