import { Dictionaries } from "polar-shared/src/util/Dictionaries" ; import chai from 'chai' ; const assert = chai . assert ; const expect = chai . expect ; chai . config . truncateThreshold = 0 ; export function assertJSON ( actual , expected , message ? , unsorted ? ) { actual = toJSON ( actual , unsorted ) ; expected = toJSON ( expected , unsorted ) ; if ( actual !== expected ) { console . error ( "BEGIN ACTUAL ==========" ) ; console . error ( actual ) ; console . error ( "END ACTUAL   ==========" ) ; } try { expect ( actual ) . equal ( expected , message ) ; } catch ( e ) { console . error ( e . message ) ; throw e ; } } export function toJSON ( obj , unsorted = false ) { if ( typeof obj === "string" ) { obj = JSON . parse ( obj ) ; } const replacer = ( key , value ) => { if ( typeof value === 'object' && value instanceof Set ) { return [ ... value ] ; } return value ; } ; if ( ! Array . isArray ( obj ) && ! unsorted ) { obj = Dictionaries . sorted ( obj ) ; } return JSON . stringify ( obj , replacer , "  " ) ; }