Skip to content

Commit

Permalink
patch(fix): octo | avoid recursion in isObjectDeepEquals() with ancho…
Browse files Browse the repository at this point in the history
…rs and diffs.
  • Loading branch information
rash805115 committed Dec 24, 2024
1 parent 75698a9 commit c125ca1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
18 changes: 9 additions & 9 deletions packages/octo/src/functions/container/container.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('Container UT', () => {

await expect(async () => {
await container.get(Test, { metadata: { type: 'metadata' } });
}).rejects.toMatchInlineSnapshot(`[Error: Timed out waiting for factory "Test" to resolve!]`);
}).rejects.toMatchInlineSnapshot(`[Error: Timed out waiting for factory to resolve!]`);
});
});

Expand Down Expand Up @@ -78,15 +78,15 @@ describe('Container UT', () => {
expect(() => {
container.registerFactory(Test, TestFactory);
container.registerFactory(Test, TestFactory);
}).toThrowErrorMatchingInlineSnapshot(`"Factory "Test" has already been registered!"`);
}).toThrowErrorMatchingInlineSnapshot(`"Factory has already been registered!"`);
});

it('should timeout waiting for factory to be created when factory does not exist', async () => {
container.setFactoryTimeout(10);

await expect(async () => {
await container.get(Test);
}).rejects.toMatchInlineSnapshot(`[Error: Timed out waiting for factory "Test" to resolve!]`);
}).rejects.toMatchInlineSnapshot(`[Error: Timed out waiting for factory to resolve!]`);
});

it('should wait for factory to be created when factory does not exist', async () => {
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('Container UT', () => {

await expect(async () => {
await container.get(Test);
}).rejects.toMatchInlineSnapshot(`[Error: Timed out waiting for factory "Test" to resolve!]`);
}).rejects.toMatchInlineSnapshot(`[Error: Timed out waiting for factory to resolve!]`);
});

it('should be able to unregister a factory of type string', async () => {
Expand All @@ -163,7 +163,7 @@ describe('Container UT', () => {

await expect(async () => {
await container.get(Test);
}).rejects.toMatchInlineSnapshot(`[Error: Timed out waiting for factory "Test" to resolve!]`);
}).rejects.toMatchInlineSnapshot(`[Error: Timed out waiting for factory to resolve!]`);
});

it('should be able to unregister all factories if options not provided', async () => {
Expand All @@ -180,10 +180,10 @@ describe('Container UT', () => {

await expect(async () => {
await container.get(Test);
}).rejects.toMatchInlineSnapshot(`[Error: Timed out waiting for factory "Test" to resolve!]`);
}).rejects.toMatchInlineSnapshot(`[Error: Timed out waiting for factory to resolve!]`);
await expect(async () => {
await container.get(Test, { metadata: { type: 'metadata' } });
}).rejects.toMatchInlineSnapshot(`[Error: Timed out waiting for factory "Test" to resolve!]`);
}).rejects.toMatchInlineSnapshot(`[Error: Timed out waiting for factory to resolve!]`);
});

it('should only unregister default factory if metadata does not match', async () => {
Expand All @@ -200,7 +200,7 @@ describe('Container UT', () => {

await expect(async () => {
await container.get(Test);
}).rejects.toMatchInlineSnapshot(`[Error: Timed out waiting for factory "Test" to resolve!]`);
}).rejects.toMatchInlineSnapshot(`[Error: Timed out waiting for factory to resolve!]`);
const test3 = await container.get(Test, { metadata: { type: 'metadata' } });
expect(test3.property).toBe('valueWithMetadata');
});
Expand All @@ -221,7 +221,7 @@ describe('Container UT', () => {
expect(test3.property).toBe('value');
await expect(async () => {
await container.get(Test, { metadata: { type: 'metadata' } });
}).rejects.toMatchInlineSnapshot(`[Error: Timed out waiting for factory "Test" to resolve!]`);
}).rejects.toMatchInlineSnapshot(`[Error: Timed out waiting for factory to resolve!]`);
});

it('should not unregister any factory if metadata does not match', async () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/octo/src/functions/container/test-container.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ describe('TestContainer UT', () => {

await expect(async () => {
await container.get(ResourceSerializationService);
}).rejects.toThrowErrorMatchingInlineSnapshot(
`"Timed out waiting for factory "ResourceSerializationService" to resolve!"`,
);
}).rejects.toThrowErrorMatchingInlineSnapshot(`"Timed out waiting for factory to resolve!"`);
});
});
});
7 changes: 6 additions & 1 deletion packages/octo/src/functions/diff/diff.utility.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { UnknownNode } from '../../app.type.js';
import { AAnchor } from '../../overlays/anchor.abstract.js';
import { Dependency } from '../dependency/dependency.js';
import { Diff, DiffAction } from './diff.js';

Expand All @@ -25,8 +26,12 @@ export class DiffUtility {
tx = typeof x,
ty = typeof y;

if (x instanceof Dependency && y instanceof Dependency) {
if (x instanceof AAnchor && y instanceof AAnchor) {
return this.isObjectDeepEquals(x.synth(), y.synth());
} else if (x instanceof Dependency && y instanceof Dependency) {
return this.isObjectDeepEquals(x.synth(), y.synth());
} else if (x instanceof Diff && y instanceof Diff) {
return this.isObjectDeepEquals(x.toJSON(), y.toJSON());
}

return x && y && tx === 'object' && tx === ty
Expand Down

0 comments on commit c125ca1

Please sign in to comment.