enhanceUnexpectedTokenMessage.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = enhanceUnexpectedTokenMessage;
  6. function _chalk() {
  7. const data = _interopRequireDefault(require('chalk'));
  8. _chalk = function _chalk() {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _interopRequireDefault(obj) {
  14. return obj && obj.__esModule ? obj : {default: obj};
  15. }
  16. /**
  17. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  18. *
  19. * This source code is licensed under the MIT license found in the
  20. * LICENSE file in the root directory of this source tree.
  21. */
  22. const DOT = ' \u2022 ';
  23. function enhanceUnexpectedTokenMessage(e) {
  24. e.stack =
  25. `${_chalk().default.bold.red('Jest encountered an unexpected token')}
  26. This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
  27. By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
  28. Here's what you can do:
  29. ${DOT}To have some of your "node_modules" files transformed, you can specify a custom ${_chalk().default.bold(
  30. '"transformIgnorePatterns"'
  31. )} in your config.
  32. ${DOT}If you need a custom transformation specify a ${_chalk().default.bold(
  33. '"transform"'
  34. )} option in your config.
  35. ${DOT}If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the ${_chalk().default.bold(
  36. '"moduleNameMapper"'
  37. )} config option.
  38. You'll find more details and examples of these config options in the docs:
  39. ${_chalk().default.cyan('https://jestjs.io/docs/en/configuration.html')}
  40. ${_chalk().default.bold.red('Details:')}
  41. ` + e.stack;
  42. return e;
  43. }