Skip to content

Add comprehensive test coverage#58

Open
Pearce-Ropion wants to merge 4 commits into
mainfrom
claude/add-unit-tests-oqlLW
Open

Add comprehensive test coverage#58
Pearce-Ropion wants to merge 4 commits into
mainfrom
claude/add-unit-tests-oqlLW

Conversation

@Pearce-Ropion
Copy link
Copy Markdown
Collaborator

@Pearce-Ropion Pearce-Ropion commented May 11, 2026

This PR significantly expands the test suite for the plugin client, replacing minimal lifecycle tests with comprehensive coverage of all client APIs and functionality.

Summary

The test suite for initialize() has been completely rewritten to provide thorough coverage of the plugin client's behavior, including lifecycle management, configuration API, elements API, style API, and message handling. Additionally, new test files have been added for utility functions and the client singleton export.

Notable Implementation Details

  • Tests use vi.spyOn() for mocking window methods and tracking postMessage calls
  • Helper functions (sendWindowMessage, postMessages, findPostMessage) abstract common test patterns
  • Tests verify both the client's internal state updates and the messages it sends to the parent window
  • Proper cleanup with beforeEach/afterEach hooks to restore window state between tests
  • Tests cover both happy paths and error cases (malformed JSON, unknown effects, etc.)

https://claude.ai/code/session_01HwKQWfqXUq4BBKom4bADuq

claude and others added 3 commits May 11, 2026 15:02
Covers deepEqual, polyfillRequestAnimationFrame, validateConfigId,
the default client singleton, and an end-to-end expansion of the
initialize() client tests (URL parsing, config/elements/style APIs,
event handlers, promise resolution and rejection, unsubscribers,
and destroy behavior). React-dependent modules are intentionally
left untested since react is only an optional peer dep and is not
installed in the test environment.
@Pearce-Ropion Pearce-Ropion marked this pull request as ready for review May 11, 2026 16:19
@Pearce-Ropion Pearce-Ropion requested review from a team, peternandersson and ryan-sigma May 11, 2026 16:19
@Pearce-Ropion Pearce-Ropion changed the title Add comprehensive test coverage for plugin client initialization Add comprehensive test coverage May 11, 2026
Copy link
Copy Markdown
Contributor

@peternandersson peternandersson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

messageListener = listener as (event: unknown) => void;
}
return original(type, listener, options);
}) as typeof window.addEventListener);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm

result: { sigmaEnv: 'author', config: { foo: 'bar' } },
error: null,
});
await Promise.resolve();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is clever!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants