Skip to content

Commit

Permalink
fix: support Node 8
Browse files Browse the repository at this point in the history
  • Loading branch information
larsgw committed Aug 29, 2019
1 parent 9ceec69 commit 52c0129
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const exec = require('child_process').execFileSync
const path = require('path')
const { URL } = require('url')
const _fetch = require('node-fetch')
const shared = require('./shared')

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@
"string-to-arraybuffer": "^1.0.2",
"sync-request": "^6.1.0",
"whatwg-url": "^7.0.0"
},
"engines": {
"node": ">=8"
}
}
9 changes: 5 additions & 4 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ try { convert = require('encoding').convert } catch (e) {}

class TestServer {
constructor () {
this.server = http.createServer(this.router)
this.server = http.createServer(this.router.bind(this))
this.port = 30001
this.hostname = 'localhost'
this.base = `http://${this.hostname}:${this.port}/`
// node 8 default keepalive timeout is 5000ms
// make it shorter here as we want to close server quickly at the end of tests
this.server.keepAliveTimeout = 1000
this.server.on('error', function (err) {
console.log(err.stack)
console.error(err.stack)
})
this.server.on('connection', function (socket) {
socket.setTimeout(1500)
Expand All @@ -31,7 +32,7 @@ class TestServer {
}

router (req, res) {
const p = (new URL(req.url)).pathname
const p = (new URL(req.url, this.base)).pathname

if (p === '/hello') {
res.statusCode = 200
Expand Down Expand Up @@ -387,7 +388,7 @@ class TestServer {
if (require.main === module) {
const server = new TestServer()
server.start(() => {
console.log(`Server started listening at ${server.hostname}:${server.port}`)
console.log(server.base)
})
}

Expand Down
4 changes: 2 additions & 2 deletions test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const resumer = require('resumer')
const FormData = require('form-data')
const stringToArrayBuffer = require('string-to-arraybuffer')
const URLSearchParamsPolyfill = require('@ungap/url-search-params')
const { URL } = require('whatwg-url')
const { URL, URLSearchParams } = require('url')
const zlib = require('zlib')

// test subjects
Expand Down Expand Up @@ -41,7 +41,7 @@ let base
before(done => {
local = spawn(process.execPath, [path.join(__dirname, 'server.js')])
local.stdout.on('data', chunk => {
base = `http://${chunk.toString().split(' ').pop().trim()}/`
base = chunk.toString().trim()
done()
})
})
Expand Down

0 comments on commit 52c0129

Please sign in to comment.