expose.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var parser = require('../');
  2. var test = require('tap').test;
  3. var fs = require('fs');
  4. var path = require('path');
  5. var files = {
  6. foo: path.join(__dirname, '/files/foo.js'),
  7. bar: path.join(__dirname, '/files/bar.js')
  8. };
  9. var sources = Object.keys(files).reduce(function (acc, file) {
  10. acc[file] = fs.readFileSync(files[file], 'utf8');
  11. return acc;
  12. }, {});
  13. test('single id export', function (t) {
  14. t.plan(1);
  15. var p = parser();
  16. p.end({ id: 'foo', file: files.foo, entry: false });
  17. var rows = [];
  18. p.on('data', function (row) { rows.push(row) });
  19. p.on('end', function () {
  20. t.same(rows.sort(cmp), [
  21. {
  22. id: 'foo',
  23. file: files.foo,
  24. source: sources.foo,
  25. deps: { './bar': files.bar }
  26. },
  27. {
  28. id: files.bar,
  29. file: files.bar,
  30. source: sources.bar,
  31. deps: {}
  32. }
  33. ].sort(cmp));
  34. });
  35. });
  36. function cmp (a, b) { return a.id < b.id ? -1 : 1 }