removeIgnores.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. var expect = require('expect.js');
  2. var helpers = require('../helpers');
  3. var glob = require('glob');
  4. var Q = require('q');
  5. var removeIgnores = require('../../lib/util/removeIgnores');
  6. describe('removeIgnores', function () {
  7. var tempDir = new helpers.TempDir({
  8. 'bower.json': {},
  9. 'index.js': 'Not to ignore',
  10. 'node_modules/underscore/index.js': 'Should be ignored'
  11. });
  12. var ignoreTest = function(dir, meta, leftovers) {
  13. tempDir.prepare();
  14. var deferred = Q.defer();
  15. removeIgnores(dir, meta).then(function() {
  16. glob('**/*.*', { cwd: dir }, function(cb, files) {
  17. expect(files).to.eql(leftovers);
  18. deferred.resolve();
  19. });
  20. });
  21. return deferred.promise;
  22. };
  23. it('removes all files in directory', function () {
  24. return ignoreTest(tempDir.path,
  25. { ignore: [ 'node_modules/**/*' ] },
  26. [ 'bower.json', 'index.js' ]
  27. );
  28. });
  29. it('removes whole directory', function () {
  30. return ignoreTest(tempDir.path,
  31. { ignore: [ 'node_modules/' ] },
  32. [ 'bower.json', 'index.js' ]
  33. );
  34. });
  35. it('removes whole directory (no ending slash)', function () {
  36. return ignoreTest(tempDir.path,
  37. { ignore: [ 'node_modules' ] },
  38. [ 'bower.json', 'index.js' ]
  39. );
  40. });
  41. it('removes all but one file', function() {
  42. return ignoreTest(tempDir.path,
  43. { ignore: [ '**/*', '!bower.json' ] },
  44. [ 'bower.json' ]
  45. );
  46. });
  47. it('refuses to ignore bower.json', function() {
  48. return ignoreTest(tempDir.path,
  49. { ignore: [ '**/*', '!index.js' ] },
  50. [ 'bower.json', 'index.js' ]
  51. );
  52. });
  53. it('removes all but one file deep down the tree', function() {
  54. return ignoreTest(tempDir.path,
  55. { ignore: [ '**/*', '!node_modules/underscore/index.js' ] },
  56. [
  57. 'bower.json',
  58. 'node_modules/underscore/index.js'
  59. ]
  60. );
  61. });
  62. });