array.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. var browserify = require('../');
  2. var vm = require('vm');
  3. var test = require('tap').test;
  4. test('array add', function (t) {
  5. var expected = [ 'ONE', 'TWO', 'THREE' ];
  6. t.plan(expected.length);
  7. var b = browserify();
  8. var files = [
  9. __dirname + '/array/one.js',
  10. __dirname + '/array/two.js',
  11. __dirname + '/array/three.js'
  12. ];
  13. b.add(files);
  14. b.bundle(function (err, src) {
  15. vm.runInNewContext(src, { console: { log: log } });
  16. function log (msg) {
  17. t.equal(msg, expected.shift());
  18. }
  19. });
  20. });
  21. test('array require', function (t) {
  22. t.plan(3);
  23. var b = browserify();
  24. var files = [ 'defined', 'subarg' ];
  25. b.require(files);
  26. b.bundle(function (err, src) {
  27. var c = {};
  28. vm.runInNewContext(src, c);
  29. t.equal(c.require('defined')(undefined, true), true);
  30. t.equal(c.require('defined')(undefined, false), false);
  31. t.deepEqual(c.require('subarg')(['-x', '3']), { x: 3, _: [] });
  32. });
  33. });
  34. test('array require opts', function (t) {
  35. t.plan(3);
  36. var b = browserify();
  37. var files = [
  38. { file: require.resolve('defined'), expose: 'abc' },
  39. { file: require.resolve('subarg'), expose: 'def' }
  40. ];
  41. b.require(files);
  42. b.bundle(function (err, src) {
  43. var c = {};
  44. vm.runInNewContext(src, c);
  45. t.equal(c.require('abc')(undefined, true), true);
  46. t.equal(c.require('abc')(undefined, false), false);
  47. t.deepEqual(c.require('def')(['-x', '3']), { x: 3, _: [] });
  48. });
  49. });
  50. test('array external', function (t) {
  51. t.plan(2);
  52. var b = browserify(__dirname + '/external/main.js');
  53. b.external(['util','freelist']);
  54. b.bundle(function (err, src) {
  55. if (err) return t.fail(err);
  56. vm.runInNewContext(
  57. 'function require (x) {'
  58. + 'if (x==="freelist") return function (n) { return n + 1000 }'
  59. + '}'
  60. + src,
  61. { t: t }
  62. );
  63. });
  64. });