-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Implement the only modifier. #204
Conversation
}) | ||
.then(function () { | ||
return eachSeries(tests.after, self._runTest.bind(self)); | ||
}) | ||
.catch(noop) | ||
.then(function () { | ||
// HACK the test count number if only modifier is shown | ||
stats.testCount = tests.only.length ? tests.only.length : stats.testCount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable testCount
is maintained by the addTest
, addOnlyTest
, addSerialTest
function, which I think that is not suitable. A better way is to return such information (testCount
, failCount
) from the promise, then calculate the final stats from at the end of the chain.
However, it involves more code change if doing so. Any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's perfectly fine, I wouldn't call it a hack.
Awesome @lijunle :) Both @vdemedes and I are traveling, so we probably won't be able to review this until monday. |
@sindresorhus That is OK, please keep in mind that, there is a hack. I am not going to merge until resolve the hack with a good way (unless a direction). |
@@ -203,16 +209,21 @@ Runner.prototype.run = function () { | |||
} | |||
}) | |||
.then(function () { | |||
return self.serial(tests.serial); | |||
return tests.only.length ? self.concurrent(tests.only) : []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it can be just return self.concurrent(tests.only)
, since tests.only
defaults to []
.
Everything looks good so far, I pointed out some things in the diff. One question I have in mind, should |
My question is no. If the guy wants to do so, he should do
Mocha allow several |
I guess I was running some out-dated version then. |
@lijunle Could you please rebase your PR (to pick up latest fixes for windows tests) and address comments in the diff? Happy to merge this ASAP. |
OK, do you want to modify the comment about the hack? |
Yeah, the comment is not really needed and this - https://github.com/sindresorhus/ava/pull/204/files#r45035490 |
- Hack the test count number if only modifier is shown.
Rebased, let us wait for the CI. 😸 However, although I removed the comment, I still consider that is a hack. The stats should be collected from Code like this: Runner.prototype.run = function () {
var self = this;
return eachSeries(tests.before, this._runTest.bind(this)) // resolve with { pass: 1, failed: 2, skipped: 3 }
.then(function (stats) {
return Object.assign(stats, self.serial(tests.serial)); // i.e. { pass: 2, failed: 3, skipped: 4 }
})
.then(function (stats) {
return Object.assign(stats, self.concurrent(tests.concurrent)); // object with { pass, failed, skipped }
})
.then(function (stats) {
return Object.assign(stats, eachSeries(tests.after, self._runTest.bind(self))); // object with { pass, failed, skipped }
})
.then(function (stats) {
self.stats.passCount = stats.pass; // calculate from the input of promise chain.
return stats; // external check could depends on return value of run function, more stable.
});
}; |
The refactoring and cleanup work is ahead, so don't worry about this 1 line ;) |
I understand. It is up to you to design the pattern, that is just my suggestion. |
I was actually taking a stab at this earlier when I got pulled away to some other stuff. I just squashed my work and pushed it up: jamestalmage@4568347 Use it if it helps. My other thoughts.
Good work! And thanks for the help. |
@lijunle Thank you! |
@jamestalmage Any improvements welcome in a follow-up pull request ;) |
Yeah, sorry! |
DO NOT MERGE
Resolve #132
I hack the test count number to show the right number and passed cases number. From my understand, such information should be pass through the promise chain.
Besides,
ava.serial.only
has no support in this PR yet./cc @vdemedes @sindresorhus
Screenshot: