standalone.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. var browserify = require('../');
  2. var vm = require('vm');
  3. var test = require('tap').test;
  4. test('standalone', function (t) {
  5. t.plan(3);
  6. var b = browserify(__dirname + '/standalone/main.js', {
  7. standalone: 'stand-test'
  8. });
  9. b.bundle(function (err, src) {
  10. t.test('window global', function (t) {
  11. t.plan(2);
  12. var c = {
  13. window: {},
  14. done : done(t)
  15. };
  16. vm.runInNewContext(src + 'window.standTest(done)', c);
  17. });
  18. t.test('CommonJS', function (t) {
  19. t.plan(2);
  20. var exp = {};
  21. var c = {
  22. module: { exports: exp },
  23. exports: exp,
  24. done : done(t)
  25. };
  26. vm.runInNewContext(src + 'module.exports(done)', c);
  27. });
  28. t.test('RequireJS', function (t) {
  29. t.plan(2);
  30. var c = {
  31. define: function (dependencies, fn) {
  32. fn()(done(t));
  33. }
  34. };
  35. c.define.amd = true;
  36. vm.runInNewContext(src, c);
  37. });
  38. });
  39. });
  40. test('A.B.C standalone', function (t) {
  41. t.plan(3);
  42. var b = browserify(__dirname + '/standalone/main.js', {
  43. standalone: 'A.B.C'
  44. });
  45. b.bundle(function (err, src) {
  46. t.test('window global', function (t) {
  47. t.plan(2);
  48. var c = { window: {} };
  49. vm.runInNewContext(src, c);
  50. c.window.A.B.C(done(t));
  51. });
  52. t.test('CommonJS', function (t) {
  53. t.plan(2);
  54. var exp = {};
  55. var c = {
  56. module: { exports: exp },
  57. exports: exp
  58. };
  59. vm.runInNewContext(src, c);
  60. c.module.exports(done(t));
  61. });
  62. t.test('RequireJS', function (t) {
  63. t.plan(2);
  64. var c = {
  65. define: function (dependencies, fn) {
  66. fn()(done(t));
  67. }
  68. };
  69. c.define.amd = true;
  70. vm.runInNewContext(src, c);
  71. });
  72. });
  73. });
  74. function done(t) {
  75. return function (one, two) {
  76. t.equal(one, 1);
  77. t.equal(two, 2);
  78. t.end();
  79. };
  80. }