Skip to content

Commit

Permalink
[INTERNAL] QUnit 2.x: add version 2.3.2 as qunit-2, adapt test tooling
Browse files Browse the repository at this point in the history
This change adds QUnit 2.3.2 in addition to the current QUnit 1.18.0, 
in order to allow step-by-step migration of test cases in all layers.

Fixes #1359 .

Details:
qunit / qunit-2
 - add QUnit 2.3.2 and its CSS, add CSS wrapper module, update 3rdparty
   info

sinon-qunit bridge
 - no longer use the abandoned signature variant of QUnit.test()
 - design time dependency is still to qunit.js for compatibility reasons

qunit-junit
 - abandon legacy globals ("assert", "raises", "equals") when qunit-2
   is used

QUnitUtils
 - abandon legacy globals ("raises") when qunit-2 is used
 - don't configure QUnit.config.reorder when qunit-2 is used

TestUtils
 - QUnit.push has been removed, use QUnit.assert.push (also deprecated!)

Opa
 - no longer use the abandoned signature variant of QUnit.test()
 - after a QUnit timeout, Opa must no longer call the assert.async()
 - QUnit.throws no longer accepts string literal as 'expected'
 
TestRunner
 - failed to parse the test results from the DOM 
   (with QUnit 2, there's more than one <strong> tag in each test case)

Tests
 - fully migrate Opa's own tests to QUnit 2.0 APIs
 - Execute Opa's own tests for both, QUnit 1.x and QUnit 2.x
 - timeout test failed to extract assertion messages (also has
   extracted any 'diff' messages)

Change-Id: I1e6748405e95e87d0478e72eecdc0566bd8dbba4
JIRA: CPOUIFPHOENIXCORE-1783
(cherry picked from commit 33c3583)
CR-Id: 002075125900001531432017
  • Loading branch information
codeworrior committed May 8, 2017
1 parent 62fef80 commit 764bee8
Show file tree
Hide file tree
Showing 45 changed files with 5,627 additions and 183 deletions.
9 changes: 8 additions & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ This project may include APIs to SAP or third party products or services. The us
OpenUI5 SUBCOMPONENTS:

OpenUI5 includes the following subcomponents that are subject to separate license terms.
Your use of these subcomponents is subject to the seperate license terms applicable to
Your use of these subcomponents is subject to the separate license terms applicable to
each subcomponent.

Component: ace 1.2.6
Expand Down Expand Up @@ -441,6 +441,13 @@ License: MIT License
<year> = 2006, 2014
<copyright holders> = jQuery Foundation and other contributors

Component: qunit 2.3.2
Licensor: jQuery Foundation and other contributors
Website: http://github.com/jquery/qunit/
License: MIT License
<year> = 2017
<copyright holders> = jQuery Foundation and other contributors

Component: qunit composite 1.0.4
Licensor: jQuery Foundation and other contributors
Website:https://github.com/JamesMGreene/qunit-composite
Expand Down
1 change: 1 addition & 0 deletions src/sap.ui.core/src/sap/ui/core/.library
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<raw-module name="sap/ui/thirdparty/mobiscroll/js/mobiscroll-scroller.js" depends="sap/ui/thirdparty/jquery.js,sap/ui/thirdparty/mobiscroll/js/mobiscroll-core.js" />
<raw-module name="sap/ui/thirdparty/mobiscroll/js/mobiscroll-datetime.js" depends="sap/ui/thirdparty/jquery.js,sap/ui/thirdparty/mobiscroll/js/mobiscroll-core.js,sap/ui/thirdparty/mobiscroll/js/mobiscroll-scroller.js" />
<raw-module name="sap/ui/thirdparty/punycode.js" />
<raw-module name="sap/ui/thirdparty/qunit-2.js" />
<raw-module name="sap/ui/thirdparty/qunit.js" />
<raw-module name="sap/ui/thirdparty/qunit-composite.js" depends="sap/ui/thirdparty/qunit.js" />
<raw-module name="sap/ui/thirdparty/qunit-reporter-junit.js" depends="sap/ui/thirdparty/qunit.js" />
Expand Down
8 changes: 8 additions & 0 deletions src/sap.ui.core/src/sap/ui/qunit/QUnitUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ sap.ui.define('sap/ui/qunit/QUnitUtils', ['jquery.sap.global', 'sap/ui/Device',

if ( typeof QUnit !== 'undefined' ) {

// any version < 2.0 activates legacy support
// note that the strange negated condition properly handles NaN
var bLegacySupport = !(parseFloat(QUnit.version) >= 2.0);

// extract the URL parameters
var mParams = jQuery.sap.getUriParameters();

if ( bLegacySupport ) {
// TODO: Remove deprecated code once all projects adapted
QUnit.equals = window.equals = window.equal;
}

// Set global timeout for all tests
var sTimeout = mParams.get("sap-ui-qunittimeout");
Expand All @@ -31,8 +37,10 @@ sap.ui.define('sap/ui/qunit/QUnitUtils', ['jquery.sap.global', 'sap/ui/Device',
}
QUnit.config.testTimeout = parseInt(sTimeout, 10);

if ( bLegacySupport ) {
// Do not reorder tests, as most of the tests depend on each other
QUnit.config.reorder = false;
}

// only when instrumentation is done on server-side blanket itself doesn't
// take care about rendering the report - in this case we do it manually
Expand Down
12 changes: 12 additions & 0 deletions src/sap.ui.core/src/sap/ui/qunit/qunit-2-css.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*!
* ${copyright}
*/

(function() {
"use strict";

/*global jQuery */

var sUrl = jQuery.sap.getModulePath("sap.ui.thirdparty.qunit-2", ".css");
jQuery.sap.includeStyleSheet(sUrl);
}());
38 changes: 24 additions & 14 deletions src/sap.ui.core/src/sap/ui/qunit/qunit-junit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

if (typeof QUnit !== "undefined") {

// any version < 2.0 activates legacy support
// note that the strange negated condition properly handles NaN
var bLegacySupport = !(parseFloat(QUnit.version) >= 2.0);

//extract base URL from script to attach the qunit-reporter-junit script
var sDocumentLocation = document.location.href.replace(/\?.*|#.*/g, ""),
aScripts = document.getElementsByTagName("script"),
Expand Down Expand Up @@ -61,29 +65,35 @@
});

// TODO: Remove deprecated code once all projects adapted
QUnit.equals = window.equals = window.equal;
QUnit.raises = window.raises = window["throws"];
if ( bLegacySupport ) {
QUnit.equals = window.equals = window.equal;
QUnit.raises = window.raises = window["throws"];
}

// register QUnit event handler to manipulate module names for better reporting in Jenkins
QUnit.moduleStart(function(oData) {
oData.name = sTestPageName + "." + formatModuleName(oData.name);
});
QUnit.testStart(function(oData) {
oData.module = sTestPageName + "." + formatModuleName(oData.module);
window.assert = QUnit.config.current.assert;
if ( bLegacySupport ) {
window.assert = QUnit.config.current.assert;
}
});
QUnit.testDone(function(assert) {
try {
delete window.assert;
} catch (ex) {
// report that the cleanup of the window.assert compatibility object
// failed because some script loaded via script tag defined an assert
// function which finally causes the "delete window.assert" to fail
if (!window._$cleanupFailed) {
QUnit.test("A script loaded via script tag defines a global assert function!", function(assert) {
QUnit.ok(QUnit.config.ignoreCleanupFailure, ex);
});
window._$cleanupFailed = true;
if ( bLegacySupport ) {
try {
delete window.assert;
} catch (ex) {
// report that the cleanup of the window.assert compatibility object
// failed because some script loaded via script tag defined an assert
// function which finally causes the "delete window.assert" to fail
if (!window._$cleanupFailed) {
QUnit.test("A script loaded via script tag defines a global assert function!", function(assert) {
assert.ok(QUnit.config.ignoreCleanupFailure, ex);
});
window._$cleanupFailed = true;
}
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/sap.ui.core/src/sap/ui/test/TestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ sap.ui.define("sap/ui/test/TestUtils", [
function pushDeeplyContains(oActual, oExpected, sMessage, bExpectSuccess) {
try {
deeplyContains(oActual, oExpected, "/");
QUnit.push(bExpectSuccess, oActual, oExpected, sMessage);
QUnit.assert.push(bExpectSuccess, oActual, oExpected, sMessage);
} catch (ex) {
QUnit.push(!bExpectSuccess, oActual, oExpected,
QUnit.assert.push(!bExpectSuccess, oActual, oExpected,
(sMessage || "") + " failed because of " + ex.message);
}
}
Expand Down
22 changes: 19 additions & 3 deletions src/sap.ui.core/src/sap/ui/test/opaQunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ sap.ui.define([
expected = null;
}

if ( QUnit.test.length === 2 && async === true ) {
throw new Error("Qunit >=2.0 is used, which no longer supports the 'async' parameter for tests.");
}

var testBody = function(assert) {
var fnStart = assert.async();
config.testName = testName;
Expand All @@ -90,6 +94,10 @@ sap.ui.define([
Opa.assert = assert;
Opa5.assert = assert;

if ( QUnit.test.length === 2 && expected !== null ) {
assert.expect(expected);
}

callback.call(this, config.arrangements, config.actions, config.assertions);

var promise = Opa.emptyQueue();
Expand All @@ -100,15 +108,23 @@ sap.ui.define([
});

promise.fail(function (oOptions) {
QUnit.ok(false, oOptions.errorMessage);
assert.ok(false, oOptions.errorMessage);
Opa.assert = undefined;
Opa5.assert = undefined;
// let OPA finish before QUnit starts executing the next test
setTimeout(fnStart, 0);
// call fnStart only when QUnit did not timeout.
if ( oOptions.stoppedManually !== false ) {
setTimeout(fnStart, 0);
}
});
};

return QUnit.test(testName, expected, testBody, async);
if ( QUnit.test.length === 2 ) {
return QUnit.test(testName, testBody);
} else {
return QUnit.test(testName, expected, testBody, async);
}

};
// Export to global namespace to be backwards compatible
window.opaTest = opaTest;
Expand Down
Loading

0 comments on commit 764bee8

Please sign in to comment.