Closed tomitrescak closed 3 years ago
If you are using wallaby.delayStart()
then the subsequent call to wallaby.start()
is expected to be asynchronous. You could change your existing code to call wallaby.start()
on 2nd execution (line 70) to setImmediate(() => wallaby.start());
or better still, refactor your code a little so that you are not maintaining the delayed
state and only call wallaby.delayStart()
on the first execution as shown below. If you have any further problems, please let us know.
wallaby.js
// @ts-nocheck
// eslint-disable-next-line @typescript-eslint/no-var-requires
var path = require('path');
module.exports = function (wallaby) {
process.env.NODE_PATH += path.delimiter + path.join(wallaby.projectCacheDir, 'src');
return {
files: ['src/**/*.ts', 'src/**/*.tsx', '!src/**/*.test.ts?(x)'],
tests: ['src/**/*.test.ts?(x)'],
env: {
type: 'node',
NODE_ENV: 'test',
BASE_URL: 'http://localhost:3000'
},
testFramework: 'mocha',
compilers: {
'**/*.ts?(x)': wallaby.compilers.babel({
presets: ['next/babel'],
plugins: [
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties', { loose: true }]
]
})
},
delays: {
run: 1000
},
workers: {
initial: 1,
regular: 1
},
reportUnhandledPromises: true,
setup: function (wallaby) {
- wallaby.delayStart();
- var delayed = false;
require.extensions['.css'] = () => {
/* */
};
if (!global.db) {
- delayed = true;
+ wallaby.delayStart();
console.log('Spinning new db');
require('apollo-connector-mongodb/dist/testing')
.getDb()
.then(db => {
console.log('Started new database instance!');
global.db = db;
wallaby.start();
});
console.log('Starting new database instance!');
}
if (!global.document) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
global.jsdom = require('jsdom-global')(undefined, {
url: 'http://localhost'
});
}
const mocha = wallaby.testFramework;
mocha.suite.on('pre-require', function () {
require(wallaby.projectCacheDir + '/src/mocha.config');
const cleanup = require('@testing-library/react').cleanup;
afterEach(cleanup);
});
- if (!delayed) {
- wallaby.start();
- }
},
teardown: function (wallaby) {
// console.log(global.db);
// global.db.stop();
console.log('Database Teardown ..');
// global.jsdom();
}
};
};
Issue description or question
Hi, I am trying to use Mocha with Wallaby but I keep randomly getting following error: "Mocha instance is currently running tests, cannot start a next test run until this one is done"
Also, I tried to implement database initialisation with delayedStart and now I get this error on EVERY SECOND run. That is, once, all runs well, on second time I get this error.
Wallaby diagnostics report