source.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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, '/files/main.js'),
  7. foo: path.join(__dirname, '/files/foo.js'),
  8. bar: path.join(__dirname, '/files/bar.js'),
  9. extra: path.join(__dirname, '/files/extra.js')
  10. };
  11. var sources = {
  12. foo: fs.readFileSync(files.foo, 'utf8'),
  13. bar: fs.readFileSync(files.bar, 'utf8'),
  14. extra: fs.readFileSync(files.extra, 'utf8'),
  15. main: "console.log(require('./foo')(5)); require('./extra.js')"
  16. };
  17. test('source', function (t) {
  18. t.plan(1);
  19. var p = parser();
  20. p.end({
  21. file: files.main,
  22. source: sources.main,
  23. entry: true
  24. });
  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: files.main,
  31. file: files.main,
  32. source: sources.main,
  33. entry: true,
  34. deps: { './foo': files.foo, './extra.js': files.extra }
  35. },
  36. {
  37. id: files.foo,
  38. file: files.foo,
  39. source: sources.foo,
  40. deps: { './bar': files.bar }
  41. },
  42. {
  43. id: files.bar,
  44. file: files.bar,
  45. source: sources.bar,
  46. deps: {}
  47. },
  48. {
  49. id: files.extra,
  50. file: files.extra,
  51. source: sources.extra,
  52. deps: {}
  53. },
  54. ].sort(cmp));
  55. });
  56. });
  57. function cmp (a, b) { return a.id < b.id ? -1 : 1 }