cache_expose.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. var parser = require('../');
  2. var test = require('tap').test;
  3. var path = require('path');
  4. var files = {
  5. foo: path.join(__dirname, '/files/foo.js'),
  6. bar: path.join(__dirname, '/files/bar.js')
  7. };
  8. var sources = {
  9. foo: 'notreal foo',
  10. bar: 'notreal bar'
  11. };
  12. var cache = {};
  13. cache[files.foo] = {
  14. source: sources.foo,
  15. deps: { './bar': files.bar }
  16. };
  17. cache[files.bar] = {
  18. source: sources.bar,
  19. deps: {}
  20. };
  21. test('cache preserves expose and entry', function (t) {
  22. t.plan(1);
  23. var p = parser({ cache: cache });
  24. p.write({ id: files.bar, expose: 'bar2', entry: false });
  25. p.end({ id: 'foo', file: files.foo, entry: true, expose: 'foo2' });
  26. var rows = [];
  27. p.on('data', function (row) { rows.push(row) });
  28. p.on('end', function () {
  29. t.same(rows.sort(cmp), [
  30. {
  31. id: 'foo',
  32. expose: 'foo2',
  33. entry: true,
  34. file: files.foo,
  35. source: sources.foo,
  36. deps: { './bar': files.bar }
  37. },
  38. {
  39. id: files.bar,
  40. expose: 'bar2',
  41. file: files.bar,
  42. source: sources.bar,
  43. deps: {}
  44. }
  45. ].sort(cmp));
  46. });
  47. });
  48. function cmp (a, b) { return a.id < b.id ? -1 : 1 }