Skip to content

Commit

Permalink
Explicit capture
Browse files Browse the repository at this point in the history
  • Loading branch information
aklarfeld committed Apr 22, 2024
1 parent d36fc26 commit dd168c3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,22 @@ const Supergood = () => {
supergoodAsyncLocalStorage.disable();
}

const getAsyncLocalStorage = () => supergoodAsyncLocalStorage.getStore();

// Set up cleanup catch for exit signals
onExit(() => close(), { alwaysLast: true });
return { close, flushCache, waitAndFlushCache, withTags, init, withCapture, startCapture, stopCapture };

return {
close,
flushCache,
waitAndFlushCache,
withTags,
init,
withCapture,
startCapture,
stopCapture,
getAsyncLocalStorage
};
};

export = Supergood();
36 changes: 35 additions & 1 deletion test/e2e/explicit-capture.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ describe('capture functionality', () => {
await axios.get(`${MOCK_DATA_SERVER}/posts`), 250
});
getInterval.unref();

await Supergood.startCapture(
{
config: { ...SUPERGOOD_CONFIG, allowLocalUrls: true },
Expand All @@ -133,6 +132,7 @@ describe('capture functionality', () => {
}

await Supergood.stopCapture();
await axios.get(`${MOCK_DATA_SERVER}/posts`);

clearInterval(getInterval);

Expand All @@ -147,5 +147,39 @@ describe('capture functionality', () => {
});
});

it('should capture calls without an async kickoff, with useRemoteConfig set to false', async () => {
const numberOfHttpCalls = 5;

const getInterval = setInterval(async () => {
await axios.get(`${MOCK_DATA_SERVER}/posts`), 250
});
getInterval.unref();
Supergood.startCapture(
{
config: { ...SUPERGOOD_CONFIG, allowLocalUrls: true, useRemoteConfig: false },
clientId: SUPERGOOD_CLIENT_ID,
clientSecret: SUPERGOOD_CLIENT_SECRET,
baseUrl: SUPERGOOD_SERVER
});


for (let i = 0; i < numberOfHttpCalls; i++) {
await axios.get(`${MOCK_DATA_SERVER}/posts`);
}

await Supergood.stopCapture();
await axios.get(`${MOCK_DATA_SERVER}/posts`);

clearInterval(getInterval);

checkPostedEvents(postEventsMock, numberOfHttpCalls, {
request: expect.objectContaining({
requestedAt: expect.any(Date)
}),
response: expect.objectContaining({
respondedAt: expect.any(Date)
})
});
});
});

0 comments on commit dd168c3

Please sign in to comment.