The test/ directory is a mix of tests that run on the BCD data itself to ensure style/consistency/etc., and at least one test for code itself, in test-utils.js. That file as this comment:
https://github.com/mdn/browser-compat-data/blob/b3cc680b9ebbb2ab4b56f71378f80e660abd2ff6/test/test-utils.js#L60
The test defines its own it helper, and would be easy to convert to any JS test frameworks.
The main candidates that come to mind are https://mochajs.org/ and https://jestjs.io/. Preferences, anyone?
I'm filing this issue because I'd like to write tests for some new code I'm writing in scripts/.
To make this concrete, I've sent PRs showing what it would look like with each framework, https://github.com/mdn/browser-compat-data/pull/6856 for Jest and https://github.com/mdn/browser-compat-data/pull/6857 for Mocha. Both are failing because both require Node.JS 10, but they work locally.
My preference would be for Mocha, because of the fewer dependencies and that the output is already similar (green checkmarks) to what our lint script does.
Note that with Mocha we may end up wanting to pull in chai for more powerful asserts, and nyc for coverage, while Jest has a lot more built in.
+1 for this. I tried to get a discussion going in #5829, but sadly, nobody responded... :(
Oh, I didn't know about that issue, I searched a bit but didn't find an existing one.
I'm not going to close either, I think that if this issue is fixed, https://github.com/mdn/browser-compat-data/issues/5829 would still remain open to actually add tests for the linter.
@ddbeck @sideshowbarker your thoughts on this one would be appreciated.
My preference would be for Mocha, because of the fewer dependencies and that the output is already similar (green checkmarks) to what our lint script does.
I agree, for those same reasons.
That said, I know Jest is pretty widely used too — maybe even more widely used now than Mocha — and I wouldn’t object if others felt more strongly that Jest was the better choice.
Note that with Mocha we may end up wanting to pull in chai for more powerful asserts, and nyc for coverage
In general, I don’t think adding additional dependencies is a problem for us in our case for BCD
while Jest has a lot more built in.
I think the flip side of that is, Mocha arguably gives you more choices
Thank you so much for opening these comparison PRs, @foolip!
I've used Jest a bit on mdn/stumptown-content and, honestly, I didn't care for the expect idioms in Jest. I felt like I had to think a lot about what they did and how they worked. The prospect of using Node's assert library—at least to start—feels like a gentler introduction of testing to BCD.
So if nobody has any strong feelings about it, I'm inclined to go with Mocha on the basis of my very weak feelings about it.
If we're going to do this, the Node.js 10 thing is a bit of an issue. We can either put this in a holding pattern for a few weeks—until we drop the mdn- package entirely, or you can retarget this against master-scoped-package (though I'll caution you that I've been pushing merges from master to it weekly, so you'll need to keep up with those to develop against the scoped branch).
I'd be happy to just wait for the master branch to depend on Node.js 10, if that's only a few weeks off.
OK, great. This will be an incentive to wrap up the package scoping in a timely manner. 😄
Mocha's been merged. Let it be known that I won't mind seeing (ideally, small) PRs that expand test coverage or move existing tests into Mocha tests. I'm really excited at the idea of separating _linting_ from tests of the code itself and making it safer to change our code without breaking things.
Most helpful comment
Mocha's been merged. Let it be known that I won't mind seeing (ideally, small) PRs that expand test coverage or move existing tests into Mocha tests. I'm really excited at the idea of separating _linting_ from tests of the code itself and making it safer to change our code without breaking things.