Skip to content

Issue #6 - Live tests#14

Merged
lekkas merged 26 commits into
nevuamarkets:mainfrom
TheyCallMeCheng:live-tests
Nov 18, 2025
Merged

Issue #6 - Live tests#14
lekkas merged 26 commits into
nevuamarkets:mainfrom
TheyCallMeCheng:live-tests

Conversation

@TheyCallMeCheng

Copy link
Copy Markdown
Contributor

Regarding issue #6

  • Divided live tests and mock tests
  • Adjusted mock tests imports to reflect the new folder organization
  • Created the tests for: onBook, onLastTradePrice, onPriceChange
  • we check that we receive the object and that the object structure is what we expected
  • Didn't create a test for TickSizeChangeEvent because it's so rare it's difficult to catch it even if we fetch 100 markets

@lekkas lekkas left a comment

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.

  1. See comments on optimizing the process by waiting for all websocket events only once.
  2. While I'd love to run these tests on every PR, I am not sure they'll run reliably on github's workers and may fail intermittently. I'd recommend we only run the live tests as part of the npm publish worfklow, so it'll run locally on the publisher's machine before the npm package is updated.

What do you think?

Comment thread tests/live/LiveData.test.ts Outdated
let stream: WSSubscriptionManager | undefined;

beforeEach(async () => {
tokenIdsArray = await getTopMarketsByVolume(marketsQty);

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.

@TheyCallMeCheng instead of fetching the markets every single time, I'd recommend we use the following flow:

  1. Call getTopMarketsByVolume and createConnectionWithType once once (perhaps using a beforeAll hook)
  2. Wait until all events types have been received. On a relevant note, let's increase the hook timeout to 2 minutes in vitest.config.ts
  3. Then proceed with each separate test that confirm all fields exists & no additional fields are present.

Comment thread tests/live/LiveData.test.ts Outdated
import { WSSubscriptionManager } from '../../src/WSSubscriptionManager'
import { BookEvent, LastTradePriceEvent, PriceChangeEvent, PriceChangeItem, TickSizeChangeEvent, WebSocketHandlers } from '../../src/types/PolymarketWebSocket'

const marketsQty = '50';

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.

Let's increase that to 100; it makes no real difference in terms of performance and will increase the chances that we catch all websocket events faster.

@TheyCallMeCheng

Copy link
Copy Markdown
Contributor Author

Thank you for the suggestions, I have implemented:

  • a vitest config file for the custom timeout
  • modified package.json to only run live test on prepublishOnly
  • fetching 100 markets instead of 50
  • run beforeAll on each describe block

About the last point, it increased performance 10x, so from 120s it now only takes between 3s and 12s to run live tests. I kept them separate per describe block for better test isolation and maintainability, and I don't think sharing a single connection across all tests would improve the performance significantly.

@lekkas

lekkas commented Nov 13, 2025

Copy link
Copy Markdown
Contributor

@TheyCallMeCheng

This is in a much better direction, thank you!

  • run beforeAll on each describe block

Why do we need to re-fetch / re-connect on each describe block separately? Perhaps we can:

  • do it only once in the beginning
  • wait for at least one event of each type we are testing for to be received (i.e. onBook, onLastTradePrice, onPriceChange)
  • then run all test groups, using the pre-fetched data:
describe('onBook', () => { // ..
describe('onLastTradePrice', () => { // ..
describe('onPriceChange', () => { // ..

@TheyCallMeCheng

Copy link
Copy Markdown
Contributor Author

Fixed, now we fetch first, wait for all events and then test.
My reasoning behind keeping different fetches was to keep each test case isolate.

@lekkas lekkas merged commit 98dce3a into nevuamarkets:main Nov 18, 2025
2 checks passed
@lekkas

lekkas commented Nov 18, 2025

Copy link
Copy Markdown
Contributor

Fixed, now we fetch first, wait for all events and then test. My reasoning behind keeping different fetches was to keep each test case isolate.

Sweet!! I just tested it locally and runs perfectly, great work! ☺️

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.

2 participants