From 92f16d3b561004d2e817367139afb462ec7e280d Mon Sep 17 00:00:00 2001 From: Dali Zheng Date: Sat, 29 Aug 2015 01:09:51 +0200 Subject: [PATCH] drop node-fetch --- doc/CHANGELOG.md | 4 ++++ package.json | 3 +-- test/integration/http.js | 23 +++++++++++-------- test/integration/serializers/ad_hoc.js | 18 +++++++-------- .../serializers/form_urlencoded.js | 2 +- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index de6fef6ad..762a3da16 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -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. diff --git a/package.json b/package.json index 4b56a940e..51b14cc1e 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" }, diff --git a/test/integration/http.js b/test/integration/http.js index e782844e7..66821a0fa 100644 --- a/test/integration/http.js +++ b/test/integration/http.js @@ -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 @@ -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 => { diff --git a/test/integration/serializers/ad_hoc.js b/test/integration/serializers/ad_hoc.js index ec8217e34..d42a34d3e 100644 --- a/test/integration/serializers/ad_hoc.js +++ b/test/integration/serializers/ad_hoc.js @@ -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') @@ -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') }) @@ -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') }) @@ -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') @@ -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') @@ -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') }) @@ -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') @@ -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') @@ -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') diff --git a/test/integration/serializers/form_urlencoded.js b/test/integration/serializers/form_urlencoded.js index 6d987eb4a..19cca4451 100644 --- a/test/integration/serializers/form_urlencoded.js +++ b/test/integration/serializers/form_urlencoded.js @@ -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')