dedupe.js 984 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. var sort = require('../');
  2. var test = require('tap').test;
  3. var through = require('through2');
  4. test('dedupe', function (t) {
  5. t.plan(1);
  6. var s = sort({ dedupe: true });
  7. var rows = [];
  8. function write (row, enc, next) { rows.push(row); next() }
  9. function end () {
  10. t.deepEqual(rows, [
  11. { id: '/bar.js', deps: {}, source: 'TWO' },
  12. { id: '/foo.js', deps: {}, source: 'TWO', dedupe: '/bar.js', sameDeps: true },
  13. {
  14. id: '/main.js',
  15. deps: { './foo': '/foo.js', './bar': '/bar.js' },
  16. source: 'ONE'
  17. }
  18. ]);
  19. }
  20. s.pipe(through.obj(write, end));
  21. s.write({
  22. id: '/main.js',
  23. deps: { './foo': '/foo.js', './bar': '/bar.js' },
  24. source: 'ONE'
  25. });
  26. s.write({
  27. id: '/foo.js',
  28. deps: {},
  29. source: 'TWO'
  30. });
  31. s.write({
  32. id: '/bar.js',
  33. deps: {},
  34. source: 'TWO'
  35. });
  36. s.end();
  37. });