ignore_missing.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. test('ignoreMissing', function (t) {
  14. t.plan(1);
  15. var p = parser({ignoreMissing: true});
  16. p.end({file: files.main, entry: true});
  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: files.main,
  23. file: files.main,
  24. source: sources.main,
  25. entry: true,
  26. deps: { './other': files.other }
  27. },
  28. {
  29. id: files.other,
  30. file: files.other,
  31. source: sources.other,
  32. deps: { 'missingModule': undefined }
  33. }
  34. ].sort(cmp));
  35. });
  36. });
  37. test('ignoreMissing off', function (t) {
  38. t.plan(1);
  39. var p = parser();
  40. p.end({file: files.main, entry: true});
  41. var rows = [];
  42. p.on('data', function (row) { rows.push(row) });
  43. p.on('error', function (err) {
  44. t.match(
  45. String(err),
  46. /Cannot find module 'missingModule'/
  47. );
  48. });
  49. p.on('end', function () {
  50. t.fail('should have errored');
  51. });
  52. });
  53. function cmp (a, b) { return a.id < b.id ? -1 : 1 }