datamade / how-to

📚 Doing all sorts of things, the DataMade way
MIT License
86 stars 12 forks source link

Adopt testing standards for JavaScript #75

Open hancush opened 4 years ago

hancush commented 4 years ago

Background

We use flake8 and pytest for code style and testing in Python. Many moons ago, @reginafcompton and I researched and proposed using the Node.js style guide and JSHint for style and jasmine for testing in JavaScript, but they weren't broadly adopted by the team, in large part because we made limited use of JavaScript. As of 2020, that's changing!

Proposal

We're learning JavaScript as a team, and the language offers many ways to achieve the same thing. Let's get ahead of the proliferation of idiosyncratic code and formally adopt style and testing standards.

As we've moved on from ES5, we should pick a style guide that aligns with ES6, and update our default .jshintrc to reflect the change.

We should also revisit our chosen test framework. Does jasmine play will with Gatsby and React? If not, identify and adopt an alternative.

Deliverables

  1. This research project should deliver a javascript/ directory containing a pointers to our style guide and default linting config, and to our documentation on JavaScript testing.
  2. It should also make a light revision to our JavaScript testing guidelines.
  3. Ideally, it would also add basic JavaScript tests to at least one project. If we're willing to absorb the time spent to implement tests as research, we could also add tests to a new client project, e.g., the stormwater credit exchange site, which will be implemented in Gatsby.

Timeline

I expect this project to take 1-2 days, depending on whether we can stick with jasmine or if we need to select a new testing framework.

Connects #22.

beamalsky commented 4 years ago

I am very glad to see you doing this! For the courts project, @jeancochrane and I added ESLint here: https://gitlab.com/court-transparency-project/charges-app/-/merge_requests/8

An advantage of ESLint is that it's built into the gatsby-starter-default, but I've never compared it to JSHint and definitely support having standard styles for JS projects. Here's are the rules we landed on for courts: https://gitlab.com/court-transparency-project/charges-app/-/blob/master/.eslintrc.js

reginafcompton commented 4 years ago

Oh myyyyy: I am tagged in a DataMade issue! @hancush I'd be happy to chat with you about how I've handled JS testing, linting, and auto-formatting this past year. "Slack me" if you'd like to set-up a call.

hancush commented 4 years ago

Code style (specifically, linting rules) is included in #78. Let's see how that goes, and assuming it covers the code style issue here, reorient this issue to be purely about testing.

smcalilly commented 1 year ago

We're all interested in this. The biggest team-wide hurdle is lack of knowledge about how to test React code — what does that look like, how does it work, what pieces of code/interaction do you test (unit tests, integration tests, etc)? This would be a good opportunity to train the entire team.

reginafcompton commented 1 year ago

Hello old friends! I do not work here anymore....but I do work with React these days. RTL is the industry-standard test library: https://testing-library.com/docs/react-testing-library/intro/ It's wonderful.