Page MenuHomePhabricator

Translate extension: Fix tests to not assume synchronous jQuery.Deferred
Closed, ResolvedPublic

Description

Each QUnit test should either return a Promise to QUnit.test (which QUnit will automatically wait for and also report a test failure if the Promise is rejected), or manually use assert.async() where needed.

Examples:

QUnit.test( 'example should pass', function ( assert ) {
  return something().then( function ( val ) {
    assert.equals( val, 'expected' );
  } );
} );

QUnit.test( 'example should fail', function ( assert ) {
  var done = assert.async();
  something().fail( function ( val ) {
    assert.equals( val, 'error message' );
  } ).always( done );
} );

See also MediaWiki core's QUnit tests of mediawiki.api for more examples.

This is in preparation for jQuery 3.0, where $.Deferred callbacks are processed asynchronously. https://jquery.com/upgrade-guide/3.0/

Failures can be seen at the pending core patch: https://gerrit.wikimedia.org/r/322812/.

Example: https://integration.wikimedia.org/ci/job/mediawiki-extensions-qunit-jessie/24368/consoleFull#console-section-2

03:54:38 Chrome 55.0.2883 (Linux 0.0.0) ext.translate.special.pagemigration -- Source units FAILED
03:54:38 	Expected at least one assertion, but none were run - call expect(0) to accept zero assertions.

Event Timeline

Krinkle created this task.Feb 24 2017, 5:38 AM
Krinkle updated the task description. (Show Details)

Ah, so what I did in https://gerrit.wikimedia.org/r/#/c/339121/ wasn't exactly correct?

Indeed, sorry. I left a comment there with more details.

Change 340288 had a related patch set uploaded (by Nikerabbit; owner: Nikerabbit):
Fix qunit tests for async handling

https://gerrit.wikimedia.org/r/340288

Change 340288 merged by jenkins-bot:
Fix qunit tests for async handling

https://gerrit.wikimedia.org/r/340288

Krinkle closed this task as Resolved.Mar 1 2017, 12:26 AM