Skip to content

Commit

Permalink
Merge pull request #559 from ckeditor/ck/add-retries-to-flaky-semapho…
Browse files Browse the repository at this point in the history
…re-tests

Tests: Add retry option to flaky multiroot test, extend delay between assertions.
Tests: Randomize the order of the tests, to prevent incorrect dependencies across tests.
  • Loading branch information
Mati365 authored Nov 14, 2024
2 parents 94a9a43 + e057ade commit c90694a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tests/useMultiRootEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 `data` property to the editor even if it is still mounting', { retry: 3 }, async () => {
const deferInitialization = createDefer();

class SlowEditor extends TestMultiRootEditor {
Expand Down Expand Up @@ -931,16 +931,20 @@ 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 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!',
content: ''
} );

await timeout( 200 );
await timeout( 500 );

deferInitialization.resolve();
await deferInitialization.resolve();

await waitFor( () => {
expect( result.current.editor ).to.be.instanceof( SlowEditor );
Expand Down
4 changes: 4 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export default defineConfig( {
include: [
'tests/**/*.test.[j|t]sx'
],
sequence: {
shuffle: true
},
coverage: {
provider: 'istanbul',
include: [ 'src/*' ],
Expand All @@ -63,6 +66,7 @@ export default defineConfig( {
},
reporter: [
'text-summary',
'text',
'html',
'lcovonly',
'json'
Expand Down

0 comments on commit c90694a

Please sign in to comment.