Skip to content

Commit c14ae9f

Browse files
committed
update readme
1 parent 884e5c4 commit c14ae9f

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

README.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Node.js.
55

66
[![Build Status](https://travis-ci.org/tapjs/node-tap.svg?branch=master)](https://travis-ci.org/tapjs/node-tap) [![Build Status](https://ci.appveyor.com/api/projects/status/913p1ypf21gf4leu?svg=true)](https://ci.appveyor.com/project/isaacs/node-tap) [![Coverage Status](https://coveralls.io/repos/tapjs/node-tap/badge.svg?branch=master&service=github)](https://coveralls.io/github/tapjs/node-tap?branch=master)
77

8+
_Just wanna see some code? [Get started!](http://www.node-tap.org/basics/)_
9+
810
It includes a command line test runner for consuming TAP-generating
911
test scripts, and a JavaScript framework for writing such scripts.
1012

@@ -15,8 +17,135 @@ test scripts, and a JavaScript framework for writing such scripts.
1517
* Great [promise support](http://www.node-tap.org/promises/)
1618
* Comprehensive [assert library](http://www.node-tap.org/asserts/)
1719
* Other [advanced stuff](http://www.node-tap.org/advanced/)
20+
* Mocha-like [BDD DSL](http://www.node-tap.org/mochalike/)
21+
* [Parallel Testing](http://www.node-tap.org/parallel/)
1822
* [Command-line interface](http://www.node-tap.org/cli/) for running
1923
tests (whether they use node-tap or not)
2024

25+
See [the changelog](http://www.node-tap.org/changelog/) for recent updates, or just get
26+
started with [the basics](http://www.node-tap.org/basics/).
27+
2128
All this is too much to manage in a single README file, so head over
2229
to [the website](http://www.node-tap.org/) to learn more.
30+
31+
## Why TAP?
32+
33+
Why should you use this thing!? **LET ME TELL YOU!**
34+
35+
Just kidding.
36+
37+
Most frameworks spend a lot of their documentation telling you why
38+
they're the greatest. I'm not going to do that.
39+
40+
### <i lang="it">tutti i gusti, sono gusti</i>
41+
42+
Node-tap is based on [my](http://izs.me) opinions about how a test
43+
framework should work, and what it should let you do. I do _not_ have
44+
any opinion about whether or not you share those opinions.
45+
46+
1. **Test files should be "normal" programs that can be run
47+
directly.**
48+
49+
That means that it can't require a special runner that
50+
puts magic functions into a global space. `node test.js` is a
51+
perfectly reasonable way to run a test, and it ought to function
52+
exactly the same as when it's run by the fancy runner with
53+
reporting and such. JavaScript tests should be JavaScript
54+
programs; not english-language poems with weird punctuation.
55+
56+
2. **Test output should be sensibly connected to the structure of the
57+
test file.**
58+
59+
That means not unnecessarily deferring test functions
60+
until `nextTick`, because that would shift the order of
61+
`console.log` output. Synchronous tests should be synchronous.
62+
63+
3. **Test files should be run in separate processes.**
64+
65+
That means that it can't use `require()` to load test files. Doing
66+
`node ./test.js` must be the exact same sort of environment for the
67+
test as doing `test-runner ./test.js`. Doing `node test/1.js; node
68+
test/2.js` should be equivalent (from the test's point of view) to
69+
doing `test-runner test/*.js`. This prevents tests from becoming
70+
implicitly dependent on one anothers' globals.
71+
72+
4. **Assertions should not normally throw (but throws MUST be handled
73+
nicely).**
74+
75+
I frequently write programs that have many hundreds of
76+
assertions based on some list of test cases. If the first failure
77+
throws, then I don't know if I've failed 100 tests or 1, without
78+
wrapping everything in a try-catch. Furthermore, I usually want to
79+
see some kind of output or reporting to verify that each one
80+
actually ran.
81+
82+
Basically, it should be your decision whether you want to throw or
83+
not. The test framework shouldn't force that on you, and should
84+
make either case easy.
85+
86+
5. **Test reporting should be separate from the test process, included
87+
in the framework, and enabled by default for humans.**
88+
89+
The [raw test output](http://www.node-tap.org/tap-format/) should be machine-parseable and
90+
human-intelligible, and a separate process should consume test
91+
output and turn it into a [pretty summarized
92+
report](http://www.node-tap.org/reporting/).
93+
This means that test data can be stored and parsed later, dug into
94+
for additional details, and so on. Also: nyan cat.
95+
96+
6. **Writing tests should be easy, maybe even fun.**
97+
98+
The lower the barrier to entry for writing new tests, the more
99+
tests get written. That means that there should be a relatively
100+
small vocabulary of actions that I need to remember as a test
101+
author. There is no benefit to having a distinction between a
102+
"suite" and a "subtest". Fancy DSLs are pretty, but more to
103+
remember.
104+
105+
That being said, if the you returns a Promise, or use a DSL that
106+
throws a decorated error, then the test framework should Just Work
107+
in a way that is reasonable.
108+
109+
7. **Tests should output enough data to diagnose a failure, and no
110+
more or less.**
111+
112+
Stack traces pointing at JS internals or the guts of the test
113+
framework itself are not helpful. A test framework is a serious UX
114+
challenge, and should be treated with care.
115+
116+
8. **Test coverage should be included.**
117+
118+
Running tests with coverage changes the way that you think about
119+
your programs, and provides much deeper insight. Node-tap bundles
120+
[nyc](https://istanbul.js.org/) for this.
121+
122+
It's not enabled by default only because it _does_ necessarily
123+
change the nature of the environment a little bit. But I strongly
124+
encourage [enabling coverage](http://www.node-tap.org/coverage/).
125+
126+
9. **Tests should be output in a predictable order.**
127+
128+
Even if they are run in parallel, the test _output_ should be
129+
consistent.
130+
131+
As of version 10, tap supports [parallel
132+
tests](http://www.node-tap.org/parallel/), which
133+
can make your tests run significantly faster if they are I/O bound
134+
or if you have multiple cores on your machine. However, even when
135+
run in parallel, the output is still serialized.
136+
137+
10. **Tests should not require more building than your code.**
138+
139+
Babel and Webpack are lovely and fine. But if your code doesn't
140+
require compilation, then I think your tests shouldn't either.
141+
Tap is extremely [promise-aware](http://www.node-tap.org/promises/), but works on any
142+
version of Node.js back to v0.10.
143+
144+
Software testing should help you build software. It should be a
145+
security blanket and a quality ratchet, giving you the support to
146+
undertake massive refactoring and fix bugs without worrying. It
147+
shouldn't be a purification rite or a hazing ritual.
148+
149+
There are many opinions left off of this list! Reasonable people can
150+
disagree. But if you find yourself nodding along, [maybe tap is for
151+
you](http://www.node-tap.org/basics/).

0 commit comments

Comments
 (0)