您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

test-adapter.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. (function () {
  2. var Testem = window.Testem
  3. var regex = /^((?:not )?ok) (\d+) (.+)$/
  4. Testem.useCustomAdapter(tapAdapter)
  5. function tapAdapter(socket){
  6. var results = {
  7. failed: 0
  8. , passed: 0
  9. , total: 0
  10. , tests: []
  11. }
  12. socket.emit('tests-start')
  13. Testem.handleConsoleMessage = function(msg){
  14. var m = msg.match(regex)
  15. if (m) {
  16. var passed = m[1] === 'ok'
  17. var test = {
  18. passed: passed ? 1 : 0,
  19. failed: passed ? 0 : 1,
  20. total: 1,
  21. id: m[2],
  22. name: m[3],
  23. items: []
  24. }
  25. if (passed) {
  26. results.passed++
  27. } else {
  28. console.error("failure", m)
  29. results.failed++
  30. }
  31. results.total++
  32. // console.log("emitted test", test)
  33. socket.emit('test-result', test)
  34. results.tests.push(test)
  35. } else if (msg === '# ok' || msg.match(/^# tests \d+/)){
  36. // console.log("emitted all test")
  37. socket.emit('all-test-results', results)
  38. }
  39. // return false if you want to prevent the console message from
  40. // going to the console
  41. // return false
  42. }
  43. }
  44. }())