index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use strict';
  2. var fs = require('fs');
  3. var path = require('path');
  4. var rules = String(fs.readFileSync(path.join(process.cwd(), 'test', '.1-ignore')));
  5. var matcher = require('../').createMatcher(rules);
  6. var test = require('tape');
  7. var checkDir = function checkDir(dir, paths, output) {
  8. if (!output) { output = ''; }
  9. paths.forEach(function (pathArr) {
  10. var isDir = Array.isArray(pathArr);
  11. var filename = isDir ? pathArr[0] : pathArr;
  12. var resolved = path.join(dir, filename);
  13. if (matcher.shouldIgnore(resolved)) {
  14. output += '- ' + resolved + '\n';
  15. } else if (isDir) {
  16. output = checkDir(resolved, pathArr[1], output);
  17. } else {
  18. output += '+ ' + resolved + '\n';
  19. }
  20. });
  21. return output;
  22. };
  23. test('expected output', function (t) {
  24. process.chdir(path.join(process.cwd(), 'test'));
  25. var root = [
  26. '.ignore',
  27. [
  28. 'a',
  29. [
  30. ['a', ['notignored']],
  31. 'ignored',
  32. 'notignored',
  33. 'notlisted'
  34. ]
  35. ],
  36. 'expected',
  37. 'test.js'
  38. ];
  39. var output = checkDir('.', root);
  40. t.equal(output, String(fs.readFileSync('1-expected')));
  41. t.end();
  42. });
  43. test('delimiter defaults to path.sep', function (t) {
  44. t.equal(matcher.delimiter, path.sep);
  45. t.end();
  46. });