Skip to content

Commit

Permalink
bug repro with dedupe=true (#253)
Browse files Browse the repository at this point in the history
* bug repro

* chore: add two more assertions

* chore: write test to explain problem

* fix: dont try to copy a non-existant value into others

---------

Co-authored-by: Simon Knott <[email protected]>
  • Loading branch information
KATT and Skn0tt authored Sep 27, 2023
1 parent ff9cc2d commit a8949df
Show file tree
Hide file tree
Showing 4 changed files with 82,817 additions and 7 deletions.
23 changes: 23 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable es5/no-for-of */
/* eslint-disable es5/no-es6-methods */

import * as fs from 'fs';

import SuperJSON from './';
import { JSONValue, SuperJSONResult, SuperJSONValue } from './types';
import {
Expand Down Expand Up @@ -1193,3 +1195,24 @@ test('dedupe=true', () => {

expect(instance.deserialize(output)).toEqual(input);
});

test('dedupe=true on a large complicated schema', () => {
const content = fs.readFileSync(__dirname + '/non-deduped-cal.json', 'utf-8');
const parsed = JSON.parse(content);

const deserialized = SuperJSON.deserialize(parsed);

const nondeduped = new SuperJSON({});

const deduped = new SuperJSON({
dedupe: true,
});

const nondedupedOut = nondeduped.deserialize(
nondeduped.serialize(deserialized)
);
const dedupedOut = deduped.deserialize(deduped.serialize(deserialized));

expect(nondedupedOut).toEqual(deserialized);
expect(dedupedOut).toEqual(deserialized);
});
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export default class SuperJSON {
}

const equalityAnnotations = generateReferentialEqualityAnnotations(
identities
identities,
this.dedupe
);
if (equalityAnnotations) {
res.meta = {
Expand Down
Loading

0 comments on commit a8949df

Please sign in to comment.