test-batch.mjs 750 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. import test from 'tape-six';
  3. import chain from '../src/index.js';
  4. import {readString} from './helpers.mjs';
  5. import parser from '../src/jsonl/parser.js';
  6. import batch from '../src/utils/batch.js';
  7. test.asPromise('batch: smoke test', (t, resolve) => {
  8. const pattern = [0, 1, true, false, null, {}, [], {a: 'b'}, ['c']],
  9. result = [],
  10. pipeline = chain([
  11. readString(pattern.map(value => JSON.stringify(value)).join('\n')),
  12. parser(),
  13. batch(2)
  14. ]);
  15. pipeline.output.on('data', batch => {
  16. t.ok(batch.length == 2 || batch.length == 1);
  17. batch.forEach(object => (result[object.key] = object.value));
  18. });
  19. pipeline.output.on('end', () => {
  20. t.deepEqual(pattern, result);
  21. resolve();
  22. });
  23. });