Skip to content

Conversation

@codeslikejaggars
Copy link
Contributor

Attempting to fix #1283. This change removes the before and after hooks from the run sequence when all tests in the collection are skipped. It intentionally keeps the always hook in the run sequence, since it would probably be surprising to a user if after.always didn't run.

Copy link
Member

@novemberborn novemberborn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're on a roll @codeslikejaggars!

This change removes the before and after hooks from the run sequence when all tests in the collection are skipped. It intentionally keeps the always hook in the run sequence, since it would probably be surprising to a user if after.always didn't run.

👍

It doesn't look like there's a test asserting that after.always still runs even if all tests are skipped?

Could you update the relevant hook documentation as well?

const getUnskippedCount = tests => tests.filter(test => {
return !(test.metadata && test.metadata.skipped === true);
}).length;
return (getUnskippedCount(this.tests.serial) + getUnskippedCount(this.tests.concurrent)) > 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be clearer with Array#some().

if (this._hasUnskippedTests()) {
const beforeHooks = new Sequence(this._buildHooks(this.hooks.before));
const afterHooks = new Sequence(this._buildHooks(this.hooks.after));
finalTests = new Sequence([beforeHooks, allTests, afterHooks], true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could create the allTests sequence in this branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I can, see response to the comment below.

const afterHooks = new Sequence(this._buildHooks(this.hooks.after));
finalTests = new Sequence([beforeHooks, allTests, afterHooks], true);
} else {
finalTests = new Sequence([allTests], true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be an empty sequence, since presumably all tests are skipped if it gets to this point. That would make the logic easier to grasp IMHO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that would work. If it's an empty sequence, the skipped tests won't be reported in the runner output.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that makes sense 👍

@codeslikejaggars codeslikejaggars force-pushed the github-issue-1283-before-and-after-with-skip branch from 6993519 to f2ee995 Compare October 27, 2017 17:42
@codeslikejaggars
Copy link
Contributor Author

Updated the readme and added a test for after.always.

@novemberborn novemberborn merged commit 1cd3a04 into avajs:master Oct 29, 2017
@novemberborn
Copy link
Member

Awesome work @codeslikejaggars 🚀

@sindresorhus
Copy link
Member

Great work @codeslikejaggars 👌✨🎉

@codeslikejaggars codeslikejaggars deleted the github-issue-1283-before-and-after-with-skip branch November 6, 2017 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should before and after run with skip?

3 participants