crypto.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var test = require('tap').test;
  2. var spawn = require('child_process').spawn;
  3. var path = require('path');
  4. var fs = require('fs');
  5. var vm = require('vm');
  6. var concat = require('concat-stream');
  7. var semver = require('semver');
  8. var temp = require('temp');
  9. temp.track();
  10. var tmpdir = temp.mkdirSync({prefix: 'browserify-test'});
  11. fs.writeFileSync(tmpdir + '/main.js', 'beep(require("crypto"))\n');
  12. if (!ArrayBuffer.isView) ArrayBuffer.isView = function () { return false; };
  13. // `crypto-browserify` no longer works in node.js <4
  14. test('*-browserify libs from node_modules/', { skip: semver.lt(process.version, 'v4.0.0') }, function (t) {
  15. t.plan(2);
  16. var bin = __dirname + '/../bin/cmd.js';
  17. var ps = spawn(process.execPath, [ bin, 'main.js' ], { cwd : tmpdir });
  18. ps.stderr.pipe(process.stderr, { end : false });
  19. ps.on('exit', function (code) {
  20. t.equal(code, 0);
  21. });
  22. ps.stdout.pipe(concat(function (src) {
  23. var c = {
  24. Int32Array: Int32Array,
  25. ArrayBuffer: ArrayBuffer,
  26. Uint8Array: Uint8Array,
  27. DataView: DataView,
  28. beep : function (c) {
  29. t.equal(typeof c.createHash, 'function');
  30. },
  31. require: function () {}
  32. };
  33. vm.runInNewContext(src.toString('utf8'), c);
  34. }));
  35. });