Skip to content

Commit

Permalink
fix: only test parseStream with node 18 and greater
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny committed May 25, 2022
1 parent 18f0a21 commit 0f48fe0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@
"homepage": "https://github.com/cheminfo/arraybuffer-xml-parser#readme",
"devDependencies": {
"@types/he": "^1.1.2",
"@types/jest": "^27.5.0",
"@types/jest": "^27.5.1",
"cheminfo-build": "^1.1.11",
"eslint": "^8.15.0",
"eslint": "^8.16.0",
"eslint-config-cheminfo-typescript": "^10.4.0",
"he": "^1.2.0",
"iobuffer": "^5.1.0",
"jest": "^28.1.0",
"pako": "^2.0.4",
"prettier": "^2.6.2",
"rimraf": "^3.0.2",
"ts-jest": "^28.0.2",
"typescript": "^4.6.4",
"ts-jest": "^28.0.3",
"typescript": "^4.7.2",
"uint8-base64": "^0.1.1"
},
"dependencies": {
Expand Down
52 changes: 27 additions & 25 deletions src/__tests__/parseStream.test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
import { open } from 'fs/promises';
import { join } from 'path';
import { TransformStream } from 'stream/web';

import { parseStream } from '../parseStream';

describe('parseStream', () => {
it('simple case', async () => {
const file = await open(join(__dirname, 'assets/sample.xml'), 'r');
const CHUNK_SIZE = 10;

const transformStream = new TransformStream({
start: function start() {}, // required.
transform: async function transform(chunk, controller) {
if (chunk === null) controller.terminate();
chunk = new Uint8Array(await chunk);
for (let i = 0; i < chunk.length; i += CHUNK_SIZE) {
controller.enqueue(chunk.slice(i, i + CHUNK_SIZE));
}
},
});
// eslint-disable-next-line jest/no-if
if (Number(process.versions.node.split('.')[0]) >= 18) {
const file = await open(join(__dirname, 'assets/sample.xml'), 'r');
const CHUNK_SIZE = 10;
const transformStream = new TransformStream({
start: function start() {}, // required.
transform: async function transform(chunk, controller) {
if (chunk === null) controller.terminate();
chunk = new Uint8Array(await chunk);
for (let i = 0; i < chunk.length; i += CHUNK_SIZE) {
controller.enqueue(chunk.slice(i, i + CHUNK_SIZE));
}
},
});

const results = [];
//@ts-expect-error feature is too new
const readableStream = file.readableWebStream();
for await (let entry of parseStream(
readableStream.pipeThrough(transformStream),
'address',
)) {
results.push(entry);
//console.log(entry);
}
expect(results).toMatchInlineSnapshot(`
const results = [];
//@ts-expect-error feature is too new
const readableStream = file.readableWebStream();
for await (let entry of parseStream(
readableStream.pipeThrough(transformStream),
'address',
)) {
results.push(entry);
//console.log(entry);
}
expect(results).toMatchInlineSnapshot(`
Array [
Object {
"buildingNo": 1,
Expand Down Expand Up @@ -57,5 +58,6 @@ describe('parseStream', () => {
},
]
`);
}
});
});
2 changes: 0 additions & 2 deletions src/parseStream.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ReadableStream } from 'stream/web';

import {
defaultOptions,
StreamParseOptions,
Expand Down

0 comments on commit 0f48fe0

Please sign in to comment.