Riteway

Simple, readable, helpful unit tests.

README

Riteway


Simple, readable, helpful unit tests.

Readable
Isolated/Integrated
Thorough
Explicit

Riteway forces you to write Readable, Isolated, and Explicit tests, because that's the only way you can use the API. It also makes it easier to be thorough by making test assertions so simple that you'll want to write more of them.

There are 5 questions every unit test must answer. Riteway forces you to answer them.

1. What is the unit under test (module, function, class, whatever)?
2. What should it do? (Prose description)
3. What was the actual output?
4. What was the expected output?
5. How do you reproduce the failure?


Installing


  1. ```shell
  2. npm install --save-dev riteway
  3. ```

Then add an npm command in your package.json:

  1. ```json
  2. "test": "riteway test/**/*-test.js",
  3. ```

Now you can run your tests with npm test. Riteway also supports full TAPE-compatible usage syntax, so you can have an advanced entry that looks like:

  1. ```json
  2. "test": "nyc riteway test/**/*-rt.js | tap-nirvana",
  3. ```

In this case, we're using nyc, which generates test coverage reports. The output is piped through an advanced TAP formatter, tap-nirvana that adds color coding, source line identification and advanced diff capabilities.

Troubleshooting


If you get an error like:

  1. ```shell
  2. SyntaxError: Unexpected identifier
  3.     at new Script (vm.js:79:7)
  4.     at createScript (vm.js:251:10)
  5.     at Object.runInThisContext (vm.js:303:10)
  6. ...
  7. ```

The problem is likely that you need a .babelrc configured with support for esm (standard JavaScript modules) and/or React. If you need React support, that might look something like:

  1. ```json
  2. {
  3.   "presets": [
  4.     [
  5.       "@babel/preset-env",
  6.       {
  7.         "targets": [
  8.           "last 2 versions",
  9.           "safari >= 7"
  10.         ]
  11.       }
  12.     ],
  13.     "@babel/preset-react"
  14.   ],
  15.   "plugins": [
  16.     [
  17.       "@babel/plugin-transform-runtime",
  18.       { "corejs": 2 }
  19.     ]
  20.   ]
  21. }
  22. ```

To install babel devDependencies:

  1. ```shell
  2. npm install --save-dev @babel/core @babel/plugin-transform-runtime @babel/preset-env @babel/register @babel/runtime-corejs2
  3. ```

And if you're using react:

  1. ```shell
  2. npm install --save-dev @babel/preset-react
  3. ```

You can then update your test script in package.json to use babel:

  1. ```json
  2. "test": "node -r @babel/register source/test"
  3. ```

If you structure your folders by type like this:

  1. ```shell
  2. todos
  3.    component
  4.    reducer
  5.    test
  6. user
  7.    component
  8.    reducer
  9.    test
  10. ```

Update your test script to find all files with your custom ending:

  1. ```json
  2. "test": "riteway -r @babel/register 'src/**/*.test.js' | tap-nirvana",
  3. ```