All files / json-crdt/__bench__/util fuzzer-traces.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   1x 9x 9x 9x 9x 9x 9x 9x 9x 9x 35531x 9x    
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 {Model} from '../../model';
import {bufferToUint8Array} from '@jsonjoy.com/util/lib/buffers/bufferToUint8Array';
 
export const loadFuzzerTrace = (traceName: string): [batch: Patch[], model: Model] => {
  const root = path.resolve(__dirname, '..', '..', '..', '..');
  const dir = path.join(root, 'node_modules', 'json-crdt-traces', 'traces', 'fuzzer', 'processed', traceName);
  const patchFile = path.join(dir, 'patches.bin');
  const modelFile = path.join(dir, 'model.bin');
  const buf = fs.readFileSync(patchFile);
  const modelBuf = bufferToUint8Array(fs.readFileSync(modelFile));
  const model = Model.fromBinary(modelBuf);
  const cborDecoder = new CborDecoder();
  const data = cborDecoder.read(buf) as Uint8Array[];
  const batch = data.map((blob) => Patch.fromBinary(blob));
  return [batch, model];
};