Today I Learned

Inspired by til.hashrocket.com

Awesome automated testing setup

Usually I have to start dev server and tests in different tabs in the terminal, but how awesome and useful would it be to have only one script for that.

Well, today @kentcdodds teach me an awesome solution for that in one of the lessons at Testing JavaScript: start-server-and-test from @bahmutov.

package.json

"scripts": {
  "test": "jest --watch",
  "test:run": "start-server-and-test start:dev http://localhost:8080 test"
  "start:dev": "webpack-dev-server"
}

So basically when I run yarn test:run, start-server-and-test run the first parameter - start:dev and wait for the server to start responding. When this happens it will run the third parameter - test.

This is very useful not only for the developer but for the CI too.