tr.js 778 B

12345678910111213141516171819202122232425262728
  1. var browserify = require('../');
  2. var vm = require('vm');
  3. var test = require('tap').test;
  4. var through = require('through2');
  5. test('function transform', function (t) {
  6. t.plan(7);
  7. var b = browserify(__dirname + '/tr/main.js');
  8. b.transform({ global: true }, function (file) {
  9. return through(function (buf, enc, next) {
  10. this.push(String(buf).replace(/ZZZ/g, '1'));
  11. next();
  12. });
  13. });
  14. b.transform(function (file) {
  15. return through(function (buf, enc, next) {
  16. this.push(String(buf)
  17. .replace(/AAA/g, '5')
  18. .replace(/BBB/g, '50')
  19. );
  20. next();
  21. })
  22. });
  23. b.bundle(function (err, src) {
  24. vm.runInNewContext(src, { t: t });
  25. });
  26. });