cache_partial.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 = {
  10. foo: 'notreal foo',
  11. bar: fs.readFileSync(files.bar, 'utf8')
  12. };
  13. var cache = {};
  14. cache[files.foo] = {
  15. source: sources.foo,
  16. deps: { './bar': files.bar }
  17. };
  18. test('uses cache and reads from disk', function (t) {
  19. t.plan(1);
  20. var p = parser({ cache: cache });
  21. p.end({ id: 'foo', file: files.foo, entry: false });
  22. var rows = [];
  23. p.on('data', function (row) { rows.push(row) });
  24. p.on('end', function () {
  25. t.same(rows.sort(cmp), [
  26. {
  27. id: 'foo',
  28. file: files.foo,
  29. source: sources.foo,
  30. deps: { './bar': files.bar }
  31. },
  32. {
  33. id: files.bar,
  34. file: files.bar,
  35. source: sources.bar,
  36. deps: {}
  37. }
  38. ].sort(cmp));
  39. });
  40. });
  41. function cmp (a, b) { return a.id < b.id ? -1 : 1 }