A very simplification of the code where the server starts asynchronously
// server/app.js
let appPromise = new Promise((resolve, reject) => {
[..async stuff..]
const app = express()
const server = http.createServer(app)
server.listen(config.port, config.ip, () => {...}
})
export default appPromise;
Where from I starts the tests:
// test/index.js
require('@babel/core').transform('code', {});
require('@babel/register');
let tests = require('./tests.js');
module.exports = {tests};
The code where tests are implemented:
// test/test.js
const app = require('../server/app')
const chai = require('chai')
const chaiHttp = require('chai-http')
chai.use(chaiHttp);
chai.should();
app.then(() => {
describe(..tests...)
})
The error I get:
.then() is not a function
What's going wrong?
I believe your issue is that you are using ES6 export, but not importing in the ES6 way.
Your import of "app" should be:
import appPromise from '../server/app';
Also, your promise in "app.js" doesn't seem to resolve anything, if that isn't an omission, you need to resolve something in your promise for .then() to work. Here is a working example:
const appPromise = new Promise((resolve, reject) => {
resolve('appPromise resolved');
});