Closed lerouxb closed 6 years ago
Actually..
This is what I came up with:
'use strict';
let failed = false;
module.exports = function () {
return {
name: 'teenytest-bail',
supervisors: {
userFunction: function (runUserFunction, metadata, cb) {
if (failed) {
if (metadata.subType === 'test') {
console.log('# skip', metadata.description);
}
return cb();
}
runUserFunction(function bailWrappedCallback (err, result) {
if (err) {
failed = true;
}
cb(err, result);
});
}
}
};
};
Nice! Does that work for you? I might use this myself.
In most testing frameworks I've used, what you're describing is frequently called "fail fast" and toggled with a --fail-fast
flag. However I think you should name and publish this however you like!
It works like that, but it would be nice if it could be controlled from a CLI parameter before I publish it anywhere. I most recently used lab which calls it --bail
. Mocha calls it --bail
too, I believe.
Again, the naming is totally your call! --fail-fast
is an RSpec/Rubyism.
Also, it's been a couple years—does our API expose any way to add CLI flags?
Regardless, I suppose you could parse process.argv
yourself in this plugin, and depending its config, figure out what the plugin should do.
https://github.com/lerouxb/teenytest-bail https://www.npmjs.com/package/teenytest-bail
I'm aware of the irony of it not having tests ;)
Thanks @lerouxb -- would you mind opening a PR on teenytest to share the extension on the Readme?
I'd like to add support for a
--bail
cli parameter or a plugin that does that or something in my helper.. Basically it should stop testing the moment a test fails. I've read through the documentation on writing plugins, but it isn't immediately obvious to me how I would implement that. Any tips?