Skip to content

Commit

Permalink
chore(dependencies): use stream-mock instead of event-stream (#319)
Browse files Browse the repository at this point in the history
* move away from event-stream, replace with stream-mock

Part of pelias/pelias#801
Technique cribbed from pelias/openaddresses#457

* share test_stream implementation
  • Loading branch information
michaelkirk authored Dec 13, 2023
1 parent 362513e commit b6211d5
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 79 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
},
"devDependencies": {
"deep-diff": "^1.0.0",
"event-stream": "^4.0.0",
"intercept-stdout": "^0.1.2",
"jshint": "^2.8.0",
"nock": "^12.0.0",
"pelias-mock-logger": "^1.3.0",
"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"
Expand Down
13 changes: 8 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down Expand Up @@ -236,3 +237,5 @@ tape('tests for main entry point', (test) => {
t.end();
});
});

module.exports = { test_stream };
9 changes: 1 addition & 8 deletions test/lookupStreamEndonymsTest.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
9 changes: 1 addition & 8 deletions test/lookupStreamPostalCityTest.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
9 changes: 1 addition & 8 deletions test/lookupStreamTest.js
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down
10 changes: 1 addition & 9 deletions test/pip/components/extractFieldsLocalizedNameTest.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
9 changes: 1 addition & 8 deletions test/pip/components/extractFieldsTest.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
9 changes: 1 addition & 8 deletions test/pip/components/filterOutCitylessNeighbourhoodsTest.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
9 changes: 1 addition & 8 deletions test/pip/components/filterOutPointRecordsTest.js
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down
9 changes: 1 addition & 8 deletions test/pip/components/simplifyGeometryTest.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit b6211d5

Please sign in to comment.