browserify_test.js 790 B

1234567891011121314151617181920212223242526272829
  1. var concat = require("concat-stream");
  2. var browserify = require("browserify");
  3. var assert = require("assert");
  4. var vm = require("vm");
  5. var b = browserify(__dirname + "/browsercode.js");
  6. b.transform(require("hbsfy"));
  7. // Browser mock
  8. var context = {
  9. document: {
  10. body: {}
  11. }
  12. };
  13. b.bundle({ debug: false }).pipe(concat(function(data) {
  14. // Browserify is not respecting the `debug` flag, so source maps
  15. // are included, blowing up the size.
  16. var stripped = data.toString('utf8').replace(/\/\/# sourceMappingURL.+/g, '');
  17. assert(stripped.length < 35000, "Bundle is too big! Maybe full Handlebars got compiled in?");
  18. vm.runInNewContext(data.toString(), context);
  19. }));
  20. setTimeout(function() {
  21. assert.equal(context.document.body.innerHTML.trim(), "<h1>HELLO</h1>");
  22. }, 400);