subdir.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. var test = require('tape');
  2. var mdeps = require('module-deps');
  3. var bpack = require('browser-pack');
  4. var insert = require('../');
  5. var concat = require('concat-stream');
  6. var path = require('path');
  7. var fs = require('fs');
  8. var vm = require('vm');
  9. test('subdir', function (t) {
  10. t.plan(1);
  11. var deps = mdeps()
  12. var pack = bpack({ raw: true, hasExports: true });
  13. deps.pipe(pack).pipe(concat(function (src) {
  14. var c = {
  15. console: { log: log }
  16. };
  17. vm.runInNewContext(src, c);
  18. function log (value) {
  19. t.equal(value, false);
  20. }
  21. }));
  22. deps.write({ transform: inserter, global: true });
  23. deps.end({
  24. id: 'main',
  25. // Fake the file path so that the relative path to is-buffer becomes
  26. // "node_modules/is-buffer/index.js"
  27. file: path.join(__dirname, '../subdir_test.js'),
  28. source: fs.readFileSync(__dirname + '/subdir/main.js')
  29. });
  30. });
  31. function inserter (file) {
  32. return insert(file, {
  33. basedir: path.join(__dirname, '..')
  34. });
  35. }