insert.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var test = require('tape');
  2. var mdeps = require('module-deps');
  3. var bpack = require('browser-pack');
  4. var insert = require('../');
  5. var concat = require('concat-stream');
  6. var vm = require('vm');
  7. test('process.nextTick inserts', function (t) {
  8. t.plan(4);
  9. var s = mdeps()
  10. s.pipe(bpack({ raw: true })).pipe(concat(function (src) {
  11. var c = {
  12. t: t,
  13. setTimeout: setTimeout,
  14. clearTimeout: clearTimeout
  15. };
  16. vm.runInNewContext(src, c);
  17. }));
  18. s.write({ transform: inserter, global: true })
  19. s.end(__dirname + '/insert/main.js');
  20. });
  21. test('buffer inserts', function (t) {
  22. t.plan(2);
  23. var s = mdeps({
  24. modules: { buffer: require.resolve('buffer/') }
  25. });
  26. s.pipe(bpack({ raw: true })).pipe(concat(function (src) {
  27. var c = {
  28. t: t,
  29. setTimeout: setTimeout,
  30. clearTimeout: clearTimeout,
  31. Uint8Array: Uint8Array,
  32. DataView: DataView
  33. };
  34. vm.runInNewContext(src, c);
  35. }));
  36. s.write({ transform: inserter, global: true })
  37. s.end(__dirname + '/insert/buffer.js');
  38. });
  39. function inserter (file) {
  40. return insert(file, {
  41. basedir: __dirname + '/insert'
  42. });
  43. }