util.js 758 B

123456789101112131415161718192021222324252627282930313233343536
  1. var scope = typeof window === 'undefined'
  2. ? global
  3. : window
  4. // Some versions of phantomjs doesn't have bind defined.
  5. // See https://github.com/ariya/phantomjs/issues/10522
  6. Function.prototype.bind = Function.prototype.bind || function (thisp) {
  7. var fn = this;
  8. return function () {
  9. return fn.apply(thisp, arguments);
  10. };
  11. };
  12. scope.hasWarned = function (_, msg, silent) {
  13. var count = _.warn.calls.count()
  14. while (count--) {
  15. var args = _.warn.calls.argsFor(count)
  16. if (args.some(containsMsg)) {
  17. return true
  18. }
  19. }
  20. if (!silent) {
  21. console.warn('[test] "' + msg + '" was never warned.')
  22. }
  23. function containsMsg (arg) {
  24. return arg.indexOf(msg) > -1
  25. }
  26. }
  27. scope.process = {
  28. env: {
  29. NODE_ENV: 'development'
  30. }
  31. }