tr_fn.js 900 B

1234567891011121314151617181920212223242526272829303132
  1. var mdeps = require('../');
  2. var test = require('tap').test;
  3. var JSONStream = require('JSONStream');
  4. var packer = require('browser-pack');
  5. var through = require('through2');
  6. var path = require('path');
  7. test('transform', function (t) {
  8. t.plan(3);
  9. var p = mdeps({
  10. transform: function (file) {
  11. return through(function (buf, enc, next) {
  12. this.push(String(buf)
  13. .replace(/AAA/g, '5')
  14. .replace(/BBB/g, '50')
  15. );
  16. next();
  17. });
  18. },
  19. transformKey: [ 'browserify', 'transform' ]
  20. });
  21. p.end(path.join(__dirname, '/files/tr_sh/main.js'));
  22. var pack = packer();
  23. p.pipe(JSONStream.stringify()).pipe(pack);
  24. var src = '';
  25. pack.on('data', function (buf) { src += buf });
  26. pack.on('end', function () {
  27. Function('t', src)(t);
  28. });
  29. });