expose_str.js 1.1 KB

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