ignore_missing_cache.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. var parser = require('../');
  2. var test = require('tap').test;
  3. var fs = require('fs');
  4. var path = require('path');
  5. var files = {
  6. main: path.join(__dirname, '/ignore_missing/main.js'),
  7. other: path.join(__dirname, '/ignore_missing/other.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. var cache = {};
  14. cache[files.main] = {
  15. source: sources.main,
  16. deps: { './other': files.other }
  17. };
  18. cache[files.other] = {
  19. source: sources.other,
  20. deps: { 'missingModule': undefined }
  21. };
  22. test('ignoreMissing with cache', function (t) {
  23. t.plan(1);
  24. var p = parser({ cache: cache, ignoreMissing: true });
  25. p.end({file: files.main, entry: true});
  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: files.main,
  32. file: files.main,
  33. source: sources.main,
  34. entry: true,
  35. deps: { './other': files.other }
  36. },
  37. {
  38. id: files.other,
  39. file: files.other,
  40. source: sources.other,
  41. deps: { 'missingModule': undefined }
  42. }
  43. ].sort(cmp));
  44. });
  45. });
  46. function cmp (a, b) { return a.id < b.id ? -1 : 1 }