Dieses Repository beinhaltet HTML- und Javascript Code zur einer NotizenWebApp auf Basis von Web Storage. Zudem sind Mocha/Chai Tests im Browser enthalten. https://meinenotizen.netlify.app/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

collect-files.js 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. 'use strict';
  2. const path = require('path');
  3. const ansi = require('ansi-colors');
  4. const debug = require('debug')('mocha:cli:run:helpers');
  5. const minimatch = require('minimatch');
  6. const utils = require('../utils');
  7. const {NO_FILES_MATCH_PATTERN} = require('../errors').constants;
  8. /**
  9. * Exports a function that collects test files from CLI parameters.
  10. * @see module:lib/cli/run-helpers
  11. * @see module:lib/cli/watch-run
  12. * @module
  13. * @private
  14. */
  15. /**
  16. * Smash together an array of test files in the correct order
  17. * @param {Object} opts - Options
  18. * @param {string[]} opts.extension - File extensions to use
  19. * @param {string[]} opts.spec - Files, dirs, globs to run
  20. * @param {string[]} opts.ignore - Files, dirs, globs to ignore
  21. * @param {string[]} opts.file - List of additional files to include
  22. * @param {boolean} opts.recursive - Find files recursively
  23. * @param {boolean} opts.sort - Sort test files
  24. * @returns {string[]} List of files to test
  25. * @private
  26. */
  27. module.exports = ({ignore, extension, file, recursive, sort, spec} = {}) => {
  28. let files = [];
  29. const unmatched = [];
  30. spec.forEach(arg => {
  31. let newFiles;
  32. try {
  33. newFiles = utils.lookupFiles(arg, extension, recursive);
  34. } catch (err) {
  35. if (err.code === NO_FILES_MATCH_PATTERN) {
  36. unmatched.push({message: err.message, pattern: err.pattern});
  37. return;
  38. }
  39. throw err;
  40. }
  41. if (typeof newFiles !== 'undefined') {
  42. if (typeof newFiles === 'string') {
  43. newFiles = [newFiles];
  44. }
  45. newFiles = newFiles.filter(fileName =>
  46. ignore.every(pattern => !minimatch(fileName, pattern))
  47. );
  48. }
  49. files = files.concat(newFiles);
  50. });
  51. const fileArgs = file.map(filepath => path.resolve(filepath));
  52. files = files.map(filepath => path.resolve(filepath));
  53. // ensure we don't sort the stuff from fileArgs; order is important!
  54. if (sort) {
  55. files.sort();
  56. }
  57. // add files given through --file to be ran first
  58. files = fileArgs.concat(files);
  59. debug('files (in order): ', files);
  60. if (!files.length) {
  61. // give full message details when only 1 file is missing
  62. const noneFoundMsg =
  63. unmatched.length === 1
  64. ? `Error: No test files found: ${JSON.stringify(unmatched[0].pattern)}` // stringify to print escaped characters raw
  65. : 'Error: No test files found';
  66. console.error(ansi.red(noneFoundMsg));
  67. process.exit(1);
  68. } else {
  69. // print messages as an warning
  70. unmatched.forEach(warning => {
  71. console.warn(ansi.yellow(`Warning: ${warning.message}`));
  72. });
  73. }
  74. return files;
  75. };