dedupe_index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. var sort = require('../');
  2. var test = require('tap').test;
  3. var through = require('through2');
  4. test('dedupe index', function (t) {
  5. t.plan(1);
  6. var s = sort({ dedupe: true, index: true });
  7. var rows = [];
  8. function write (row, enc, next) { rows.push(row); next() }
  9. function end () {
  10. t.deepEqual(rows, [
  11. {
  12. id: '/bar.js',
  13. deps: {},
  14. source: 'TWO',
  15. index: 1,
  16. indexDeps: {}
  17. },
  18. {
  19. id: '/foo.js',
  20. deps: {},
  21. source: 'TWO',
  22. dedupe: '/bar.js',
  23. index: 2,
  24. indexDeps: {},
  25. dedupeIndex: 1,
  26. sameDeps: true
  27. },
  28. {
  29. id: '/main.js',
  30. deps: { './foo': '/foo.js', './bar': '/bar.js' },
  31. source: 'ONE',
  32. index: 3,
  33. indexDeps: { './foo': 2, './bar': 1 },
  34. }
  35. ]);
  36. }
  37. s.pipe(through.obj(write, end));
  38. s.write({
  39. id: '/main.js',
  40. deps: { './foo': '/foo.js', './bar': '/bar.js' },
  41. source: 'ONE'
  42. });
  43. s.write({
  44. id: '/foo.js',
  45. deps: {},
  46. source: 'TWO'
  47. });
  48. s.write({
  49. id: '/bar.js',
  50. deps: {},
  51. source: 'TWO'
  52. });
  53. s.end();
  54. });