unicode.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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/unicode/main.js'),
  7. foo: path.join(__dirname, '/files/unicode/foo.js'),
  8. bar: path.join(__dirname, '/files/unicode/bar.js')
  9. };
  10. var sources = Object.keys(files).reduce(function (acc, file) {
  11. acc[file] = fs.readFileSync(files[file], 'utf8');
  12. return acc;
  13. }, {});
  14. test('unicode deps', function (t) {
  15. t.plan(1);
  16. var p = parser();
  17. p.end(files.main);
  18. var rows = [];
  19. p.on('data', function (row) { rows.push(row) });
  20. p.on('end', function () {
  21. t.same(rows.sort(cmp), [
  22. {
  23. id: files.main,
  24. file: files.main,
  25. source: sources.main,
  26. entry: true,
  27. deps: { './foo': files.foo }
  28. },
  29. {
  30. id: files.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 }