flatten-path.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. var should = require('should');
  2. var path = require('path');
  3. var flattenPath = require('../lib/flatten-path');
  4. var fileInstance;
  5. describe('gulp-flatten', function () {
  6. beforeEach(function () {
  7. fileInstance = {
  8. base: '/some/project/src/',
  9. path: '/some/project/src/top1/top2/bottom2/bottom1/app.css',
  10. relative: 'top1/top2/bottom2/bottom1/app.css'
  11. };
  12. });
  13. describe('flatten-path()', function () {
  14. it('should keep top parent dirs from indludeParents option', function (done) {
  15. var topOnly = flattenPath(fileInstance, {includeParents: 1});
  16. topOnly.should.equal('top1/app.css');
  17. done();
  18. });
  19. it('should keep bottom parent dirs from indludeParents option', function (done) {
  20. var bottomOnly = flattenPath(fileInstance, {includeParents: [0, 1]});
  21. bottomOnly.should.equal('bottom1/app.css');
  22. done();
  23. });
  24. it('should treat negative number in indludeParents as bottom parent levels', function (done) {
  25. var bottomOnly = flattenPath(fileInstance, {includeParents: -1});
  26. bottomOnly.should.equal('bottom1/app.css');
  27. done();
  28. });
  29. it('should keep top and bottom parent dirs from indludeParents option', function (done) {
  30. var both = flattenPath(fileInstance, {includeParents: [1, 2]});
  31. both.should.equal('top1/bottom2/bottom1/app.css');
  32. done();
  33. });
  34. it('should pick relative path if indludeParents bottom+top too long', function (done) {
  35. var relative = flattenPath(fileInstance, {includeParents: [10, 10]});
  36. relative.should.equal(fileInstance.relative);
  37. done();
  38. });
  39. });
  40. });