Expresso project - mocha tests problem

Hey folks,

I am working on the Expresso project Expresso project in the web development path and I am having problems with the test run to check the code.

I experience two problems:

  • When I run the tests by typing “npm test” only a part of them is shown, like 1/3 of them.

  • The console hangs and doesn’t return back to the user.

Can you help me understand why this is happening?

Here I have pasted the main project files I am working on.

NOTE: I have tried to include the test.js file, but it’s too long.

server.js

const express = require('express');
const app = express();
const PORT = process.env.PORT || 4000;

const errorHandler = require('errorhandler');

const apiRouter = require('./api/api');

app.use('/api', apiRouter);

app.use(errorHandler());

app.listen(PORT, () => {
    console.log(`Listening on port ${PORT}`);
});

module.exports = app;

api.js

const express = require('express');
const apiRouter = express.Router();
const employeesRouter = require('./employees');

    // <<< api/employees >>>
apiRouter.use('/employees', employeesRouter);

module.exports = apiRouter;

employees.js

const express = require('express');
const employeesRouter = express.Router();

const sqlite = require('sqlite3');
const db = new sqlite.Database('./database.sqlite');

    // <<< api/employees >>>
employeesRouter.get('/', (req, res, next) => {
    const sql = 'SELECT * FROM Employee WHERE is_current_employee = 1';

    db.all(sql, (error, employees) => {
        if (error) {
            next(error);
        } else {
            res.status(200).json({ employees: employees });
        }
    });

});

module.exports = employeesRouter;

Hey @nik84 !

I realize this is about a year too late, but in case anyone else runs into the same issue…

I tried to get mine to make the same error and it seems that the issue is related to your sqlite3 database and Node. To fix that issue, try updating the code where you import sqlite3 and create a database to the following…

const sqlite3 = require("sqlite3");
const db = new sqlite3.Database(
  process.env.TEST_DATABASE || "./database.sqlite"
);

I have been trying to find a good article on how this works to share with you, but have not had any luck so far.

If there is anybody out that there who could explain how process.env.TEST_DATABASE works, that would be much appreciated!

Hope this helps!

Chris DeCleene