Skip to content

Commit

Permalink
drop node-fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
gr0uch committed Aug 28, 2015
1 parent da946e1 commit 92f16d3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
4 changes: 4 additions & 0 deletions doc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog


##### 1.2.5 (2015-08-29)
- Polish: drop `node-fetch` as a dependency for testing, instead use `http` module directly.


##### 1.2.4 (2015-08-29)
- Feature: add `enforceLinks` option, when set as `false` it will ignore referential integrity errors. Useful for client-side use.

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fortune",
"description": "High-level I/O for web applications.",
"version": "1.2.4",
"version": "1.2.5",
"license": "MIT",
"author": {
"email": "0x8890@airmail.cc",
Expand Down Expand Up @@ -38,7 +38,6 @@
"deep-equal": "^1.0.0",
"error-class": "^1.0.8",
"negotiator": "^0.5.3",
"node-fetch": "^1.3.2",
"tapdance": "^3.0.5",
"ws": "^0.8.0"
},
Expand Down
23 changes: 14 additions & 9 deletions test/integration/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ import { fail } from 'tapdance'
import testInstance from './test_instance'
import http from 'http'
import chalk from 'chalk'
import fetch from 'node-fetch'
import fortune from '../../lib'
import * as stderr from '../stderr'


const port = 1337

// Set promise polyfill for old versions of Node.
fetch.Promise = Promise


export default function httpTest (options, path, request, fn, change) {
let store
Expand Down Expand Up @@ -42,14 +38,23 @@ export default function httpTest (options, path, request, fn, change) {
request.headers['Content-Length'] = Buffer.byteLength(request.body)
}

return fetch(`http://localhost:${port}${path}`, request)
return new Promise((resolve, reject) =>
http.request(Object.assign({ port, path }, request), response => {
headers = response.headers
status = response.statusCode

const chunks = []

response.on('error', reject)
response.on('data', chunk => chunks.push(chunk))
response.on('end', () => resolve(Buffer.concat(chunks)))
}).end(request ? request.body : null))

.then(response => {
server.close()
stderr.debug(chalk.bold('Response status: ' + response.status))
stderr.debug(response.headers.raw())
; ({ headers, status } = response)
return store.disconnect().then(() => response.text())
stderr.debug(chalk.bold('Response status: ' + status))
stderr.debug(headers)
return store.disconnect().then(() => response.toString())
})

.then(text => {
Expand Down
18 changes: 9 additions & 9 deletions test/integration/serializers/ad_hoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ run(() => {
comment('get index')
return test('/', null, response => {
equal(response.status, 200, 'status is correct')
ok(~response.headers.get('content-type').indexOf(mediaType),
ok(~response.headers['content-type'].indexOf(mediaType),
'content type is correct')
deepEqual(response.body, [ 'user', 'animal', '☯' ],
'response body is correct')
Expand All @@ -27,7 +27,7 @@ run(() => {
comment('get empty collection')
return test(encodeURI('/☯'), null, response => {
equal(response.status, 200, 'status is correct')
ok(~response.headers.get('content-type').indexOf(mediaType),
ok(~response.headers['content-type'].indexOf(mediaType),
'content type is correct')
deepEqual(response.body, [], 'response body is correct')
})
Expand All @@ -38,7 +38,7 @@ run(() => {
comment('get records')
return test('/user', null, response => {
equal(response.status, 200, 'status is correct')
ok(~response.headers.get('content-type').indexOf(mediaType),
ok(~response.headers['content-type'].indexOf(mediaType),
'content type is correct')
equal(response.body.length, 3, 'response body is correct')
})
Expand All @@ -49,7 +49,7 @@ run(() => {
comment('get records by ID')
return test('/animal/1,%2Fwtf', null, response => {
equal(response.status, 200, 'status is correct')
ok(~response.headers.get('content-type').indexOf(mediaType),
ok(~response.headers['content-type'].indexOf(mediaType),
'content type is correct')
deepEqual(response.body.map(record => record.id),
[ 1, '/wtf' ], 'response body is correct')
Expand All @@ -63,7 +63,7 @@ run(() => {
fields: 'name,owner'
})}`, null, response => {
equal(response.status, 200, 'status is correct')
ok(~response.headers.get('content-type').indexOf(mediaType),
ok(~response.headers['content-type'].indexOf(mediaType),
'content type is correct')
deepEqual(response.body.map(record => Object.keys(record).length),
[ 4, 4, 4, 4 ], 'response body fields are correct')
Expand All @@ -77,7 +77,7 @@ run(() => {
'match[name]': 'Fido'
})}`, null, response => {
equal(response.status, 200, 'status is correct')
ok(~response.headers.get('content-type').indexOf(mediaType),
ok(~response.headers['content-type'].indexOf(mediaType),
'content type is correct')
equal(response.body[0].name, 'Fido', 'match is correct')
})
Expand All @@ -92,7 +92,7 @@ run(() => {
offset: 1
})}`, null, response => {
equal(response.status, 200, 'status is correct')
ok(~response.headers.get('content-type').indexOf(mediaType),
ok(~response.headers['content-type'].indexOf(mediaType),
'content type is correct')
deepEqual(response.body.map(record => record.name),
[ 'Fido', 'Sniffles' ], 'response body is correct')
Expand All @@ -112,7 +112,7 @@ run(() => {
} ]
}, response => {
equal(response.status, 201, 'status is correct')
ok(~response.headers.get('content-type').indexOf(mediaType),
ok(~response.headers['content-type'].indexOf(mediaType),
'content type is correct')
deepEqual(response.body.map(record => record.name),
[ 'Ayy lmao' ], 'response body is correct')
Expand All @@ -131,7 +131,7 @@ run(() => {
} ]
}, response => {
equal(response.status, 200, 'status is correct')
ok(~response.headers.get('content-type').indexOf(mediaType),
ok(~response.headers['content-type'].indexOf(mediaType),
'content type is correct')
deepEqual(response.body.map(record => record.name),
[ 'Ayy lmao' ], 'response body is correct')
Expand Down
2 changes: 1 addition & 1 deletion test/integration/serializers/form_urlencoded.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ run(() => {
})
}, response => {
equal(response.status, 201, 'status is correct')
ok(~response.headers.get('content-type').indexOf('application/json'),
ok(~response.headers['content-type'].indexOf('application/json'),
'content type is correct')
deepEqual(response.body.map(record => record.name),
[ 'Ayy lmao' ], 'response body is correct')
Expand Down

0 comments on commit 92f16d3

Please sign in to comment.