Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to randomise tests #421

Closed
pke opened this issue Jan 19, 2018 · 1 comment
Closed

Support to randomise tests #421

pke opened this issue Jan 19, 2018 · 1 comment

Comments

@pke
Copy link

pke commented Jan 19, 2018

Catching issues caused by globals are easier to catch if node-tap would allow to run tests within a testfile in random order. I know that it does that when you put the tests in different files you can run them in parallel which would also surface such global vars bugs. However it would be nice to be able to randomise tests within a file too.

@isaacs
Copy link
Member

isaacs commented Jan 21, 2019

In general, I very much prefer to avoid situations where tests pass "sometimes", but not other times. Coverage, code structure, and careful thinking can help ensure that the program is being well covered, and fuzz testing like this is often frustrating, making it easy to justify ignoring a failing test. (Run it again, it'll be fine. Just a fluke. Etc.)

You can of course do this yourself using parallel tests the same as you can with test files. Just set t.jobs = <some number> and then any async tests will be run in parallel. See for yourself:

const t = require('./')
t.jobs = 10

// run for some random amount of time up to 1s
const asyncRandomTest = (t) => {
  console.error('starting ', t.name)
  setTimeout(() => {
    console.error('ending', t.name)
    t.end()
  }, 1000 * Math.random())
}

t.test('first', asyncRandomTest)
t.test('second', asyncRandomTest)
t.test('third', asyncRandomTest)
t.test('fourth', asyncRandomTest)

@isaacs isaacs closed this as completed Jan 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants