add a simple test runner?
An important target group for this app (imo) are beginners and prototype builders. From my experience, both these groups would benefit greatly from having simple test infrastructure bundled with this starter.
From my own experience, I usually have a script.js that I'd include into the main module, but that's pretty hacky until I finally setup (whatever flavor of test infra is popular). The value I get is from being able to write code that'll run on every edit-save separately from my app, but that later morphs into a unit test suite or so on. For beginners, they'd build their app, but write tests for smaller parts of the app they're building, while learning to write tests for their code.
To be clear, I'm not advocating any specific framework/suite/assert libs; I'd just like to be able to run even a if(true) throw new Error script on every change.
Thoughts?
Thanks for the great tool!
I agree we should ship a test runner (Jest, ava, mocha, whatever) as long as we can stick with “no configuration” as the guiding design principle.
Other thoughts:
- We’re probably not going to include anything for running tests in browser because of the complexity it involves.
- We’re probably not going to include jsdom either.
- Testing app logic with a simple Node runner using Jasmine (or what do people use these days?) seems like a good idea.
How about tape? It's super simple and it already almost works -- if you restrict yourself to the subset of ES6 that your version of node supports you can use it now; all one would need to get it working is running it in babel-node; i.e. react-scripts test would run babel-node src/test.js.
With you on zero config; running src/tests.js in a 'watch' mode on npm start (and once on npm run build?) would be good. You sure about not running it in a 'browser' though? Phantomjs works pretty nicely, and wouldn't need any config/ explicit invocation/require iirc.
Huge vote for Mocha + Enzyme + Sinon. This probably requires JSdom, at least according to Enzyme docs.
I'm agree with Threepointone. Maybe PhantomJS with Mocha.
@ffxsam Enzyme would keep things nice and simple.
Thanks adding it to the conversation!
also headless chrome is round the corner, so that'll be a great solution with no 'dependencies'
I'd be happy to help and/or answer any questions about using Enzyme here!
Is PhantomJS really needed though? It seems a bit overkill, when Enzyme can easily simulate events on components. If I'm not mistaken, PhantomJS & Selenium are more for E2E testing, not unit testing.
@ffxsam Agree on Enzyme (it's great), and we wouldn't need jsdom if we do shallow rendering.
jsdom is only required for mount and render, correct?
Another vote for Enzyme, simplifies testing considerably, also the official React docs kind of recommend it now 😄
To make it clear, the tool currently only abstracts build dependencies so it shouldn’t matter too much what library you use to make assertions / mount tree / etc. Choosing the runner and conventions is what we need to do.
I'd vote Mocha then
Personally I think a "no config" setup would make sense with Jasmine, as it has all the things you need (assertions, mocking, etc..) with no configs. Where as Mocha might require chai and other things.
That's a good point, but based on what @gaearon said above, I don't think we're as concerned with the assertion library because it's not a build dependency. I'd still favor Mocha just because I think it's more commonly used, but I have no problem with Jasmine if that's the way we want to go.
If many people will be using Enzyme, I think Mocha makes more sense and it's quite easy to set up. Enzyme was designed to be used with Mocha, though of course it can be used with any test-runner.
Enzyme+Jasmine is a separate repo, FYI.
A few questions about conventions:
Can we put the tests in a test folder on the same level as src?
Should we include a template test, since there's a template component?
Do people prefer explicit extensions on the test files (i.e. '.spec.js') or just run everything in the test folder?
I'm thinking something like:
my-app/
src/
App.js
...
test/
App[.spec?].js
I'd err on the side of having __tests__ folders anywhere in the tree. It's very painful to write imports that go many folders up and then many folders down. Also colocating related code helps comprehension.
Hi all,
I have no qualifications whatsoever, so feel free to completely ignore this comment.
I personally would advocate for considering anything ending with .test.js or .spec.js as a test, because it allows you to either put your tests next to your code (as I prefer to do), or throughout the tree in __tests__. It would also be really easy to look for tests in a tests directory on the same level as src as well.