• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var path = require('path');
2var test = require('tape');
3var resolve = require('../');
4
5test('filter', function (t) {
6    t.plan(4);
7    var dir = path.join(__dirname, 'resolver');
8    var packageFilterArgs;
9    resolve('./baz', {
10        basedir: dir,
11        packageFilter: function (pkg, pkgfile) {
12            pkg.main = 'doom';
13            packageFilterArgs = [pkg, pkgfile];
14            return pkg;
15        }
16    }, function (err, res, pkg) {
17        if (err) t.fail(err);
18
19        t.equal(res, path.join(dir, 'baz/doom.js'), 'changing the package "main" works');
20
21        var packageData = packageFilterArgs[0];
22        t.equal(pkg, packageData, 'first packageFilter argument is "pkg"');
23        t.equal(packageData.main, 'doom', 'package "main" was altered');
24
25        var packageFile = packageFilterArgs[1];
26        t.equal(
27            packageFile,
28            path.join(dir, 'baz/package.json'),
29            'second packageFilter argument is "pkgfile"'
30        );
31
32        t.end();
33    });
34});
35