Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing editor.destroy calls to tests #17136

Merged
merged 16 commits into from
Sep 24, 2024
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
4 changes: 2 additions & 2 deletions packages/ckeditor5-alignment/tests/alignmentcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ describe( 'AlignmentCommand', () => {
} );
} );

afterEach( () => {
editor.destroy();
afterEach( async () => {
await editor.destroy();
} );

it( 'is a command', () => {
Expand Down
8 changes: 6 additions & 2 deletions packages/ckeditor5-alignment/tests/alignmentediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ describe( 'AlignmentEditing', () => {
model = editor.model;
} );

afterEach( () => {
editor.destroy();
afterEach( async () => {
await editor.destroy();
} );

it( 'should have pluginName', () => {
Expand Down Expand Up @@ -57,6 +57,10 @@ describe( 'AlignmentEditing', () => {
model = editor.model;
} );

afterEach( async () => {
await editor.destroy();
} );

it( 'is allowed on paragraph', () => {
expect( model.schema.checkAttribute( [ '$root', 'paragraph' ], 'alignment' ) ).to.be.true;
} );
Expand Down
12 changes: 12 additions & 0 deletions packages/ckeditor5-autoformat/tests/autoformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,10 @@ describe( 'Autoformat', () => {
} );
} );

afterEach( async () => {
await editor.destroy();
} );

it( 'should not replace asterisk with bulleted list item', () => {
setData( model, '<paragraph>*[]</paragraph>' );
insertSpace();
Expand Down Expand Up @@ -1308,6 +1312,8 @@ describe( 'Autoformat', () => {
insertSpace();

expect( getData( model ) ).to.equal( '<paragraph>## []</paragraph>' );

return editor.destroy();
} );
} );
} );
Expand Down Expand Up @@ -2401,6 +2407,10 @@ describe( 'Autoformat', () => {
} );
} );

afterEach( async () => {
await editor.destroy();
} );

it( 'should not replace asterisk with bulleted list item', () => {
setData( model, '<paragraph>*[]</paragraph>' );
insertSpace();
Expand Down Expand Up @@ -2528,6 +2538,8 @@ describe( 'Autoformat', () => {
insertSpace();

expect( getData( model ) ).to.equal( '<paragraph>## []</paragraph>' );

return editor.destroy();
} );
} );
} );
Expand Down
4 changes: 4 additions & 0 deletions packages/ckeditor5-autoformat/tests/blockautoformatediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ describe( 'blockAutoformatEditing', () => {
} );
} );

afterEach( async () => {
await editor.destroy();
} );

describe( 'command name', () => {
it( 'should run a command when the pattern is matched', () => {
const spy = testUtils.sinon.spy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ describe( 'inlineAutoformatEditing', () => {
} );
} );

afterEach( async () => {
await editor.destroy();
} );

describe( 'regExp', () => {
it( 'should not call the formatCallback if there are less than 3 capture groups', () => {
inlineAutoformatEditing( editor, plugin, /(\*)(.+?)\*/g, formatSpy );
Expand Down
4 changes: 2 additions & 2 deletions packages/ckeditor5-block-quote/tests/blockquotecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ describe( 'BlockQuoteCommand', () => {
} );
} );

afterEach( () => {
editor.destroy();
afterEach( async () => {
await editor.destroy();
} );

it( 'is a command', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/ckeditor5-block-quote/tests/blockquoteediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ describe( 'BlockQuoteEditing', () => {
editor.setData( '<blockquote><ul><li>xx</li></ul></blockquote>' );

expect( editor.getData() ).to.equal( '<blockquote><ul><li>xx</li></ul></blockquote>' );

return editor.destroy();
} );
} );

Expand Down
8 changes: 8 additions & 0 deletions packages/ckeditor5-ckbox/tests/ckboxediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,8 @@ describe( 'CKBoxEditing', () => {

expect( uploadImageCommand.isEnabled ).to.be.true;
expect( uploadImageCommand.isAccessAllowed ).to.be.true;

await editor.destroy();
} );

it( 'should disable image upload command if access not allowed', async () => {
Expand All @@ -1894,6 +1896,8 @@ describe( 'CKBoxEditing', () => {

expect( uploadImageCommand.isEnabled ).to.be.false;
expect( uploadImageCommand.isAccessAllowed ).to.be.false;

await editor.destroy();
} );

it( 'should not disable image upload command if access allowed ( CKBox loaded first )', async () => {
Expand All @@ -1918,6 +1922,8 @@ describe( 'CKBoxEditing', () => {

expect( uploadImageCommand.isEnabled ).to.be.true;
expect( uploadImageCommand.isAccessAllowed ).to.be.true;

await editor.destroy();
} );

it( 'should disable image upload command if access not allowed ( CKBox loaded first )', async () => {
Expand All @@ -1942,6 +1948,8 @@ describe( 'CKBoxEditing', () => {

expect( uploadImageCommand.isEnabled ).to.be.false;
expect( uploadImageCommand.isAccessAllowed ).to.be.false;

await editor.destroy();
} );
} );
} );
Expand Down
4 changes: 4 additions & 0 deletions packages/ckeditor5-clipboard/tests/clipboardpipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ describe( 'ClipboardPipeline feature', () => {
} );
} );

afterEach( async () => {
await editor.destroy();
} );

describe( 'constructor()', () => {
it( 'registers ClipboardObserver', () => {
expect( view.getObserver( ClipboardObserver ) ).to.be.instanceOf( ClipboardObserver );
Expand Down
4 changes: 4 additions & 0 deletions packages/ckeditor5-clipboard/tests/pasteplaintext.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ describe( 'PastePlainText', () => {
} );
} );

afterEach( async () => {
await editor.destroy();
} );

it( 'should inherit selection attributes (collapsed selection)', () => {
let insertedNode;

Expand Down
27 changes: 21 additions & 6 deletions packages/ckeditor5-core/tests/_utils-tests/classictesteditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe( 'ClassicTestEditor', () => {
} );

describe( 'constructor()', () => {
it( 'creates an instance of editor', () => {
it( 'creates an instance of editor', async () => {
const editor = new ClassicTestEditor( editorElement, { foo: 1 } );

expect( editor ).to.be.instanceof( Editor );
Expand All @@ -47,28 +47,40 @@ describe( 'ClassicTestEditor', () => {
expect( editor.ui ).to.be.instanceOf( EditorUI );
expect( editor.ui.view ).to.be.instanceOf( BoxedEditorUIView );
expect( editor.data.processor ).to.be.instanceof( HtmlDataProcessor );

editor.fire( 'ready' );
await editor.destroy();
} );

it( 'creates the instance of the editable (without rendering)', () => {
it( 'creates the instance of the editable (without rendering)', async () => {
const editor = new ClassicTestEditor( editorElement );

expect( editor.ui.view.editable ).to.be.instanceOf( InlineEditableUIView );
expect( editor.ui.view.editable.isRendered ).to.be.false;

editor.fire( 'ready' );
await editor.destroy();
} );

it( 'creates the #ui and ui#view (without rendering)', () => {
it( 'creates the #ui and ui#view (without rendering)', async () => {
const editor = new ClassicTestEditor( editorElement );

expect( editor.ui ).to.be.instanceOf( EditorUI );
expect( editor.ui.view ).to.be.instanceOf( BoxedEditorUIView );
expect( editor.ui.view.isRendered ).to.be.false;
expect( editor.ui.getEditableElement() ).to.be.undefined;

editor.fire( 'ready' );
await editor.destroy();
} );

it( 'creates main root element', () => {
it( 'creates main root element', async () => {
const editor = new ClassicTestEditor( editorElement );

expect( editor.model.document.getRoot( 'main' ) ).to.instanceof( RootElement );

editor.fire( 'ready' );
await editor.destroy();
} );

it( 'mixes ElementApiMixin', () => {
Expand Down Expand Up @@ -152,15 +164,18 @@ describe( 'ClassicTestEditor', () => {
} );

it( 'sets proper states', () => {
const editor = new ClassicTestEditor();
const baseEditor = new ClassicTestEditor();

expect( editor.state ).to.equal( 'initializing' );
expect( baseEditor.state ).to.equal( 'initializing' );

return ClassicTestEditor.create( editorElement ).then( editor => {
expect( editor.state ).to.equal( 'ready' );

return editor.destroy().then( () => {
expect( editor.state ).to.equal( 'destroyed' );

baseEditor.fire( 'ready' );
return baseEditor.destroy();
} );
} );
} );
Expand Down
18 changes: 16 additions & 2 deletions packages/ckeditor5-core/tests/_utils-tests/modeltesteditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ describe( 'ModelTestEditor', () => {
testUtils.createSinonSandbox();

describe( 'constructor()', () => {
it( 'creates an instance of editor', () => {
it( 'creates an instance of editor', async () => {
const editor = new ModelTestEditor( { foo: 1 } );

expect( editor ).to.be.instanceof( Editor );
expect( editor.config.get( 'foo' ) ).to.equal( 1 );
expect( editor.data.processor ).to.be.instanceof( HtmlDataProcessor );

editor.fire( 'ready' );
await editor.destroy();
} );

it( 'should disable editing pipeline', () => {
Expand All @@ -38,10 +41,13 @@ describe( 'ModelTestEditor', () => {
} );
} );

it( 'creates main root element', () => {
it( 'creates main root element', async () => {
const editor = new ModelTestEditor();

expect( editor.model.document.getRoot( 'main' ) ).to.instanceof( RootElement );

editor.fire( 'ready' );
await editor.destroy();
} );
} );

Expand All @@ -57,6 +63,10 @@ describe( 'ModelTestEditor', () => {
} );
} );

afterEach( async () => {
await editor.destroy();
} );

it( 'should set data of the first root', () => {
editor.model.document.createRoot( '$root', 'secondRoot' );

Expand All @@ -78,6 +88,10 @@ describe( 'ModelTestEditor', () => {
} );
} );

afterEach( async () => {
await editor.destroy();
} );

it( 'should set data of the first root', () => {
setData( editor.model, 'foo' );

Expand Down
10 changes: 8 additions & 2 deletions packages/ckeditor5-core/tests/_utils-tests/virtualtesteditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@ describe( 'VirtualTestEditor', () => {
testUtils.createSinonSandbox();

describe( 'constructor()', () => {
it( 'creates an instance of editor', () => {
it( 'creates an instance of editor', async () => {
const editor = new VirtualTestEditor( { foo: 1 } );

expect( editor ).to.be.instanceof( Editor );
expect( editor.data.processor ).to.be.instanceof( HtmlDataProcessor );
expect( editor.config.get( 'foo' ) ).to.equal( 1 );

editor.fire( 'ready' );
await editor.destroy();
} );

it( 'creates main root element', () => {
it( 'creates main root element', async () => {
const editor = new VirtualTestEditor();

expect( editor.model.document.getRoot( 'main' ) ).to.instanceof( RootElement );

editor.fire( 'ready' );
await editor.destroy();
} );
} );

Expand Down
13 changes: 11 additions & 2 deletions packages/ckeditor5-core/tests/_utils/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
/* global window, document, setTimeout */

const TEST_RETRIES = 2;
const TEST_TIMEOUT = 5000;
const GARBAGE_COLLECTOR_TIMEOUT = 500;
const TEST_TIMEOUT = 6500;
const GARBAGE_COLLECTOR_TIMEOUT = 800;

/**
* Memory tests suite definition that:
Expand Down Expand Up @@ -83,10 +83,15 @@ function runTest( createEditor ) {
} )
// Run create&destroy multiple times. Helps scaling up the issue.
.then( createAndDestroy ) // #1
.then( () => timeout( 300 ) )
.then( createAndDestroy ) // #2
.then( () => timeout( 300 ) )
.then( createAndDestroy ) // #3
.then( () => timeout( 300 ) )
.then( createAndDestroy ) // #4
.then( () => timeout( 300 ) )
.then( createAndDestroy ) // #5
.then( () => timeout( 300 ) )
.then( collectMemoryStats )
.then( memory => {
const memoryDifference = memory.usedJSHeapSize - memoryAfterFirstStart.usedJSHeapSize;
Expand Down Expand Up @@ -164,3 +169,7 @@ function isWindows() {

return userAgent.indexOf( 'windows' ) > -1;
}

function timeout( ms ) {
return new Promise( resolve => setTimeout( resolve, ms ) );
}
11 changes: 8 additions & 3 deletions packages/ckeditor5-core/tests/accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ describe( 'Accessibility', () => {
} );

afterEach( async () => {
editor.destroy();
if ( editor.state === 'initializing' ) {
editor.fire( 'ready' );
}

await editor.destroy();
} );

it( 'should provide default categories, groups, and keystrokes', () => {
Expand Down Expand Up @@ -95,7 +99,7 @@ describe( 'Accessibility', () => {
] );
} );

it( 'should add info specific to the menu bar when available', () => {
it( 'should add info specific to the menu bar when available', async () => {
const editor = new Editor( {
menuBar: {
isVisible: true
Expand All @@ -111,7 +115,8 @@ describe( 'Accessibility', () => {
mayRequireFn: true
} );

editor.destroy();
editor.fire( 'ready' );
await editor.destroy();
} );

describe( 'addKeystrokeInfoCategory()', () => {
Expand Down
Loading