MithrilJS / ospec

Noiseless testing framework
MIT License
48 stars 13 forks source link

Lost assertions in async tests #50

Closed pygy closed 1 year ago

pygy commented 2 years ago

It is currently possible to have assertions that run after the test that defined them, and at that point, ospec is unacle to trace their origin.

One possibility to solve this would be to change the API to something tape-like:

o("test", o => {
  // this would either refuse to work
  setTimeout(()=>o(1).equals(false), 5)
})

If we were to implement this, we'd need a complimentary codemod to upgrade the test suites. If someone skilled in theses want to step up and write it would be most welcome. Otherwise I'll dive into it.

pygy commented 1 year ago

I'm in the process of implementing this as an opt-in, run-time option. I'll provide o.localAssertions and o.localAssertions which can be nested. o.localAssertions(true) at the root of a test suite will also be valid as a global switch.

o.localAssertions( ()=> {
  o("new style", o => {})
  o.globalAssertions(()=>{
    o("old-style", done => {done()})
  })
})