-
Notifications
You must be signed in to change notification settings - Fork 519
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
Add mocha_test rule #168
Comments
Any issues using something like:
We've implemented that in a defs.bzl alongside the WORKSPACE file, with:
It just works by running any .test.ts file which is included in Let me know if this is the right way to go, and I'll look at tidying up the above & a pull request etc. I don't know if you want to end up with a test rule for every test runner and/or bundling program. Surely anything provided through NPM with a CLI could fit into the above format? Another alternative would be a short example of how to do something like the above to help people new to Bazel. (As a side note r.e. other test runners - I had a lot of headaches trying to make Jest work, including postinstall patches to fix it's symlink handling behaviour as it would just hang with no errors due to the Bazel symlinks. Was kinda buggy and slow, not really sure why.). |
My quick stream-of-conciousness thoughts:
|
Cool, I'll do some more work on it if there's nothing fundamentally wrong with the approach.
|
After doing some cleanup work on #383 I found that Putting it another way, if we were to rename So that leads me to ask, why do you want a mocha test rule? Is there some test you've authored that can't execute under |
Can all tests which run in Jasmine run in Mocha? No, as Jasmine is 'batteries included' and Mocha requires you to include Chai, Sinon, etc for expectations and mocking etc. Can all tests which run in Mocha run in Jasmine? Possibly, simple tests do. I don't think that APIs are the same despite being similar. Likely edge cases which break.
Our goal is to run Typescript tests (.test.ts) files on Typescript source files (.ts), by calling a test runner with ts-node. We could compile tests + sources to JS and run the tests as JS too, which would add 1-2 extra rules per unit test. Is it preferable to have more general support, i.e. For example, a generic test runner:
N.B. if you wanted to pass in files to the test runner, e.g. mocha.opts, mock files as other dependencies, you'd need to use $(location :mocha.opts) so that the argument gets expanded, which is pretty opaque for users. Or a mocha-specific:
Since it's easy enough to write an additional wrapper around the |
Sorry, I'm still missing the answer to a basic question: if all known tests run under Jasmine, then what is the motivation to use mocha instead? |
Not all known tests run under Jasmine. My team has invested heavily in mocha and would like to use a mocha-native test command that includes |
@chrisleck of course you're free to use mocha, and your team can maintain a rule that does that. For considering upstreaming it to this repo, however, there's a high bar because our team will have to maintain and support the rule from now on. That's why I'm trying to carefully understand the tradeoff. Could you give an example of a test that runs under Mocha but not under Jasmine? How typical do you think such an example is? |
Please consider the discussion in issue #394 when naming this new test rule. |
I can't include my team's tests directly here, but we utilize Mocha's ability to create your own custom runner interface (using the confusingly named Also, our
|
@alexeagle Yeah it is a tricky one indeed, but here is a very basic comparison of mocha vs jasmine: https://raygun.com/blog/mocha-vs-jasmine-chai-sinon-cucumber/ so feature-wise they are very similar, but syntactically they are different, so while it might be possible to migrate things to jasmine I think it is going to be a big task for big test suites. So I think the question comes down to, should we support the 3 major test frameworks, jasmine, mocha, jest here in Would it be possible maybe to have kind of a middle ground @alexeagle? |
I finally got around to trying this. A mocha_test rule seems like overkill for us to ship with core rules_nodejs when you can implement your own thing so easily. Here's a working
|
adding a mocha example in #1216 to close this |
A mocha_test is now in the examples |
@alexeagle - in your example, how does one refer to a |
Similar to jasmine_node_test, create a mocha wrapper for running simple TS / javascript / node unit tests.
Other similar nodejs rulesets for bazel already support this: https://github.com/pubref/rules_node#mocha_test
The text was updated successfully, but these errors were encountered: