flatten-path.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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('includeParents', 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. describe('subPath', function () {
  41. it('should keep top parent dirs from subPath option', function (done) {
  42. var topOnly = flattenPath(fileInstance, {subPath: [0, 2]});
  43. topOnly.should.equal('top1/top2/app.css');
  44. done();
  45. });
  46. it('should keep bottom parent dirs from subPath option', function (done) {
  47. var bottomOnly = flattenPath(fileInstance, {subPath: -2});
  48. bottomOnly.should.equal('bottom2/bottom1/app.css');
  49. done();
  50. });
  51. it('should keep top2 and bottom2 from subPath option', function (done) {
  52. var middleOnly = flattenPath(fileInstance, {subPath: [1, -1]});
  53. middleOnly.should.equal('top2/bottom2/app.css');
  54. done();
  55. });
  56. });
  57. });