standalone_sourcemap.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. var browserify = require('../');
  2. var fs = require('fs');
  3. var vm = require('vm');
  4. var test = require('tap').test;
  5. test('standalone in debug mode', function (t) {
  6. t.plan(3);
  7. var main = fs.readFileSync(__dirname + '/standalone/main.js');
  8. var b = browserify(__dirname + '/standalone/main.js', {
  9. standalone: 'stand-test',
  10. debug: true
  11. });
  12. b.bundle(function (err, buf) {
  13. var src = buf.toString('utf8');
  14. t.test('window global', function (t) {
  15. t.plan(2);
  16. var c = {
  17. window: {},
  18. done : done(t)
  19. };
  20. vm.runInNewContext(src + '\nwindow.standTest(done)', c);
  21. });
  22. t.test('CommonJS', function (t) {
  23. t.plan(2);
  24. var exp = {};
  25. var c = {
  26. module: { exports: exp },
  27. exports: exp,
  28. done : done(t)
  29. };
  30. vm.runInNewContext(src + '\nmodule.exports(done)', c);
  31. });
  32. t.test('RequireJS', function (t) {
  33. t.plan(2);
  34. var c = {
  35. define: function (dependencies, fn) {
  36. fn()(done(t));
  37. }
  38. };
  39. c.define.amd = true;
  40. vm.runInNewContext(src, c);
  41. });
  42. });
  43. });
  44. function done(t) {
  45. return function (one, two) {
  46. t.equal(one, 1);
  47. t.equal(two, 2);
  48. t.end();
  49. };
  50. }