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
- ```shell
- npm install --save-dev riteway
- ```
Then add an npm command in your package.json:
- ```json
- "test": "riteway test/**/*-test.js",
- ```
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:
- ```json
- "test": "nyc riteway test/**/*-rt.js | tap-nirvana",
- ```
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:
- ```shell
- SyntaxError: Unexpected identifier
- at new Script (vm.js:79:7)
- at createScript (vm.js:251:10)
- at Object.runInThisContext (vm.js:303:10)
- ...
- ```
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:
- ```json
- {
- "presets": [
- [
- "@babel/preset-env",
- {
- "targets": [
- "last 2 versions",
- "safari >= 7"
- ]
- }
- ],
- "@babel/preset-react"
- ],
- "plugins": [
- [
- "@babel/plugin-transform-runtime",
- { "corejs": 2 }
- ]
- ]
- }
- ```
To install babel devDependencies:
- ```shell
- npm install --save-dev @babel/core @babel/plugin-transform-runtime @babel/preset-env @babel/register @babel/runtime-corejs2
- ```
And if you're using react:
- ```shell
- npm install --save-dev @babel/preset-react
- ```
You can then update your test script in package.json to use babel:
- ```json
- "test": "node -r @babel/register source/test"
- ```
If you structure your folders by type like this:
- ```shell
- ├──todos
- │ ├── component
- │ ├── reducer
- │ └── test
- └──user
- ├── component
- ├── reducer
- └── test
- ```
Update your test script to find all files with your custom ending:
- ```json
- "test": "riteway -r @babel/register 'src/**/*.test.js' | tap-nirvana",
- ```