filter.js 1004 B

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