taz
TypeScript icon, indicating that this package has built-in type declarations

6.15.0 • Public • Published

Taz

Little test runner for node.js

FAQ

What inspired Taz?

Taz is mostly inspired by go test. After working in Go for awhile, you soon realize that they nailed testing and it's one of Go's top 5 features. There are features in taz that you won't find in any other Node.js test framework. These features come from go test.

I also wanted taz to feel familiar to existing Node.js users. The work done in Ava and Mocha inspired me here, particularly Ava's test API and Mocha's reporting system.

How does taz compare to Mocha, Jest, Ava, Tape, etc.?

Taz comes from using mocha for a long time. During this time, there were always just a few things I wanted to improve:

  • The ability to run tests with node test.js
  • First-class support for .mjs files
  • Parallelization across files
  • A simpler test API

I like Ava and it's pretty close to my ideal. I made a few different decisions in building taz:

  • Tests within a file run serially, rather than in parallel. This is to preserve the order of console.log.
  • No transpilation. This improves the startup performance of Taz and reduces resource usage. Taz leaves the responsibility of transpilation to the test author.
  • Mocha reporter support. I think this is just because I've been using mocha for so long, but I just love Mocha's test reporting style. Taz works with all of Mocha's reporters!

Jest is the hot new test framework and to be fair to Jest, I've used it the least out of this list. I found a minimal test to take about 1 second to run on my computer (cold startup). It appears that Jest is optimized for large test suites. This isn't my typical workload and Taz is not optimized for this workload, though I'm quite sure Taz would be competitive here as is. Philisophically, I prefer a test framework to do the minimum amount of necessary operations to support 95% of your testing needs. The last 5% of your needs can be pulled in from NPM.

Tape is the closest in spirit to taz. Tape used to be lower-level than Taz, but recently I've noticed it's become a lot higher-level. Taz has a few features that Tape doesn't have and Tape has a few features that Taz doesn't have. I don't have much else to say about Tape other than when you're trying out Taz, be sure to give Tape a shot too!

Does taz run tests within a file in parallel?

No it doesn't. This may change in the future, if we're able to figure out a way to preserve console ordering. I'd also like to explore test caching. Go's testing framework does a great job of caching tests that haven't changed.

Does taz have subtests?

Taz does not support subtests. I used to be a big subtest fan but I recently realized that every time I was using subtests, it would be less complex to do use table-driven tests instead.

Where's before(fn) and after(fn)

Taz does not support before and after functions. Like subtests, I used to think I needed them, but later realized that before(fn) and after(fn) encourage shared state across tests. It's generally better to do this:

test('my test', async t => {
  const db = await connect(
    t,
    process.env.POSTGRES_URL,
  )
  t.after(db.close)
})

If the resource is very expensive, then you can mimic before and after like this:

let expensive
 
test('open expensive resource', async t => {
  expensive = await connect(t)
})
 
test('test 1')
test('test 2')
test('test 3')
 
test('close expensive resource', async t => {
  await expensive.close()
})

Readme

Keywords

none

Package Sidebar

Install

npm i taz

Weekly Downloads

24

Version

6.15.0

License

MIT

Unpacked Size

120 kB

Total Files

78

Last publish

Collaborators

  • mattmueller