debug_standalone.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. var test = require('tap').test;
  2. var browserify = require('../');
  3. var through = require('through2');
  4. var vm = require('vm');
  5. test('ordinary debug', function (t) {
  6. t.plan(1);
  7. var stream = through();
  8. stream.push('console.log(1+2)');
  9. stream.push(null);
  10. var b = browserify({ debug: true });
  11. b.add(stream);
  12. b.bundle(function (err, buf) {
  13. var src = buf.toString('utf8');
  14. var last = src.split('\n').slice(-2)[0];
  15. t.ok(
  16. /\/\/# sourceMappingURL=data:application\/json;charset=utf-8;base64,[\w+\/=]+$/
  17. .test(last)
  18. );
  19. });
  20. });
  21. test('debug standalone', function (t) {
  22. t.plan(1);
  23. var stream = through();
  24. stream.push('console.log(1+2)');
  25. stream.push(null);
  26. var b = browserify({ debug: true, standalone: 'xyz' });
  27. b.add(stream);
  28. b.bundle(function (err, buf) {
  29. var src = buf.toString('utf8');
  30. var last = src.split('\n').slice(-2)[0];
  31. t.ok(
  32. /\/\/# sourceMappingURL=data:application\/json;charset=utf-8;base64,[\w+\/=]+$/
  33. .test(last)
  34. );
  35. });
  36. });
  37. test('debug standalone exposed', function (t) {
  38. t.plan(2);
  39. var stream = through();
  40. stream.push('console.log(1+2)');
  41. stream.push(null);
  42. var b = browserify({ debug: true, standalone: 'xyz' });
  43. b.require(__dirname + '/debug_standalone/x.js', { expose: 'xxx' });
  44. b.bundle(function (err, buf) {
  45. var src = buf.toString('utf8');
  46. var last = src.split('\n').slice(-2)[0];
  47. t.ok(
  48. /\/\/# sourceMappingURL=data:application\/json;charset=utf-8;base64,[\w+\/=]+$/
  49. .test(last)
  50. );
  51. var c = { window: {} };
  52. vm.runInNewContext(src, c);
  53. t.equal(c.window.xyz, 555);
  54. });
  55. });