Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug repro with dedupe=true #253

Merged
merged 5 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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