Parcourir la source

Added a test for batch().

Eugene Lazutkin il y a 3 ans
Parent
commit
a091f07942
1 fichiers modifiés avec 29 ajouts et 0 suppressions
  1. 29 0
      tests/test-batch.mjs

+ 29 - 0
tests/test-batch.mjs

@@ -0,0 +1,29 @@
+'use strict';
+
+import test from 'tape-six';
+
+import chain from '../src/index.js';
+
+import {readString} from './helpers.mjs';
+import parser from '../src/jsonl/parser.js';
+
+import batch from '../src/utils/batch.js';
+
+test.asPromise('batch: smoke test', (t, resolve) => {
+  const pattern = [0, 1, true, false, null, {}, [], {a: 'b'}, ['c']],
+    result = [],
+    pipeline = chain([
+      readString(pattern.map(value => JSON.stringify(value)).join('\n')),
+      parser(),
+      batch(2)
+    ]);
+
+  pipeline.output.on('data', batch => {
+    t.ok(batch.length == 2 || batch.length == 1);
+    batch.forEach(object => (result[object.key] = object.value));
+  });
+  pipeline.output.on('end', () => {
+    t.deepEqual(pattern, result);
+    resolve();
+  });
+});