diff --git a/package.json b/package.json index 10172db..a0a9999 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ }, "devDependencies": { "deep-diff": "^1.0.0", - "event-stream": "^4.0.0", "intercept-stdout": "^0.1.2", "jshint": "^2.8.0", "nock": "^12.0.0", @@ -52,6 +51,7 @@ "pelias-model": "^7.0.0", "precommit-hook": "^3.0.0", "proxyquire": "^2.0.0", + "stream-mock": "^2.0.5", "tap-dot": "^2.0.0", "tape": "^5.0.0", "temp": "^0.9.0" diff --git a/test/index.js b/test/index.js index 1f2655d..7337668 100644 --- a/test/index.js +++ b/test/index.js @@ -1,17 +1,18 @@ 'use strict'; const tape = require('tape'); -const event_stream = require('event-stream'); +const stream_mock = require('stream-mock'); const proxyquire = require('proxyquire').noCallThru(); const through = require('through2'); const stream = require('../src/lookupStream'); function test_stream(input, testedStream, callback) { - const input_stream = event_stream.readArray(input); - const destination_stream = event_stream.writeArray(callback); - - input_stream.pipe(testedStream).pipe(destination_stream); + const reader = new stream_mock.ObjectReadableMock(input); + const writer = new stream_mock.ObjectWritableMock(); + writer.on('error', (e) => callback(e)); + writer.on('finish', () => callback(null, writer.data)); + reader.pipe(testedStream).pipe(writer); } tape('tests for main entry point', (test) => { @@ -236,3 +237,5 @@ tape('tests for main entry point', (test) => { t.end(); }); }); + +module.exports = { test_stream }; \ No newline at end of file diff --git a/test/lookupStreamEndonymsTest.js b/test/lookupStreamEndonymsTest.js index 07d80e2..6fd4b09 100644 --- a/test/lookupStreamEndonymsTest.js +++ b/test/lookupStreamEndonymsTest.js @@ -1,16 +1,9 @@ const tape = require('tape'); -const event_stream = require('event-stream'); +const test_stream = require('./index').test_stream; const Document = require('pelias-model').Document; const stream = require('../src/lookupStream'); -function test_stream(input, testedStream, callback) { - const input_stream = event_stream.readArray(input); - const destination_stream = event_stream.writeArray(callback); - - input_stream.pipe(testedStream).pipe(destination_stream); -} - tape('tests', (test) => { test.test('endonyms - country - Germany/Deutschland', (t) => { const inputDoc = new Document('whosonfirst', 'placetype', '1') diff --git a/test/lookupStreamPostalCityTest.js b/test/lookupStreamPostalCityTest.js index 9ceffa2..d55ac47 100644 --- a/test/lookupStreamPostalCityTest.js +++ b/test/lookupStreamPostalCityTest.js @@ -1,16 +1,9 @@ const tape = require('tape'); -const event_stream = require('event-stream'); +const test_stream = require('./index').test_stream; const Document = require('pelias-model').Document; const stream = require('../src/lookupStream'); -function test_stream(input, testedStream, callback) { - const input_stream = event_stream.readArray(input); - const destination_stream = event_stream.writeArray(callback); - - input_stream.pipe(testedStream).pipe(destination_stream); -} - tape('tests', (test) => { test.test('postal cities - USA lookup - ZIP 18964', (t) => { const inputDoc = new Document( 'whosonfirst', 'placetype', '1') diff --git a/test/lookupStreamTest.js b/test/lookupStreamTest.js index 0ea9539..1c42765 100644 --- a/test/lookupStreamTest.js +++ b/test/lookupStreamTest.js @@ -1,18 +1,11 @@ const tape = require('tape'); -const event_stream = require('event-stream'); +const test_stream = require('./index').test_stream; const Document = require('pelias-model').Document; const _ = require('lodash'); const proxyquire = require('proxyquire').noCallThru(); const stream = require('../src/lookupStream'); -function test_stream(input, testedStream, callback) { - const input_stream = event_stream.readArray(input); - const destination_stream = event_stream.writeArray(callback); - - input_stream.pipe(testedStream).pipe(destination_stream); -} - tape('tests', (test) => { test.test('doc without centroid should not modify input', (t) => { const input = [ diff --git a/test/pip/components/extractFieldsLocalizedNameTest.js b/test/pip/components/extractFieldsLocalizedNameTest.js index f43b11f..3ee6897 100644 --- a/test/pip/components/extractFieldsLocalizedNameTest.js +++ b/test/pip/components/extractFieldsLocalizedNameTest.js @@ -1,15 +1,7 @@ var tape = require('tape'); -var event_stream = require('event-stream'); +const test_stream = require('../../index').test_stream; var extractFields = require('../../../src/pip/components/extractFields'); - -function test_stream(input, testedStream, callback) { - var input_stream = event_stream.readArray(input); - var destination_stream = event_stream.writeArray(callback); - - input_stream.pipe(testedStream).pipe(destination_stream); -} - tape('extractFields localized name tests', function(test) { test.test('using wof:lang_x_spoken', function(t) { diff --git a/test/pip/components/extractFieldsTest.js b/test/pip/components/extractFieldsTest.js index b0bd36f..3f43965 100644 --- a/test/pip/components/extractFieldsTest.js +++ b/test/pip/components/extractFieldsTest.js @@ -1,12 +1,5 @@ var tape = require('tape'); -var event_stream = require('event-stream'); - -function test_stream(input, testedStream, callback) { - var input_stream = event_stream.readArray(input); - var destination_stream = event_stream.writeArray(callback); - - input_stream.pipe(testedStream).pipe(destination_stream); -} +const test_stream = require('../../index').test_stream; tape('extractFields tests', function(test) { test.test('non-special case record', function(t) { diff --git a/test/pip/components/filterOutCitylessNeighbourhoodsTest.js b/test/pip/components/filterOutCitylessNeighbourhoodsTest.js index 2bc0435..b965d48 100644 --- a/test/pip/components/filterOutCitylessNeighbourhoodsTest.js +++ b/test/pip/components/filterOutCitylessNeighbourhoodsTest.js @@ -1,17 +1,10 @@ const tape = require('tape'); -const event_stream = require('event-stream'); +const test_stream = require('../../index').test_stream; const async = require('async'); const proxyquire = require('proxyquire').noCallThru(); const filterOutCitylessNeighbourhoods = require('../../../src/pip/components/filterOutCitylessNeighbourhoods'); -function test_stream(input, testedStream, callback) { - const input_stream = event_stream.readArray(input); - const destination_stream = event_stream.writeArray(callback); - - input_stream.pipe(testedStream).pipe(destination_stream); -} - tape('non-neighbourhoods tests', test => { const non_neighbourhoods = [ 'borough', diff --git a/test/pip/components/filterOutHierarchylessNeighbourhoodsTest.js b/test/pip/components/filterOutHierarchylessNeighbourhoodsTest.js index 084de7c..f85a125 100644 --- a/test/pip/components/filterOutHierarchylessNeighbourhoodsTest.js +++ b/test/pip/components/filterOutHierarchylessNeighbourhoodsTest.js @@ -1,17 +1,10 @@ const tape = require('tape'); -const event_stream = require('event-stream'); +const test_stream = require('../../index').test_stream; const async = require('async'); const proxyquire = require('proxyquire').noCallThru(); const filterOutHierarchylessNeighbourhoods = require('../../../src/pip/components/filterOutHierarchylessNeighbourhoods'); -function test_stream(input, testedStream, callback) { - const input_stream = event_stream.readArray(input); - const destination_stream = event_stream.writeArray(callback); - - input_stream.pipe(testedStream).pipe(destination_stream); -} - tape('non-neighbourhoods tests', test => { const non_neighbourhoods = [ 'borough', diff --git a/test/pip/components/filterOutPointRecordsTest.js b/test/pip/components/filterOutPointRecordsTest.js index 93dc809..0a77864 100644 --- a/test/pip/components/filterOutPointRecordsTest.js +++ b/test/pip/components/filterOutPointRecordsTest.js @@ -1,15 +1,8 @@ var tape = require('tape'); -var event_stream = require('event-stream'); +const test_stream = require('../../index').test_stream; var filterOutPointRecords = require('../../../src/pip/components/filterOutPointRecords'); -function test_stream(input, testedStream, callback) { - var input_stream = event_stream.readArray(input); - var destination_stream = event_stream.writeArray(callback); - - input_stream.pipe(testedStream).pipe(destination_stream); -} - tape('filterOutPointNotPolygon', function (test){ test.test('record without geometry.type should return false', function(t) { var input = [ diff --git a/test/pip/components/simplifyGeometryTest.js b/test/pip/components/simplifyGeometryTest.js index ca3ca07..2953f29 100644 --- a/test/pip/components/simplifyGeometryTest.js +++ b/test/pip/components/simplifyGeometryTest.js @@ -1,12 +1,5 @@ var tape = require('tape'); -var event_stream = require('event-stream'); - -function test_stream(input, testedStream, callback) { - var input_stream = event_stream.readArray(input); - var destination_stream = event_stream.writeArray(callback); - - input_stream.pipe(testedStream).pipe(destination_stream); -} +const test_stream = require('../../index').test_stream; tape('simplifyGeometry tests', function(test) { test.test('Polygon geometry type should simplify first coordinates', function(t) {