Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80529 views
1
#!/usr/bin/env node
2
3
var hyperquest = require('hyperquest')
4
var concat = require('concat-stream')
5
var split = require('split')
6
var thru = require('through2')
7
var fs = require('fs')
8
9
var url = 'https://api.github.com/repos/iojs/io.js/contents'
10
var dirs = [
11
'/test/parallel',
12
'/test/pummel'
13
]
14
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
23
dirs.forEach(function (dir) {
24
var req = hyperquest(url + dir, httpOpts)
25
req.pipe(concat(function (data) {
26
if (req.response.statusCode !== 200) {
27
throw new Error(url + dir + ': ' + data.toString())
28
}
29
downloadBufferTests(dir, JSON.parse(data))
30
}))
31
})
32
33
function downloadBufferTests (dir, files) {
34
files.forEach(function (file) {
35
if (!/test-buffer.*/.test(file.name)) return
36
37
var path
38
if (file.name !== 'test-buffer-iterator.js') {
39
path = __dirname + '/../test/node/' + file.name
40
} else {
41
path = __dirname + '/../test/es6/' + file.name
42
}
43
44
var downloadUrl = file.download_url.replace('/master/', '/v1.x/')
45
46
hyperquest(downloadUrl, httpOpts)
47
.pipe(split())
48
.pipe(testfixer(file.name))
49
.pipe(fs.createWriteStream(path))
50
})
51
}
52
53
function testfixer (filename) {
54
var firstline = true
55
56
return thru(function (line, enc, cb) {
57
line = line.toString()
58
59
if (firstline) {
60
// require buffer explicitly
61
line = 'var Buffer = require(\'../../\').Buffer\n' +
62
'if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false\n' +
63
line
64
firstline = false
65
}
66
67
// comment out require('common')
68
line = line.replace(/(var common = require.*)/, 'var common = {};')
69
70
// require browser buffer
71
line = line.replace(/(.*)require\('buffer'\)(.*)/, '$1require(\'../../\')$2')
72
73
// smalloc is only used for kMaxLength
74
line = line.replace(/require\('smalloc'\)/, '{ kMaxLength: 0x3FFFFFFF }')
75
76
// comment out console logs
77
line = line.replace(/(.*console\..*)/, '// $1')
78
79
// we can't reliably test typed array max-sizes in the browser
80
if (filename === 'test-buffer-big.js') {
81
line = line.replace(/(.*new Int8Array.*RangeError.*)/, '// $1')
82
line = line.replace(/(.*new ArrayBuffer.*RangeError.*)/, '// $1')
83
line = line.replace(/(.*new Float64Array.*RangeError.*)/, '// $1')
84
}
85
86
// https://github.com/iojs/io.js/blob/v0.12/test/parallel/test-buffer.js#L38
87
// we can't run this because we need to support
88
// browsers that don't have typed arrays
89
if (filename === 'test-buffer.js') {
90
line = line.replace(/b\[0\] = -1;/, 'b[0] = 255;')
91
}
92
93
// https://github.com/iojs/io.js/blob/v0.12/test/parallel/test-buffer.js#L1138
94
// unfortunately we can't run this as it touches
95
// node streams which do an instanceof check
96
// and crypto-browserify doesn't work in old
97
// versions of ie
98
if (filename === 'test-buffer.js') {
99
line = line.replace(/^(\s*)(var crypto = require.*)/, '$1// $2')
100
line = line.replace(/(crypto.createHash.*\))/, '1 /*$1*/')
101
}
102
103
cb(null, line + '\n')
104
})
105
}
106
107