cache.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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('uses cache', function (t) {
  22. t.plan(1);
  23. var p = parser({ cache: cache });
  24. p.end({ id: 'foo', file: files.foo, entry: false });
  25. var rows = [];
  26. p.on('data', function (row) { rows.push(row) });
  27. p.on('end', function () {
  28. t.same(rows.sort(cmp), [
  29. {
  30. id: 'foo',
  31. file: files.foo,
  32. source: sources.foo,
  33. deps: { './bar': files.bar }
  34. },
  35. {
  36. id: files.bar,
  37. file: files.bar,
  38. source: sources.bar,
  39. deps: {}
  40. }
  41. ].sort(cmp));
  42. });
  43. });
  44. function cmp (a, b) { return a.id < b.id ? -1 : 1 }