indexed.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. var sort = require('../');
  2. var test = require('tap').test;
  3. var through = require('through2');
  4. test('indexed', function (t) {
  5. t.plan(1);
  6. var s = sort({ 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. index: 1,
  15. indexDeps: {}
  16. },
  17. {
  18. id: '/foo.js',
  19. deps: { './bar': '/bar.js' },
  20. index: 2,
  21. indexDeps: { './bar': 1 }
  22. },
  23. {
  24. id: '/main.js',
  25. deps: { './foo': '/foo.js' },
  26. index: 3,
  27. indexDeps: { './foo': 2 }
  28. },
  29. ]);
  30. }
  31. s.pipe(through.obj(write, end));
  32. s.write({ id: '/main.js', deps: { './foo': '/foo.js' } });
  33. s.write({ id: '/foo.js', deps: { './bar': '/bar.js' } });
  34. s.write({ id: '/bar.js', deps: {} });
  35. s.end();
  36. });