Make WordPress Core

Changeset 32706


Ignore:
Timestamp:
06/07/2015 10:15:47 PM (10 years ago)
Author:
iseulde
Message:

TinyMCE: wptextpattern: make tests ~2x faster

  • Reuse the same instance for all tests in the module.
  • Run without CSS (skin).
  • Less typing.

See #31441.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/qunit/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js

    r32700 r32706  
    11( function( $, QUnit, tinymce, _type, setTimeout ) {
    2     var editor;
     2    var editor,
     3        count = 0;
    34
    45    if ( tinymce.Env.ie && tinymce.Env.ie < 9 ) {
     
    3233    QUnit.module( 'tinymce.plugins.wptextpattern', {
    3334        beforeEach: function( assert ) {
    34             var done = assert.async();
     35            var done;
    3536
    36             $( '#qunit-fixture' ).append( '<textarea id="editor">' );
     37            if ( ! editor ) {
     38                done = assert.async();
    3739
    38             tinymce.init( {
    39                 selector: '#editor',
    40                 plugins: 'wptextpattern',
    41                 init_instance_callback: function() {
    42                     editor = arguments[0];
    43                     editor.focus();
    44                     editor.selection.setCursorLocation();
    45                     setTimeout( done );
    46                 }
    47             } );
     40                $( document.body ).append( '<textarea id="editor">' );
     41
     42                tinymce.init( {
     43                    selector: '#editor',
     44                    skin: false,
     45                    plugins: 'wptextpattern',
     46                    init_instance_callback: function() {
     47                        editor = arguments[0];
     48                        editor.focus();
     49                        editor.selection.setCursorLocation();
     50                        done();
     51                    }
     52                } );
     53            } else {
     54                editor.setContent( '' );
     55                editor.selection.setCursorLocation();
     56            }
    4857        },
    49         afterEach: function() {
    50             editor.remove();
     58        afterEach: function( assert ) {
     59            count++;
     60
     61            if ( count === assert.test.module.tests.length ) {
     62                editor.remove();
     63                $( '#editor' ).remove();
     64            }
    5165        }
    5266    } );
    5367
    5468    QUnit.test( 'Unordered list.', function( assert ) {
    55         type( '* test', function() {
    56             assert.equal( editor.getContent(), '<ul>\n<li>test</li>\n</ul>' );
     69        type( '* a', function() {
     70            assert.equal( editor.getContent(), '<ul>\n<li>a</li>\n</ul>' );
    5771        }, assert.async() );
    5872    } );
    5973
    6074    QUnit.test( 'Ordered list.', function( assert ) {
    61         type( '1. test', function() {
    62             assert.equal( editor.getContent(), '<ol>\n<li>test</li>\n</ol>' );
     75        type( '1. a', function() {
     76            assert.equal( editor.getContent(), '<ol>\n<li>a</li>\n</ol>' );
    6377        }, assert.async() );
    6478    } );
     
    95109        editor.selection.setCursorLocation( editor.$( 'p' )[0].firstChild, 6 );
    96110
    97         type( ' test', function() {
    98             assert.equal( editor.getContent(), '<p>* test test</p>' );
     111        type( ' a', function() {
     112            assert.equal( editor.getContent(), '<p>* test a</p>' );
    99113        }, assert.async() );
    100114    } );
Note: See TracChangeset for help on using the changeset viewer.