All files / json-crdt/__bench__/util concurrent-trace.ts

100% Statements 20/20
100% Branches 0/0
100% Functions 2/2
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 211x 1x 1x 1x 1x   1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 9109x 2x    
import * as path from 'path';
import * as fs from 'fs';
import {Patch} from '../../../json-crdt-patch';
import {CborDecoder} from '@jsonjoy.com/json-pack/lib/cbor/CborDecoder';
import {JsonDecoder} from '@jsonjoy.com/json-pack/lib/json/JsonDecoder';
 
export const loadConcurrentTrace = (traceName: string): [batch: Patch[], view: unknown] => {
  const root = path.resolve(__dirname, '..', '..', '..', '..');
  const dir = path.join(root, 'node_modules', 'json-crdt-traces', 'traces', 'text', 'concurrent', traceName);
  const patchFile = path.join(dir, 'patches.bin');
  const viewFile = path.join(dir, 'view.json');
  const buf = fs.readFileSync(patchFile);
  const viewBuf = fs.readFileSync(viewFile);
  const cborDecoder = new CborDecoder();
  const jsonDecoder = new JsonDecoder();
  const data = cborDecoder.read(buf) as Uint8Array[];
  const view = jsonDecoder.read(viewBuf);
  const batch = data.map((blob) => Patch.fromBinary(blob));
  return [batch, view];
};