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