getNoTestFoundVerbose.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = getNoTestFoundVerbose;
  6. function _chalk() {
  7. const data = _interopRequireDefault(require('chalk'));
  8. _chalk = function _chalk() {
  9. return data;
  10. };
  11. return data;
  12. }
  13. var _pluralize = _interopRequireDefault(require('./pluralize'));
  14. function _interopRequireDefault(obj) {
  15. return obj && obj.__esModule ? obj : {default: obj};
  16. }
  17. /**
  18. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  19. *
  20. * This source code is licensed under the MIT license found in the
  21. * LICENSE file in the root directory of this source tree.
  22. */
  23. function getNoTestFoundVerbose(testRunData, globalConfig) {
  24. const individualResults = testRunData.map(testRun => {
  25. const stats = testRun.matches.stats || {};
  26. const config = testRun.context.config;
  27. const statsMessage = Object.keys(stats)
  28. .map(key => {
  29. if (key === 'roots' && config.roots.length === 1) {
  30. return null;
  31. }
  32. const value = config[key];
  33. if (value) {
  34. const valueAsString = Array.isArray(value)
  35. ? value.join(', ')
  36. : String(value);
  37. const matches = (0, _pluralize.default)(
  38. 'match',
  39. stats[key] || 0,
  40. 'es'
  41. );
  42. return ` ${key}: ${_chalk().default.yellow(
  43. valueAsString
  44. )} - ${matches}`;
  45. }
  46. return null;
  47. })
  48. .filter(line => line)
  49. .join('\n');
  50. return testRun.matches.total
  51. ? `In ${_chalk().default.bold(config.rootDir)}\n` +
  52. ` ${(0, _pluralize.default)(
  53. 'file',
  54. testRun.matches.total || 0,
  55. 's'
  56. )} checked.\n` +
  57. statsMessage
  58. : `No files found in ${config.rootDir}.\n` +
  59. `Make sure Jest's configuration does not exclude this directory.` +
  60. `\nTo set up Jest, make sure a package.json file exists.\n` +
  61. `Jest Documentation: ` +
  62. `facebook.github.io/jest/docs/configuration.html`;
  63. });
  64. let dataMessage;
  65. if (globalConfig.runTestsByPath) {
  66. dataMessage = `Files: ${globalConfig.nonFlagArgs
  67. .map(p => `"${p}"`)
  68. .join(', ')}`;
  69. } else {
  70. dataMessage = `Pattern: ${_chalk().default.yellow(
  71. globalConfig.testPathPattern
  72. )} - 0 matches`;
  73. }
  74. return (
  75. _chalk().default.bold('No tests found, exiting with code 1') +
  76. '\n' +
  77. 'Run with `--passWithNoTests` to exit with code 0' +
  78. '\n' +
  79. individualResults.join('\n') +
  80. '\n' +
  81. dataMessage
  82. );
  83. }