From a9539e35fb20b7f69767c8a3d3d551d6d7f35973 Mon Sep 17 00:00:00 2001 From: Mateusz Baginski Date: Wed, 13 Nov 2024 13:04:59 +0100 Subject: [PATCH 1/4] Add retries to flaky multiroot semaphores tests. --- tests/useMultiRootEditor.test.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/useMultiRootEditor.test.tsx b/tests/useMultiRootEditor.test.tsx index eeb7d32..5f20be5 100644 --- a/tests/useMultiRootEditor.test.tsx +++ b/tests/useMultiRootEditor.test.tsx @@ -896,7 +896,7 @@ describe( 'useMultiRootEditor', () => { describe( 'semaphores', () => { const testSemaphoreForWatchdog = enableWatchdog => { - it( 'should assign properly `data` property to editor even if it is still mounting', async () => { + it( 'should assign properly `data` property to editor even if it is still mounting', { retry: 3 }, async () => { const deferInitialization = createDefer(); class SlowEditor extends TestMultiRootEditor { @@ -933,6 +933,10 @@ describe( 'useMultiRootEditor', () => { await timeout( 100 ); + // Depending on the execution order on the event loop this `setData` might be delayed by the React engine. + // It happens only if event loop is busy and React has to wait for the next tick a little bit longer than usual. + // It does not play well with `waitFor` below so we added few retries to make it more stable. + // It should not be a problem in real life, as it is a rare case and might be solved in future React versions. result.current.setData( { intro: 'Hello World!', content: '' From df470f8891d9f272396c1cd5e7059bd0c00df67c Mon Sep 17 00:00:00 2001 From: Mateusz Baginski Date: Wed, 13 Nov 2024 13:30:46 +0100 Subject: [PATCH 2/4] Make tests run in random order --- tests/useMultiRootEditor.test.tsx | 6 +++--- vite.config.ts | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/useMultiRootEditor.test.tsx b/tests/useMultiRootEditor.test.tsx index 5f20be5..6f88a62 100644 --- a/tests/useMultiRootEditor.test.tsx +++ b/tests/useMultiRootEditor.test.tsx @@ -931,7 +931,7 @@ describe( 'useMultiRootEditor', () => { editor: SlowEditor } ) ); - await timeout( 100 ); + await timeout( 500 ); // Depending on the execution order on the event loop this `setData` might be delayed by the React engine. // It happens only if event loop is busy and React has to wait for the next tick a little bit longer than usual. @@ -942,9 +942,9 @@ describe( 'useMultiRootEditor', () => { content: '' } ); - await timeout( 200 ); + await timeout( 500 ); - deferInitialization.resolve(); + await deferInitialization.resolve(); await waitFor( () => { expect( result.current.editor ).to.be.instanceof( SlowEditor ); diff --git a/vite.config.ts b/vite.config.ts index 80b8125..b88d767 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -54,6 +54,9 @@ export default defineConfig( { include: [ 'tests/**/*.test.[j|t]sx' ], + sequence: { + shuffle: true + }, coverage: { provider: 'istanbul', include: [ 'src/*' ], From 9e42d6cf5b07fa9b300a013cec05e8082fe7d828 Mon Sep 17 00:00:00 2001 From: Mateusz Baginski Date: Wed, 13 Nov 2024 13:59:32 +0100 Subject: [PATCH 3/4] Add coverage `text` reporter to investigate uncovered lines --- vite.config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/vite.config.ts b/vite.config.ts index b88d767..23cfcd7 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -66,6 +66,7 @@ export default defineConfig( { }, reporter: [ 'text-summary', + 'text', 'html', 'lcovonly', 'json' From e057aded41d4c743a32464320085aaec076bd4b9 Mon Sep 17 00:00:00 2001 From: Mateusz Baginski Date: Thu, 14 Nov 2024 10:37:13 +0100 Subject: [PATCH 4/4] Adjust docs --- tests/useMultiRootEditor.test.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/useMultiRootEditor.test.tsx b/tests/useMultiRootEditor.test.tsx index 6f88a62..ab85dc8 100644 --- a/tests/useMultiRootEditor.test.tsx +++ b/tests/useMultiRootEditor.test.tsx @@ -896,7 +896,7 @@ describe( 'useMultiRootEditor', () => { describe( 'semaphores', () => { const testSemaphoreForWatchdog = enableWatchdog => { - it( 'should assign properly `data` property to editor even if it is still mounting', { retry: 3 }, async () => { + it( 'should assign `data` property to the editor even if it is still mounting', { retry: 3 }, async () => { const deferInitialization = createDefer(); class SlowEditor extends TestMultiRootEditor { @@ -933,9 +933,9 @@ describe( 'useMultiRootEditor', () => { await timeout( 500 ); - // Depending on the execution order on the event loop this `setData` might be delayed by the React engine. - // It happens only if event loop is busy and React has to wait for the next tick a little bit longer than usual. - // It does not play well with `waitFor` below so we added few retries to make it more stable. + // Depending on the execution order on the event loop, this `setData` might be delayed by the React engine. + // It happens only if the event loop is busy and React has to wait for the next tick a little bit longer than usual. + // It does not play well with the `waitFor` below, so we added a few retries to make it more stable. // It should not be a problem in real life, as it is a rare case and might be solved in future React versions. result.current.setData( { intro: 'Hello World!',