shim-done.ts 747 B

123456789101112131415161718192021222324252627282930313233343536
  1. // wrap tests to support test('foo', done => {...}) interface
  2. const _test = test
  3. const wait = (): [() => void, Promise<void>] => {
  4. let done
  5. const p = new Promise<void>((resolve, reject) => {
  6. done = resolve
  7. done.fail = reject
  8. })
  9. return [done, p]
  10. }
  11. const shimmed =
  12. ((global as any).it =
  13. (global as any).test =
  14. (desc: string, fn?: any, timeout?: number) => {
  15. if (fn && fn.length > 0) {
  16. _test(
  17. desc,
  18. () => {
  19. const [done, p] = wait()
  20. fn(done)
  21. return p
  22. },
  23. timeout
  24. )
  25. } else {
  26. _test(desc, fn, timeout)
  27. }
  28. })
  29. ;['skip', 'only', 'todo', 'concurrent'].forEach(key => {
  30. shimmed[key] = _test[key]
  31. })
  32. export {}