Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.

Commit 96c8fb3

Browse files
Walkerdigitalsadhu
authored andcommitted
refactor(reader): Fixes based on PR feedback
1 parent 4da61c6 commit 96c8fb3

File tree

5 files changed

+57
-20
lines changed

5 files changed

+57
-20
lines changed

lib/reader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { Readable, PassThrough, Stream } = require('stream');
3+
const { Readable, PassThrough, Stream } = require('readable-stream');
44
const { parse } = require('JSONStream');
55
const mergeStream = require('merge-stream');
66
const { dedupe, sort, setOrder } = require('./util');

lib/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { Transform } = require('stream');
3+
const { Transform } = require('readable-stream');
44

55
function compareByOrder (a, b) {
66
if (a.order === b.order) {

package-lock.json

Lines changed: 37 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"JSONStream": "^1.3.1",
3030
"asset-pipe-common": "1.0.0-beta.6",
3131
"asset-pipe-sink-fs": "^1.0.0-beta.9",
32-
"merge-stream": "^1.0.1"
32+
"merge-stream": "^1.0.1",
33+
"readable-stream": "^2.3.3"
3334
},
3435
"devDependencies": {
3536
"eslint": "^4.1.1",

test/reader.test.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const Reader = require('../');
66
const SinkFs = require('asset-pipe-sink-fs');
77
const path = require('path');
88
const { sort, dedupe, compareByOrder } = require('../lib/util');
9-
const { Readable, PassThrough } = require('stream');
9+
const { Readable, PassThrough } = require('readable-stream');
1010

1111
function createSlowStream (sink, filePath, timeout = 1000) {
1212
const myStream = new PassThrough();
@@ -76,7 +76,7 @@ test('Dedupe of identical hashes occurs', done => {
7676
const bundle = [];
7777
reader.on('data', data => bundle.push(data.toString()));
7878
reader.on('end', () => {
79-
expect(bundle.length).toBe(1);
79+
expect(bundle).toHaveLength(1);
8080
done();
8181
});
8282
});
@@ -216,13 +216,13 @@ test('SortAndDedupe() rows without id value dropped', done => {
216216
.pipe(dedupe())
217217
.on('data', data => buffer.push(data))
218218
.on('end', () => {
219-
expect(buffer.length).toBe(2);
219+
expect(buffer).toHaveLength(2);
220220
done();
221221
});
222222
});
223223

224224
test('new Reader([s1,s2,s3,s4]) ensure dedupe and correct css concat order', done => {
225-
expect.assertions(3);
225+
expect.assertions(1);
226226
const sink = new SinkFs({
227227
path: path.join(__dirname, './test-assets'),
228228
});
@@ -237,16 +237,18 @@ test('new Reader([s1,s2,s3,s4]) ensure dedupe and correct css concat order', don
237237
const bundle = [];
238238
reader.on('data', data => bundle.push(data.toString()));
239239
reader.on('end', () => {
240-
expect(bundle[0]).toBe('/* my-module-3/main.css */\n\n/* my-module-3/dep.css */\n\n/* dep/main.css */\n');
241-
expect(bundle[1]).toBe('/* my-module-2/main.css */\n');
242-
expect(bundle[2]).toBe('/* my-module-1/main.css */\n');
240+
expect(bundle).toEqual([
241+
'/* my-module-3/main.css */\n\n/* my-module-3/dep.css */\n\n/* dep/main.css */\n',
242+
'/* my-module-2/main.css */\n',
243+
'/* my-module-1/main.css */\n',
244+
]);
243245
done();
244246
});
245247
});
246248
});
247249

248250
test('new Reader([s1,s2,s3,s4]) operates correctly under slow speed conditions', done => {
249-
expect.assertions(3);
251+
expect.assertions(1);
250252
const sink = new SinkFs({
251253
path: path.join(__dirname, './test-assets'),
252254
});
@@ -262,9 +264,11 @@ test('new Reader([s1,s2,s3,s4]) operates correctly under slow speed conditions',
262264
const bundle = [];
263265
reader.on('data', data => bundle.push(data.toString()));
264266
reader.on('end', () => {
265-
expect(bundle[0]).toBe('/* my-module-3/main.css */\n\n/* my-module-3/dep.css */\n\n/* dep/main.css */\n');
266-
expect(bundle[1]).toBe('/* my-module-2/main.css */\n');
267-
expect(bundle[2]).toBe('/* my-module-1/main.css */\n');
267+
expect(bundle).toEqual([
268+
'/* my-module-3/main.css */\n\n/* my-module-3/dep.css */\n\n/* dep/main.css */\n',
269+
'/* my-module-2/main.css */\n',
270+
'/* my-module-1/main.css */\n',
271+
]);
268272
done();
269273
});
270274
});
@@ -294,7 +298,7 @@ test('sort() transform operating on stream items without order property', done =
294298
.pipe(sort())
295299
.on('data', data => buffer.push(data))
296300
.on('end', () => {
297-
expect(buffer.length).toBe(1);
301+
expect(buffer).toHaveLength(1);
298302
done();
299303
});
300304
});

0 commit comments

Comments
 (0)