1

I am using mocha, chai, supertest & nyc for my test cases. All of my test cases are working as expected. But I am not able to see the total count of test cases at the end.

21 passing (150ms)       // <--- these counts are missing in console
1 failing (150ms)       // <--- these counts are missing in console

I am not able to see how many test cases are passed (or failed). It just executes them all and quit the process.

This is how my test cases are structured:

describe("GET /", () => {
   it("should return all users", async () => {
      await model.insertMany(users);
      const res = await request(app).get("/users");
      expect(res.status).to.equal(200);
      expect(res.body.data.length).to.equal(2);
   });
});

And this is how run it: with npm test:

  "scripts": {
    "start": "node index.js",
    "test": "NODE_ENV=test nyc --reporter=html --reporter=text mocha --exit --timeout 15000"
  }

Version:

node - v11.15.0
npm - 6.7.0
mocha - 6.2.1
chai - 4.2.0
nyc - 14.1.1
supertest - 4.0.2

Any leads will be appreciated :)

Mohammed Amir Ansari
  • 2,311
  • 2
  • 12
  • 26

2 Answers2

0

Seems you set wrong mocha reporters to html and text. html reporter is not suitable for console and text reporter doesn't exist. Ref: https://mochajs.org/#reporters

The workaround is to remove --reporter=xxx then Mocha will use default spec reporter e.g

"test": "NODE_ENV=test nyc mocha --exit --timeout 15000"

If you keep insisting to use multi reporters, you could use this lib https://www.npmjs.com/package/mocha-multi-reporters

Hope it helps

deerawan
  • 8,002
  • 5
  • 42
  • 51
0

To be honest I am bit perplexed about that thing. Apparently out of all included reporters only tap seem to include a comment with total failed, passed and skipped at the end.

My guess is that mocha creators assumed that because they return an error code that counts the number of failures, there is no need for it.

That decision of returning the number of failed tests as RC code is mind-blowing, and clearly against POSIX specification.

sorin
  • 161,544
  • 178
  • 535
  • 806