mercredi 29 juillet 2020

Mocha failing to run simple test

I have a project in Node JS 8. These are my current versions :

 $ node --version
v8.17.0
 $ node_modules/.bin/mocha --version
6.2.3

I have a really simple endpoint and a really simple test. However the tests fail with an error in Mocha itself :

.../node_modules/mocha/lib/cli/options.js:108
      const pair = arg.split('=');

TypeError: arg.split is not a function

This is my test :

const app = require('../app.js')
const chai = require('chai')
const request = require('supertest')

var expect = chai.expect

describe('app.js', function() {
    describe('test', function() { 
        it('should reply ok', function(done) { 
          request(app) .post('/hello') .send('test') .end(function(err, res) { 
            expect(res.statusCode).to.equal(200); 
            expect(res.body).to.equal('test'); 
            done(); 
          }); 
        }); 
      }); 
});

What might I be doing wrong?

Note :

This is a snippet to demonstrate how I am running the tests :

"scripts": {
    "test": "NODE_ENV=test node_modules/.bin/mocha — timeout 10000"
  },

This is my packages tree list :

npm list --depth=0
...
├── chai@4.2.0
├── express@4.17.1
├── mocha@6.2.3
└── supertest@4.0.2

And my project structure :

$ find . | grep -v node_modules
.
./tests
./tests/test.js
./README.md
./package-lock.json
./package.json
./middleware.js
./app.js

Aucun commentaire:

Enregistrer un commentaire