dedupe-nomap.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. var browserify = require('../');
  2. var test = require('tap').test;
  3. test('identical content gets deduped and the row gets a "nomap" flag set when sourcemaps are turned on', function (t) {
  4. t.plan(4)
  5. var rows = [];
  6. browserify({ debug: true })
  7. .on('dep', [].push.bind(rows))
  8. .require(require.resolve('./dup'), { entry: true })
  9. .bundle(check);
  10. function check(err, src) {
  11. if (err) return t.fail(err);
  12. var nomappeds = rows.filter(function (x) { return x.nomap });
  13. var nm = nomappeds[0];
  14. t.equal(rows.length, 3, 'packs 3 rows');
  15. t.equal(nomappeds.length, 1, 'one of has nomapped flag set');
  16. t.equal(
  17. rows.filter(function (x) {
  18. return x.id == nm.dedupeIndex
  19. }).length,
  20. 1,
  21. '2 rows with the same hash as the duplicate exist'
  22. );
  23. t.similar(
  24. nm.source,
  25. /arguments\[4\]\[.+\]\[0\]\.apply\(exports,arguments\)$/,
  26. 'redirects duplicate to original via require call'
  27. );
  28. }
  29. })
  30. test('identical content gets deduped and the row gets a "nomap" flag set when sourcemaps are turned off', function (t) {
  31. t.plan(4)
  32. var rows = [];
  33. browserify({ debug: false })
  34. .on('dep', [].push.bind(rows))
  35. .require(require.resolve('./dup'), { entry: true })
  36. .bundle(check);
  37. function check(err, src) {
  38. if (err) return t.fail(err);
  39. var nomappeds = rows.filter(function (x) { return x.nomap });
  40. var nm = nomappeds[0];
  41. t.equal(rows.length, 3, 'packs 3 rows');
  42. t.equal(nomappeds.length, 1, 'one of has nomapped flag set');
  43. t.equal(
  44. rows.filter(function (x) {
  45. return x.id == nm.dedupeIndex
  46. }).length,
  47. 1,
  48. '2 rows with the same hash as the duplicate exist'
  49. );
  50. t.similar(
  51. nm.source,
  52. /arguments\[4\]\[.+\]\[0\]\.apply\(exports,arguments\)$/,
  53. 'redirects duplicate to original via require call'
  54. );
  55. }
  56. })