jeudi 28 mars 2019

Spec mocha reporter doesn't produce correct output in terminal while webstorm does

I am trying to write mocha tests for rest api calls for my backend. I wrote a basic test and it displays output properly when I see in IDE. But on running npm run test, the command produces random output as mentioned below. Following are my files for reference:

index.spec.ts with rest api tests

process.env.NODE_ENV = 'test';

import 'mocha';
import * as chai from 'chai';
import {server} from "../../bin/www";

const expect = chai.expect;

import chaiHttp = require("chai-http");

chai.use(chaiHttp);

describe("Hello API Request", function () {

    it("should return status 200", async () => {
        const request = chai.request(server);
        const res = await request.get("/");
        expect(res.status).to.eql(200);
    });

    it("should return status 400", async () => {
        const request = chai.request(server);
        const res = await request.get("/");
        expect(res.status).to.eql(400);
    });
});


package.json file

{
  "name": "co-admin-backend",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "ts-node ./bin/www",
    "tslint": "./node_modules/.bin/tslint --project tsconfig.json",
    "build": "npm run tslint && tsc",
    "test": "./node_modules/.bin/mocha --require ts-node/register test/**/*.spec.ts"
  },
  "dependencies": {
    "@types/node": "^10.11.0",
    "archiver": "^3.0.0",
    "body-parser": "~1.18.2",
    "child-process-promise": "^2.2.1",
    "cookie-parser": "~1.4.3",
    "cors": "~2.8.3",
    "csv-parse": "^3.2.0",
    "debug": "~4.1.0",
    "express": "~4.16.0",
    "firebase-admin": "^6.1.0",
    "fs-extra": "^7.0.0",
    "instagram-private-api": "^0.6.8",
    "jsonwebtoken": "~8.4.0",
    "mkdirp": "^0.5.1",
    "mkdirp-promise": "^5.0.1",
    "moment": "^2.22.1",
    "morgan": "^1.9.1",
    "multer": "^1.3.0",
    "p-limit": "^2.1.0",
    "request": "~2.88.0",
    "request-promise": "^4.2.2",
    "rotating-file-stream": "^1.3.9"
  },
  "devDependencies": {
    "@types/chai": "^4.1.7",
    "@types/mocha": "^5.2.6",
    "chai": "^4.2.0",
    "chai-http": "^4.2.1",
    "eslint": "^4.13.1",
    "eslint-plugin-promise": "^4.0.1",
    "mocha": "^6.0.2",
    "nodemon": "^1.18.10",
    "ts-node": "^7.0.1",
    "tslint": "^5.11.0",
    "typescript": "^3.2.1"
  }
}

Test for comparing 2 numbers work fine

index.spec.ts output with normal test

The output for api request is obtained fine here in Webstorm

index.spec.ts output with api request test

The output for api request is not shown properly in terminal

package.json file

I want to fix the terminal output when I run npm run test. Any ideas how this could be fixed?

Aucun commentaire:

Enregistrer un commentaire