mocha.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. var assert = require('assert');
  2. var fileset = require('..');
  3. var EventEmitter = require('events').EventEmitter;
  4. describe('Sync API - Given a **.md pattern', function() {
  5. it('returns the list of matching file in this repo', function() {
  6. var results = fileset.sync('*.md', 'test/fixtures/**/*.md');
  7. assert.ok(Array.isArray(results), 'should be an array');
  8. assert.ok(results.length, 'should return at least one element');
  9. assert.equal(results.length, 1, 'actually, should return only one');
  10. });
  11. });
  12. describe('Sync API - Given a *.md and **.js pattern, and two exclude', function() {
  13. it('returns the list of matching file in this repo', function() {
  14. var results = fileset.sync('*.md *.js', 'CHANGELOG.md test/fixtures/**/*.md test/fixtures/**/*.js');
  15. assert.ok(Array.isArray(results), 'should be an array');
  16. assert.ok(results.length, 'should return at least one element');
  17. assert.equal(results.length, 3, 'actually, should return only 3');
  18. });
  19. });
  20. // Given a **.md pattern
  21. describe('Given a **.md pattern', function() {
  22. it('returns the list of matching file in this repo', function(done) {
  23. fileset('*.js', function(err, results) {
  24. if(err) return done(err);
  25. assert.ok(Array.isArray(results), 'should be an array');
  26. assert.ok(results.length, 'should return at least one element');
  27. assert.equal(results.length, 1, 'actually, should return only two');
  28. done();
  29. });
  30. });
  31. });
  32. describe('Say we want the **.js files, but not those in node_modules', function() {
  33. it('recursively walks the dir and returns the matching list', function(done) {
  34. fileset('**/*.js', '', function(err, results) {
  35. if(err) return done(err);
  36. assert.ok(Array.isArray(results), 'should be an array');
  37. assert.equal(results.length, 2);
  38. done();
  39. });
  40. });
  41. it('recursively walks the dir and returns the matching list', function(done) {
  42. fileset('**/*.js', function(err, results) {
  43. if(err) return done(err);
  44. assert.ok(Array.isArray(results), 'should be an array');
  45. assert.equal(results.length, 2);
  46. done();
  47. });
  48. });
  49. it('supports multiple paths at once', function(done) {
  50. fileset('**/*.js *.md', 'node_modules/**', function(err, results) {
  51. if(err) return done(err);
  52. assert.ok(Array.isArray(results), 'should be an array');
  53. assert.equal(results.length, 2);
  54. assert.deepEqual(results, [
  55. 'fixtures/an (odd) filename.js',
  56. 'mocha.js'
  57. ]);
  58. done();
  59. });
  60. });
  61. it('Should support multiple paths for excludes as well', function(done) {
  62. fileset('**/*.js *.md', 'node_modules/** **.md tests/*.js', function(err, results) {
  63. if(err) return done(err);
  64. assert.ok(Array.isArray(results), 'should be an array');
  65. assert.equal(results.length, 2);
  66. assert.deepEqual(results, [
  67. 'fixtures/an (odd) filename.js',
  68. 'mocha.js'
  69. ]);
  70. done();
  71. });
  72. });
  73. });
  74. describe('Testing out emmited events', function() {
  75. it('recursively walk the dir and return the matching list', function(done) {
  76. fileset('**/*.js', 'node_modules/**')
  77. .on('error', done)
  78. .on('end', function(results) {
  79. assert.ok(Array.isArray(results), 'should be an array');
  80. assert.equal(results.length, 2);
  81. done();
  82. });
  83. });
  84. it('support multiple paths at once', function(done) {
  85. fileset('**/*.js *.md', 'node_modules/**')
  86. .on('error', done)
  87. .on('end', function(results) {
  88. assert.ok(Array.isArray(results), 'should be an array');
  89. assert.equal(results.length, 2);
  90. assert.deepEqual(results, [
  91. 'fixtures/an (odd) filename.js',
  92. 'mocha.js'
  93. ]);
  94. done();
  95. });
  96. });
  97. });
  98. describe('Testing patterns passed as arrays', function() {
  99. it('match files passed as an array with odd filenames', function(done) {
  100. fileset(['fixtures/*.md', 'fixtures/an (odd) filename.js'], ['*.md'])
  101. .on('error', done)
  102. .on('end', function(results) {
  103. assert.ok(Array.isArray(results), 'should be an array');
  104. assert.equal(results.length, 1);
  105. assert.deepEqual(results, [
  106. 'fixtures/an (odd) filename.js',
  107. ]);
  108. done();
  109. });
  110. });
  111. });