Skip to content

Commit

Permalink
removed request from dev dependencies, replaced with node-fetch (dat-…
Browse files Browse the repository at this point in the history
  • Loading branch information
joshterrill authored Jul 21, 2021
1 parent 890a00c commit b5fa5a6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@
"dependency-check": "^3.4.1",
"hypercore": "^6.25.2",
"mkdirp": "^0.5.4",
"node-fetch": "^2.6.1",
"pkg": "^4.4.4",
"random-access-memory": "^3.1.1",
"recursive-readdir-sync": "^1.0.6",
"request": "^2.88.2",
"standard": "^12.0.0",
"tape": "^4.13.2",
"tape-spawn": "^1.4.2",
Expand Down
14 changes: 14 additions & 0 deletions test/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ var rimraf = require('rimraf')
var encoding = require('dat-encoding')
var recursiveReadSync = require('recursive-readdir-sync')
var Dat = require('dat-node')
var fetch = require('node-fetch')

module.exports.matchLink = matchDatLink
module.exports.isDir = isDir
module.exports.testFolder = newTestFolder
module.exports.datJson = datJson
module.exports.shareFixtures = shareFixtures
module.exports.fileList = fileList
module.exports.fetchText = fetchText

function shareFixtures (opts, cb) {
if (typeof opts === 'function') return shareFixtures(null, opts)
Expand Down Expand Up @@ -75,3 +77,15 @@ function isDir (dir) {
return false
}
}

function fetchText (url) {
let resp = {}
return fetch(url).then(function (res) {
resp = res
return resp.text()
}).then(function (body) {
return { resp, body, error: null }
}).catch(function (error) {
return { error, resp: {}, body: null }
})
}
28 changes: 13 additions & 15 deletions test/http.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var path = require('path')
var test = require('tape')
var rimraf = require('rimraf')
var request = require('request')
var spawn = require('./helpers/spawn.js')
var { fetchText } = require('./helpers')

var dat = path.resolve(path.join(__dirname, '..', 'bin', 'cli.js'))
var fixtures = path.join(__dirname, 'fixtures')
Expand All @@ -16,20 +16,19 @@ test('http - share with http', function (t) {
var sharingHttp = output.indexOf('Serving files over http') > -1
if (!sharingHttp) return false

request('http://localhost:8080', function (err, resp, body) {
t.error(err, 'no error')
t.ok(resp.statusCode === 200, 'okay status')
fetchText('http://localhost:8080').then(function ({ resp, body, error }) {
t.error(error, 'no error')
t.ok(resp.status === 200, 'okay status')
t.ok(body)

request('http://localhost:8080/folder/nested/hello.txt', function (err, resp, body) {
t.error(err, 'no error')
t.ok(resp.statusCode === 200, 'okay status')
fetchText('http://localhost:8080/folder/nested/hello.txt').then(function ({ resp, body, error }) {
t.error(error, 'no error')
t.ok(resp.status === 200, 'okay status')
t.same(body, 'code for science and society', 'body of file okay')

st.kill()
})
})

return true
})
st.stderr.empty()
Expand All @@ -45,20 +44,19 @@ test('http - share with http other port', function (t) {
var sharingHttp = output.indexOf('Serving files over http') > -1
if (!sharingHttp) return false

request('http://localhost:3333', function (err, resp, body) {
t.error(err, 'no error')
t.ok(resp.statusCode === 200, 'okay status')
fetchText('http://localhost:3333').then(function ({ resp, body, error }) {
t.error(error, 'no error')
t.ok(resp.status === 200, 'okay status')
t.ok(body)

request('http://localhost:3333/folder/nested/hello.txt', function (err, resp, body) {
t.error(err, 'no error')
t.ok(resp.statusCode === 200, 'okay status')
fetchText('http://localhost:3333/folder/nested/hello.txt').then(function ({ resp, body, error }) {
t.error(error, 'no error')
t.ok(resp.status === 200, 'okay status')
t.same(body, 'code for science and society', 'body of file okay')

st.kill()
})
})

return true
})
st.stderr.empty()
Expand Down

0 comments on commit b5fa5a6

Please sign in to comment.