-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests stop after uncaught first exception. #172
Comments
@tosbaha thank you for posting the issue. That sounds weird, I will take a look soon. |
The newly published |
Thanks for such a fast fix. I really appreciate it. It works for my purposes but, it doesn't work for following scenario. Put following code |
@tosbaha not a problem. Unfortunately I can't reproduce your issue: in my case I can see that the test finishes with an "end" event: describe('suite', function () {
it('throw exception immediately', function () {
throw new Error('foo');
});
// eslint-disable-next-line no-unused-vars
it('throw exception in setTimeout', function (done) {
setTimeout(() => {
throw new Error('foo');
}, 100);
});
it('should pass', () => {
// eslint-disable-next-line no-unused-vars
const a = 2;
});
it('throw exception in promise', () => {
return new Promise(() => {
throw new Error('foo');
});
});
it('require unknown package', () => {
require('packagedoesnotexist');
});
it('should pass', () => {
// eslint-disable-next-line no-unused-vars
const a = 2;
});
}); Can you create a gist/repo so that I could reproduce it? |
For me it is giving me an error. Here is my test setup. 1.test.js const abcd = require('thisdoesntexist');
describe('First Test:', function() {
it('should crash', function (done) {
done();
});
}); 2.test.js describe('Second Test', function() {
it('case 2', function (done) {
setTimeout(() => {
throw new Error('foo');
}, 100);
});
}); 3.test.js describe('Third Test:', function() {
it('should work', function (done) {
console.log('Third Test OK');
done();
});
}); 4.test.js describe('Fourth Test:', function() {
it('should work too', function (done) {
console.log('Fourth Test OK');
done();
});
}); Testing Codeconst Mocha = require('mocha-parallel-tests').default;
const glob = require('glob-promise');
const mocha = new Mocha({
bail:false,
reporter: 'mochawesome',
reporterOptions: {
reportTitle: 'My Tests',
reportPageTitle: 'Health Check',
json: true,
html: true,
code: false,
// quiet: true
}
});
class HealthCheck {
async getMocha() {
const specs = await glob('./testfolder/*.js', {absolute: true});
console.log(specs);
specs.map(spec => {
mocha.addFile(spec);
});
mocha.suite.timeout(60000);
return mocha;
}
async checkIt() {
return new Promise(async (resolve) => {
const mocha = await this.getMocha();
const runner = await mocha.run();
let testError = null;
runner.on('end', () => {
console.log('Final end!');
if (testError) console.error(testError.err);
resolve();
});
});
}
}
(async() => {
try {
const health = new HealthCheck();
const result = await health.checkIt();
console.log('Result: ' + result);
} catch (e) {
console.log('Error: ' + e);
}
})(); PS: I tested with or without mochawesome. It always crashes and stop processing other test files. |
This is pretty expected: if you run your code with Neat pick: in your code |
Thanks again for the feedback. I thought maybe there was a way to catch all kind of errors. |
Cheers, mate 😎 |
I have multiple test files. I want to run them in parallel programmatically. If one of the test files fail with Uncaught exception, testing stops. I checked the source code and saw that you are using process.exit after
Uncaught exception
I tried to setbail:false
but it didn't change anything.TLDR; I want to run all test files in parallel and get a report at the end even if one the tests are failed/crashed.
The text was updated successfully, but these errors were encountered: