[6a3a178] | 1 | var path = require('path');
|
---|
| 2 | var test = require('tape');
|
---|
| 3 | var resolve = require('../');
|
---|
| 4 |
|
---|
| 5 | var resolverDir = path.join(__dirname, '/pathfilter/deep_ref');
|
---|
| 6 |
|
---|
| 7 | var pathFilterFactory = function (t) {
|
---|
| 8 | return function (pkg, x, remainder) {
|
---|
| 9 | t.equal(pkg.version, '1.2.3');
|
---|
| 10 | t.equal(x, path.join(resolverDir, 'node_modules/deep/ref'));
|
---|
| 11 | t.equal(remainder, 'ref');
|
---|
| 12 | return 'alt';
|
---|
| 13 | };
|
---|
| 14 | };
|
---|
| 15 |
|
---|
| 16 | test('#62: deep module references and the pathFilter', function (t) {
|
---|
| 17 | t.test('deep/ref.js', function (st) {
|
---|
| 18 | st.plan(3);
|
---|
| 19 |
|
---|
| 20 | resolve('deep/ref', { basedir: resolverDir }, function (err, res, pkg) {
|
---|
| 21 | if (err) st.fail(err);
|
---|
| 22 |
|
---|
| 23 | st.equal(pkg.version, '1.2.3');
|
---|
| 24 | st.equal(res, path.join(resolverDir, 'node_modules/deep/ref.js'));
|
---|
| 25 | });
|
---|
| 26 |
|
---|
| 27 | var res = resolve.sync('deep/ref', { basedir: resolverDir });
|
---|
| 28 | st.equal(res, path.join(resolverDir, 'node_modules/deep/ref.js'));
|
---|
| 29 | });
|
---|
| 30 |
|
---|
| 31 | t.test('deep/deeper/ref', function (st) {
|
---|
| 32 | st.plan(4);
|
---|
| 33 |
|
---|
| 34 | resolve(
|
---|
| 35 | 'deep/deeper/ref',
|
---|
| 36 | { basedir: resolverDir },
|
---|
| 37 | function (err, res, pkg) {
|
---|
| 38 | if (err) t.fail(err);
|
---|
| 39 | st.notEqual(pkg, undefined);
|
---|
| 40 | st.equal(pkg.version, '1.2.3');
|
---|
| 41 | st.equal(res, path.join(resolverDir, 'node_modules/deep/deeper/ref.js'));
|
---|
| 42 | }
|
---|
| 43 | );
|
---|
| 44 |
|
---|
| 45 | var res = resolve.sync(
|
---|
| 46 | 'deep/deeper/ref',
|
---|
| 47 | { basedir: resolverDir }
|
---|
| 48 | );
|
---|
| 49 | st.equal(res, path.join(resolverDir, 'node_modules/deep/deeper/ref.js'));
|
---|
| 50 | });
|
---|
| 51 |
|
---|
| 52 | t.test('deep/ref alt', function (st) {
|
---|
| 53 | st.plan(8);
|
---|
| 54 |
|
---|
| 55 | var pathFilter = pathFilterFactory(st);
|
---|
| 56 |
|
---|
| 57 | var res = resolve.sync(
|
---|
| 58 | 'deep/ref',
|
---|
| 59 | { basedir: resolverDir, pathFilter: pathFilter }
|
---|
| 60 | );
|
---|
| 61 | st.equal(res, path.join(resolverDir, 'node_modules/deep/alt.js'));
|
---|
| 62 |
|
---|
| 63 | resolve(
|
---|
| 64 | 'deep/ref',
|
---|
| 65 | { basedir: resolverDir, pathFilter: pathFilter },
|
---|
| 66 | function (err, res, pkg) {
|
---|
| 67 | if (err) st.fail(err);
|
---|
| 68 | st.equal(res, path.join(resolverDir, 'node_modules/deep/alt.js'));
|
---|
| 69 | st.end();
|
---|
| 70 | }
|
---|
| 71 | );
|
---|
| 72 | });
|
---|
| 73 |
|
---|
| 74 | t.end();
|
---|
| 75 | });
|
---|