Skip to content

Commit be31744

Browse files
committed
Maybe hopefully fix broken tests on slower Windows VMs, harden it up a bit along the way
1 parent d0455c2 commit be31744

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

test-qq-multipart.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
var test = require('tape')
2-
var fs = require('fs')
3-
var path = require('path')
4-
var tiny = require('./dist.js')
5-
var http = require('http')
6-
var server
1+
let test = require('tape')
2+
let fs = require('fs')
3+
let path = require('path')
4+
let tiny = require('./dist.js')
5+
let http = require('http')
6+
let port = 3000
7+
let host = 'localhost'
8+
let server
79

810
test('make a multipart post', t=> {
911
t.plan(1)
@@ -14,30 +16,30 @@ test('start a fake server', t=> {
1416
t.plan(1)
1517
// somebody thought this was intuitive
1618
server = http.createServer((req, res)=> {
17-
var body = []
18-
req.on('data', function _data(data) {
19-
//console.log(data.toString())
20-
body.push(data)
21-
})
19+
let body = []
20+
req.on('data', chunk => body.push(chunk))
2221
req.on('end', function _end() {
23-
console.log('END', Buffer.concat(body).toString())
22+
body = Buffer.concat(body).toString()
23+
res.end(body)
2424
})
25-
res.end('ugh')
26-
}).listen(3000, x=> {
27-
t.ok(true, 'opened server')
25+
})
26+
server.listen({port, host}, err=> {
27+
if (err) t.fail(err)
28+
else t.pass(`Started server`)
2829
})
2930
})
3031

3132
test('can multipart/form-data post', t=> {
3233
t.plan(1)
34+
let file = fs.readFileSync(path.join(__dirname, 'readme.md'))
3335
tiny.post({
34-
url: 'http://localhost:3000',
36+
url: `http://${host}:${port}`,
3537
headers: {
36-
'Content-Type': 'multipart/form-data'
38+
'content-type': 'multipart/form-data'
3739
},
3840
data: {
3941
one: 1,
40-
anotherFile: fs.createReadStream(path.join(__dirname, 'readme.md'))
42+
file
4143
}
4244
},
4345
function _post(err, data) {
@@ -46,7 +48,7 @@ test('can multipart/form-data post', t=> {
4648
console.log(err)
4749
}
4850
else {
49-
t.ok(true, 'posted')
51+
t.ok(data.body.includes(file.toString()), 'posted')
5052
console.log(data)
5153
}
5254
})

0 commit comments

Comments
 (0)