Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -177,43 +177,50 @@ describe('Thread Blocked Native', { timeout: 30_000 }, () => {
.completed();
});

test('worker thread', async () => {
test('worker thread', { timeout: 60_000 }, async () => {
const instrument = join(__dirname, 'instrument.mjs');
await createRunner(__dirname, 'worker-main.mjs')
.withMockSentryServer()
.withFlags('--import', instrument)
.expect({
event: event => {
const crashedThread = event.threads?.values?.find(thread => thread.crashed)?.id as string;
const crashedThread = event.threads?.values?.find(thread => thread.crashed)?.id as string | undefined;
expect(crashedThread).toBeDefined();

const expectedEvent = ANR_EVENT();
expect(event).toMatchObject({
...ANR_EVENT(),
...expectedEvent,
// We compare this separately below
threads: expect.any(Object),
exception: {
...EXCEPTION(crashedThread),
},
threads: {
values: [
{
id: '0',
name: 'main',
crashed: false,
current: true,
main: true,
stacktrace: {
frames: expect.any(Array),
},
},
{
id: crashedThread,
name: `worker-${crashedThread}`,
crashed: true,
current: true,
main: false,
},
],
},
});

const threadValues = event.threads?.values ?? [];
expect(threadValues).toHaveLength(2);
// Any order is fine, we just check that both are present
expect(threadValues).toContainEqual(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

q: Is there a specific reason why this one got outsourced into its own expect? expect.objectContaining would have worked above as well if I'm not mistaken

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I personally don't like how these nested contains things are visualized when they fail - I always have a hard time finding out what is actually not matching. I find this easier to parse when it fails, but this is more a personal preference :D functionally that also worked fine, yes!

expect.objectContaining({
id: '0',
name: 'main',
crashed: false,
current: true,
main: true,
stacktrace: {
frames: expect.any(Array),
},
}),
);
expect(threadValues).toContainEqual(
expect.objectContaining({
id: crashedThread,
name: `worker-${crashedThread}`,
crashed: true,
current: true,
main: false,
}),
);
},
})
.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { longWork } from './long-work.js';

setTimeout(() => {
longWork();
}, 5000);
}, 10_000);
Loading