MCPcopy Create free account
hub / github.com/ckeditor/ckeditor5-react / runTest

Function runTest

tests/integrations/ckeditor-classiceditor.test.tsx:96–135  ·  view source on GitHub ↗
( createEditor, destroyEditor )

Source from the content-addressed store, hash-verified

94
95 // Runs a single test case.
96 function runTest( createEditor, destroyEditor ) {
97 let memoryAfterFirstStart;
98
99 return Promise
100 .resolve()
101 // Initialize the first editor before measuring the heap size.
102 // A cold start may allocate a bit of memory on the module-level.
103 .then( createAndDestroy )
104 .then( () => {
105 return collectMemoryStats().then( mem => {
106 memoryAfterFirstStart = mem;
107 } );
108 } )
109 // Run create&destroy multiple times. Helps scaling up the issue.
110 .then( createAndDestroy ) // #1
111 .then( createAndDestroy ) // #2
112 .then( createAndDestroy ) // #3
113 .then( createAndDestroy ) // #4
114 .then( createAndDestroy ) // #5
115 .then( collectMemoryStats )
116 .then( memory => {
117 const memoryDifference = ( memory as any ).usedJSHeapSize - memoryAfterFirstStart.usedJSHeapSize;
118 // While theoretically we should get 0KB when there's no memory leak, in reality,
119 // the results we get (when there are no leaks) vary from -500KB to 500KB (depending on which tests are executed).
120 // However, when we had memory leaks, memoryDifference was reaching 20MB,
121 // so, in order to detect significant memory leaks we can expect that the heap won't grow more than 1MB.
122 expect( memoryDifference, 'used heap size should not grow' ).to.be.at.most( 1e6 );
123 } );
124
125 function createAndDestroy() {
126 return Promise.resolve()
127 .then( createEditor )
128 .then( destroyEditor )
129 .then( () => {
130 // Simulate real world rerendering queue. Unmounting of editor is *async* so it'll take a while
131 // to unmount existing instance of editor.
132 return timeout( 200 );
133 } );
134 }
135 }
136
137 function collectMemoryStats() {
138 return new Promise( resolve => {

Callers 1

Calls 1

collectMemoryStatsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…