Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

download-node-tests.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/env node
  2. var concat = require('concat-stream')
  3. var cp = require('child_process')
  4. var fs = require('fs')
  5. var hyperquest = require('hyperquest')
  6. var path = require('path')
  7. var split = require('split')
  8. var through = require('through2')
  9. var url = 'https://api.github.com/repos/nodejs/node/contents'
  10. var dirs = [
  11. '/test/parallel',
  12. '/test/pummel'
  13. ]
  14. cp.execSync('rm -rf node/*.js', { cwd: path.join(__dirname, '../test') })
  15. var httpOpts = {
  16. headers: {
  17. 'User-Agent': null
  18. // auth if github rate-limits you...
  19. // 'Authorization': 'Basic ' + Buffer('username:password').toString('base64'),
  20. }
  21. }
  22. dirs.forEach(function (dir) {
  23. var req = hyperquest(url + dir, httpOpts)
  24. req.pipe(concat(function (data) {
  25. if (req.response.statusCode !== 200) {
  26. throw new Error(url + dir + ': ' + data.toString())
  27. }
  28. downloadBufferTests(dir, JSON.parse(data))
  29. }))
  30. })
  31. function downloadBufferTests (dir, files) {
  32. files.forEach(function (file) {
  33. if (!/test-buffer.*/.test(file.name)) return
  34. if (file.name === 'test-buffer-fakes.js') {
  35. // These teses only apply to node, where they're calling into C++ and need to
  36. // ensure the prototype can't be faked, or else there will be a segfault.
  37. return
  38. }
  39. console.log(file.download_url)
  40. var out = path.join(__dirname, '../test/node', file.name)
  41. hyperquest(file.download_url, httpOpts)
  42. .pipe(split())
  43. .pipe(testfixer(file.name))
  44. .pipe(fs.createWriteStream(out))
  45. .on('finish', function () {
  46. console.log('wrote ' + file.name)
  47. })
  48. })
  49. }
  50. function testfixer (filename) {
  51. var firstline = true
  52. return through(function (line, enc, cb) {
  53. line = line.toString()
  54. if (firstline) {
  55. // require buffer explicitly
  56. var preamble = 'var Buffer = require(\'../../\').Buffer;\n'
  57. if (/use strict/.test(line)) line += '\n' + preamble
  58. else line + preamble + '\n' + line
  59. firstline = false
  60. }
  61. // use `var` instead of `const`/`let`
  62. line = line.replace(/(const|let) /g, 'var ')
  63. // make `var common = require('common')` work
  64. line = line.replace(/(var common = require.*)/g, 'var common = { skip: function () {} };')
  65. // make `require('../common')` work
  66. line = line.replace(/require\('\.\.\/common'\);/g, '')
  67. // require browser buffer
  68. line = line.replace(/(.*)require\('buffer'\)(.*)/g, '$1require(\'../../\')$2')
  69. // comment out console logs
  70. line = line.replace(/(.*console\..*)/g, '// $1')
  71. // we can't reliably test typed array max-sizes in the browser
  72. if (filename === 'test-buffer-big.js') {
  73. line = line.replace(/(.*new Int8Array.*RangeError.*)/, '// $1')
  74. line = line.replace(/(.*new ArrayBuffer.*RangeError.*)/, '// $1')
  75. line = line.replace(/(.*new Float64Array.*RangeError.*)/, '// $1')
  76. }
  77. // https://github.com/nodejs/node/blob/v0.12/test/parallel/test-buffer.js#L1138
  78. // unfortunately we can't run this because crypto-browserify doesn't work in old
  79. // versions of ie
  80. if (filename === 'test-buffer.js') {
  81. line = line.replace(/^(\s*)(var crypto = require.*)/, '$1// $2')
  82. line = line.replace(/(crypto.createHash.*\))/, '1 /*$1*/')
  83. }
  84. cb(null, line + '\n')
  85. })
  86. }