dedupe-deps.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. var browserify = require('../');
  2. var test = require('tap').test;
  3. test('identical content gets deduped and the row gets an implicit dep on the original source', function (t) {
  4. t.plan(1)
  5. var rows = [];
  6. browserify()
  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 deduped = rows.filter(function (x) { return x.dedupeIndex });
  13. var d = deduped[0];
  14. t.deepEqual(d.deps, { 'dup': d.dedupeIndex }, "adds implicit dep");
  15. }
  16. })
  17. test('identical content gets deduped with fullPaths', function (t) {
  18. t.plan(1)
  19. var rows = [];
  20. browserify({fullPaths: true})
  21. .on('dep', [].push.bind(rows))
  22. .require(require.resolve('./dup'), { entry: true })
  23. .bundle(check);
  24. function check(err, src) {
  25. if (err) return t.fail(err);
  26. var deduped = rows.filter(function (x) { return x.dedupe });
  27. var d = deduped[0];
  28. t.deepEqual(
  29. d.source,
  30. 'arguments[4]['+ JSON.stringify(d.dedupe) + '][0]'
  31. + '.apply(exports,arguments)',
  32. "dedupes content"
  33. );
  34. }
  35. })
  36. test('identical content does not get deduped with dedupe option false', function (t) {
  37. t.plan(1)
  38. var rows = [];
  39. browserify({fullPaths: true, dedupe: false})
  40. .on('dep', [].push.bind(rows))
  41. .require(require.resolve('./dup'), { entry: true })
  42. .bundle(check);
  43. function check(err, src) {
  44. if (err) return t.fail(err);
  45. var deduped = rows.filter(function (x) { return x.dedupe });
  46. t.equal(deduped.length, 0, 'does not dedupe');
  47. }
  48. })