Skip to content

Commit

Permalink
move away from event-stream, replace with stream-mock
Browse files Browse the repository at this point in the history
Part of pelias/pelias#801
Technique cribbed from pelias/openaddresses#457
  • Loading branch information
michaelkirk committed Dec 11, 2023
1 parent 9cccf9c commit 7212745
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
"through2-sink": "^1.0.0"
},
"devDependencies": {
"event-stream": "^4.0.0",
"jshint": "^2.5.6",
"pelias-mock-logger": "^1.1.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
11 changes: 6 additions & 5 deletions test/components/conformsTo.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const tape = require('tape');
const event_stream = require('event-stream');
const stream_mock = require('stream-mock');

const conformsTo = require('../../src/components/conformsTo');

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('conformsTo', (test) => {
Expand Down
11 changes: 6 additions & 5 deletions test/components/extractFieldsTest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var tape = require('tape');
var event_stream = require('event-stream');
const stream_mock = require('stream-mock');

var extractFields = require('../../src/components/extractFields');

Expand All @@ -14,10 +14,11 @@ var extractFields = require('../../src/components/extractFields');
* Callback signature should be something like function callback(error, result)
*/
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 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('readStreamComponents', function(test) {
Expand Down
11 changes: 6 additions & 5 deletions test/components/isActiveRecordTest.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
var tape = require('tape');
var event_stream = require('event-stream');
const stream_mock = require('stream-mock');

var isActiveRecord = require('../../src/components/isActiveRecord');

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 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('isActiveRecord', function(test) {
Expand Down
11 changes: 6 additions & 5 deletions test/components/isNotNullIslandRelated.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const tape = require('tape');
const event_stream = require('event-stream');
const stream_mock = require('stream-mock');

const isNotNullIslandRelated = require('../../src/components/isNotNullIslandRelated');

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 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('isNotNullIslandRelated tests', (test) => {
Expand Down
11 changes: 6 additions & 5 deletions test/components/recordHasIdAndPropertiesTest.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
var tape = require('tape');
var event_stream = require('event-stream');
const stream_mock = require('stream-mock');

var recordHasIdAndProperties = require('../../src/components/recordHasIdAndProperties');

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 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('recordHasIdAndProperties', function(test) {
Expand Down
11 changes: 6 additions & 5 deletions test/components/recordHasNameTest.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
var tape = require('tape');
var event_stream = require('event-stream');
var stream_mock = require('stream-mock');

var recordHasName = require('../../src/components/recordHasName');

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 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('recordHasName', function(test) {
Expand Down
5 changes: 3 additions & 2 deletions test/importStreamTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ var importStream = require('../src/importStream');
var sink = require('through2-sink');
var Document = require('pelias-model').Document;
var map_stream = require('through2-map');
var event_stream = require('event-stream');
const stream_mock = require('stream-mock');


tape('importStream', function(test) {
test.test('all wofRecords should be converted to Documents and sent to destination', function(t) {
var docs = [];

var recordStream = event_stream.readArray([
var recordStream = new stream_mock.ObjectReadableMock([
{ id: 1, place_type: 'placetype 1' },
{ id: 2, place_type: 'placetype 2' },
{ id: 3, place_type: 'placetype 3' },
Expand Down
11 changes: 6 additions & 5 deletions test/peliasDocGeneratorsTest.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
var tape = require('tape');
var Document = require('pelias-model').Document;
var peliasDocGenerators = require('../src/peliasDocGenerators');
var event_stream = require('event-stream');
const stream_mock = require('stream-mock');

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 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('create', function(test) {
Expand Down

0 comments on commit 7212745

Please sign in to comment.