index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // set some global Vue options
  2. var Vue = require('src')
  3. Vue.options.replace = false
  4. Vue.config.silent = true
  5. /**
  6. * Because Vue's internal modules reference the warn function
  7. * from different modules (some from util and some from debug),
  8. * we need to normalize the warn check into a few global
  9. * utility functions.
  10. */
  11. var _ = require('src/util')
  12. var __ = require('src/util/debug')
  13. var scope = typeof window === 'undefined'
  14. ? global
  15. : window
  16. scope.spyWarns = function () {
  17. spyOn(_, 'warn')
  18. spyOn(__, 'warn')
  19. }
  20. scope.getWarnCount = function () {
  21. return _.warn.calls.count() + __.warn.calls.count()
  22. }
  23. scope.hasWarned = function (msg, silent) {
  24. if (!_.warn.calls) {
  25. console.warn('make sure to call spyWarns() before tests.')
  26. }
  27. var count = _.warn.calls.count()
  28. var args
  29. while (count--) {
  30. args = _.warn.calls.argsFor(count)
  31. if (args.some(containsMsg)) {
  32. return true
  33. }
  34. }
  35. count = __.warn.calls.count()
  36. while (count--) {
  37. args = __.warn.calls.argsFor(count)
  38. if (args.some(containsMsg)) {
  39. return true
  40. }
  41. }
  42. if (!silent) {
  43. console.warn('[test] "' + msg + '" was never warned.')
  44. }
  45. function containsMsg (arg) {
  46. if (arg instanceof Error) throw arg
  47. return typeof arg === 'string' && arg.indexOf(msg) > -1
  48. }
  49. }
  50. scope.process = {
  51. env: {
  52. NODE_ENV: 'development'
  53. }
  54. }
  55. // require all test files
  56. var testsContext = require.context('.', true, /_spec$/)
  57. testsContext.keys().forEach(testsContext)