Skip to content
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

Improve bail strategy not to execute next befores/afters #698

Merged
merged 1 commit into from Apr 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/runner.js
Expand Up @@ -285,7 +285,7 @@ internals.executeExperiments = function (experiments, state, skip, callback) {
const previousDomains = state.domains;
state.domains = [];

const skipExperiment = skip || experiment.options.skip || !internals.experimentHasTests(experiment, state);
const skipExperiment = skip || experiment.options.skip || !internals.experimentHasTests(experiment, state) || (state.options.bail && state.report.failures);
const steps = [
function (next) {

Expand Down
101 changes: 101 additions & 0 deletions test/runner.js
Expand Up @@ -819,6 +819,107 @@ describe('Runner', () => {
});
});

it('bail will terminate on the first test failure (skipping next befores)', (done) => {

const script = Lab.script();
let beforeRan = false;
script.experiment('root', () => {

script.experiment('test', () => {

script.test('1', (testDone) => {

testDone();
});

script.test('2', (testDone) => {

throw new Error('bailing');
});

script.test('3', (testDone) => {

testDone();
});
});

script.experiment('test', () => {

script.before((done) => {

beforeRan = true;
done();
});

script.test('1', (testDone) => {

testDone();
});
});
});

Lab.execute(script, { bail: true }, null, (err, notebook) => {

expect(err).not.to.exist();
expect(notebook.tests).to.have.length(4);
expect(notebook.failures).to.equal(1);
expect(notebook.tests[1].err.message).to.contain('bailing');
expect(notebook.tests[2].skipped).to.be.true();
expect(notebook.tests[3].skipped).to.be.true();
expect(beforeRan).to.be.false();
done();
});
});

it('bail will terminate on the first test failure (skipping sub-experiments)', (done) => {

const script = Lab.script();
let beforeRan = false;
script.experiment('test', () => {

script.test('1', (testDone) => {

testDone();
});

script.test('2', (testDone) => {

throw new Error('bailing');
});

script.test('3', (testDone) => {

testDone();
});

script.experiment('test', () => {

script.before((done) => {

beforeRan = true;
done();
});

script.test('1', (testDone) => {

testDone();
});
});
});

Lab.execute(script, { bail: true }, null, (err, notebook) => {

expect(err).not.to.exist();
expect(notebook.tests).to.have.length(4);
expect(notebook.failures).to.equal(1);
expect(notebook.tests[1].err.message).to.contain('bailing');
expect(notebook.tests[2].skipped).to.be.true();
expect(notebook.tests[3].skipped).to.be.true();
expect(beforeRan).to.be.false();
done();
});
});

it('dry run won\'t execute tests', (done) => {

const script = Lab.script();
Expand Down