1 | #!/usr/bin/env node
|
2 |
|
3 | var concat = require('concat-stream')
|
4 | var cp = require('child_process')
|
5 | var fs = require('fs')
|
6 | var hyperquest = require('hyperquest')
|
7 | var path = require('path')
|
8 | var split = require('split')
|
9 | var through = require('through2')
|
10 |
|
11 | var url = 'https://api.github.com/repos/nodejs/node/contents'
|
12 | var dirs = [
|
13 | '/test/parallel',
|
14 | '/test/pummel'
|
15 | ]
|
16 |
|
17 | cp.execSync('rm -rf node/*.js', { cwd: path.join(__dirname, '../test') })
|
18 |
|
19 | var httpOpts = {
|
20 | headers: {
|
21 | 'User-Agent': null
|
22 |
|
23 |
|
24 | }
|
25 | }
|
26 |
|
27 | dirs.forEach(function (dir) {
|
28 | var req = hyperquest(url + dir, httpOpts)
|
29 | req.pipe(concat(function (data) {
|
30 | if (req.response.statusCode !== 200) {
|
31 | throw new Error(url + dir + ': ' + data.toString())
|
32 | }
|
33 | downloadBufferTests(dir, JSON.parse(data))
|
34 | }))
|
35 | })
|
36 |
|
37 | function downloadBufferTests (dir, files) {
|
38 | files.forEach(function (file) {
|
39 | if (!/test-buffer.*/.test(file.name)) return
|
40 |
|
41 | if (file.name === 'test-buffer-fakes.js') {
|
42 |
|
43 |
|
44 | return
|
45 | }
|
46 |
|
47 | console.log(file.download_url)
|
48 |
|
49 | var out = path.join(__dirname, '../test/node', file.name)
|
50 | hyperquest(file.download_url, httpOpts)
|
51 | .pipe(split())
|
52 | .pipe(testfixer(file.name))
|
53 | .pipe(fs.createWriteStream(out))
|
54 | .on('finish', function () {
|
55 | console.log('wrote ' + file.name)
|
56 | })
|
57 | })
|
58 | }
|
59 |
|
60 | function testfixer (filename) {
|
61 | var firstline = true
|
62 |
|
63 | return through(function (line, enc, cb) {
|
64 | line = line.toString()
|
65 |
|
66 | if (firstline) {
|
67 |
|
68 | var preamble = 'var Buffer = require(\'../../\').Buffer;\n'
|
69 | if (/use strict/.test(line)) line += '\n' + preamble
|
70 | else line + preamble + '\n' + line
|
71 | firstline = false
|
72 | }
|
73 |
|
74 |
|
75 | line = line.replace(/(const|let) /g, 'var ')
|
76 |
|
77 |
|
78 | line = line.replace(/(var common = require.*)/g, 'var common = { skip: function () {} };')
|
79 |
|
80 |
|
81 | line = line.replace(/require\('\.\.\/common'\);/g, '')
|
82 |
|
83 |
|
84 | line = line.replace(/(.*)require\('buffer'\)(.*)/g, '$1require(\'../../\')$2')
|
85 |
|
86 |
|
87 | line = line.replace(/(.*console\..*)/g, '// $1')
|
88 |
|
89 |
|
90 | if (filename === 'test-buffer-big.js') {
|
91 | line = line.replace(/(.*new Int8Array.*RangeError.*)/, '// $1')
|
92 | line = line.replace(/(.*new ArrayBuffer.*RangeError.*)/, '// $1')
|
93 | line = line.replace(/(.*new Float64Array.*RangeError.*)/, '// $1')
|
94 | }
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | if (filename === 'test-buffer.js') {
|
100 | line = line.replace(/^(\s*)(var crypto = require.*)/, '$1// $2')
|
101 | line = line.replace(/(crypto.createHash.*\))/, '1 /*$1*/')
|
102 | }
|
103 |
|
104 | cb(null, line + '\n')
|
105 | })
|
106 | }
|