Skip to content
This repository has been archived by the owner on Sep 7, 2018. It is now read-only.

Command line switch to fail on focus rocket #327

Closed
c089 opened this issue Dec 19, 2012 · 27 comments · Fixed by busterjs/buster-test#25
Closed

Command line switch to fail on focus rocket #327

c089 opened this issue Dec 19, 2012 · 27 comments · Fixed by busterjs/buster-test#25

Comments

@c089
Copy link
Contributor

c089 commented Dec 19, 2012

Focus rockets are great, but leaving them in the code before committing is a hazard. For CI servers, I could imagine a command line switch that, when activated will cause buster-test to fail with an error if any rockets are found.

@augustl
Copy link
Member

augustl commented Apr 16, 2013

That makes a lot of sense, thanks for the suggestion.

@dominykas
Copy link
Member

I'd love to fix this, as I'm getting burned by this myself occasionally, but I'll need some help...

If I understand correctly, I should create a new flag, e.g. --earthworm or --grounded in buster-test-cli, then update prepareOptions and it will eventually propagate down to https://github.com/busterjs/buster-test/blob/master/lib/test-runner.js#L474. That's the easy bit (except figuring out how to properly write tests for the entire thing).

But what's the appropriate thing to do when this.focusMode && this.grounded? throw? suite:end with some sort of a result? Reject the promise?

@dwittner
Copy link
Member

@dymonaz, i currently don't know how to realize it, but the behavior should be similar to the behavior in case you have a test-case without a name set. In test-case.js an Error is thrown and that leads to the output

Failed requiring .\test.js: Test case name required

without a stack trace.

@dominykas
Copy link
Member

What if instead of failing, the switch ignored the rockets (i.e. on --grounded run all tests, no rockets allowed)? I think that might just be easier to implement... Just an extra condition around here: https://github.com/busterjs/buster-test/blob/master/lib/test-runner.js#L497

@dominykas
Copy link
Member

Then again... the above might be a bad idea, since the goal is not only to "make CI run ALL tests" - checking in focus rocket affects other people in the team and should draw attention...

@augustl
Copy link
Member

augustl commented Jun 17, 2014

Note that if you return when.reject("An error message") from the runContexts function (i.e. return a rejected promise), I'm pretty sure the test run will fail with that message. So if you figure out how to add a CLI flag you should be all good :)

@dwittner
Copy link
Member

@dymonaz, i even think the main purpose of the command line switch is to ensure nobody has checked in a focus rocket.
@augustl, i am quite sure return when.reject("An error message") in test-runner#runContexts won't work, because i have tried it out. The test run just hangs.

@dominykas
Copy link
Member

Returning a rejected promise is not good enough, because nobody actually listens for it, i.e. while runSuite() returns a promise, I don't think anyone ever reads its value (I couldn't find a place that does). Tests read runSuite() promises.

The reason the test run just hangs is because if there's a rejected promise in runContexts, runSuite rejects itself, but never fires "suite:end" - which is a separate issue.

I was able to make the suite fail by rejecting the promise, still firing suite:end, but setting results.ok=false. This does not show a pretty error message though... But that's probably up to reporters?

@dominykas
Copy link
Member

The code in the pull request doesn't look pretty, but it does the job. The only real problem is that the error is never displayed - I'd normally just console.error that - but is there something else I should do? What about reporters, etc?

A better approach would be a suite:end with an error (rather than results), or even a suite:error - but that would mean a huge change across all the reporters, I guess - and I'm not brave enough to just do it.

But if this approach is kind of OK - it's fairly simple to add if (this.focusMode && this.focusModeDisabled) { runSuitePromise = when.reject(new Error("Focus rockets are grounded."); } and move on to adding the command line argument.

@dominykas
Copy link
Member

Can we re-open this? busterjs/buster-test#25 was just a first step - still working on the final solution (I think there'll be one PR on buster-test and one on buster-test-cli).

@dwittner dwittner reopened this Sep 21, 2014
@dwittner
Copy link
Member

Yes we can ;)

@dominykas
Copy link
Member

OK, the --no-focus-mode switch is there and it seems to work. The remaining piece is proper error reporting, as mentioned before. Right now I'm thinking that emitting suite:error just before suite:end here: https://github.com/busterjs/buster-test/blob/master/lib/test-runner.js#L498 is the right thing to do - it would then be up to individual reports to pretty-print it. Thoughts?

@cjohansen
Copy link
Member

That sounds good. Make sure that the result object emitted with suite:end also indicates an unsuccessful run.

Small nitpick: I prefer boolean options and command line arguments, so I'd like to rename the option here. One suggestion is --fail-focus-rocket, but I'm open to other suggestions. Thoughts?

@dwittner
Copy link
Member

We already have a --fail-on option for failing on warnings at the given level. Thus i would prefer --fail-on-focus-rocket, but i don't have an idea for the short option.

@dominykas
Copy link
Member

--fail-on-focus (skip the rocket for less typing)?

@cjohansen suite:end already passes a results object with bool ok - but it does not contain the actual error message (and I'm not sure I want to add there, because it's just a very nice and small object with result counts).

@cjohansen
Copy link
Member

👍

@cjohansen
Copy link
Member

@dymonaz I just meant that the ok flag in suite:end needs to be false. This is in addition to your proposed suite:error event.

@dominykas
Copy link
Member

Yeah, I already did the ok bit earlier. I'll probably update both PRs this week.

@dwittner
Copy link
Member

@dymonaz 👍 for --fail-on-focus

But which short option we want to use?

@dominykas
Copy link
Member

I was thinking about none :)

@cjohansen
Copy link
Member

None is fine :)

@dwittner
Copy link
Member

That's maximum shortness. :) 👍

@dominykas
Copy link
Member

OK, I think busterjs/buster-test-cli#14 is now done - renamed to --fail-on-focus and I think that's all?

As for the suite:error... It now gets emitted just before suite:end, so that part is done, but what do I do about reporters? My initial thought was to blindly reuse the uncaughtException handler, but...

As I'm not really a fan of long threads that never get released, my suggestion would be this:

Do you think we'd be close to a release-able state after that? Happy to hear about alternatives on how to carve this up into smaller pieces of work...

@cjohansen
Copy link
Member

The json-proxy reporter is used when the test runner is running in the browser. It is connected to a socket which passes the test runner messages back to the server. It should pass the message along like it does with the others.

Sounds like a solid plan!

@dominykas
Copy link
Member

Took the liberty to also update the specification reporter - seems that during the API changes printStats was not renamed to be a suite:end handler (well, at least I hope that's what was supposed to happen). Now specification prints the summary at the end again, and also does the suite:error to uncaughtException dance.

I think this is done, once busterjs/buster-test#26 is merged?

Docs probably need an update for this http://docs.busterjs.org/en/latest/overview/#focus-rocket - are there any other places to update?

@cjohansen
Copy link
Member

No, I think that's about it. Well done!

@dominykas
Copy link
Member

This should be closed, shouldn't it?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants