summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2020-04-22 08:56:17 +0000
committerAaron Bohy <aab@odoo.com>2020-04-24 08:11:17 +0000
commita3a415b13003cd3bfccc202e833efac9ccfeebce (patch)
treecc11846dc7ce5b0742b8933dec85047ccc62bc2c
parenteec563c2f1e464656dd2b67b5107a1035817b671 (diff)
[FIX] web: tests: detect failed modules in small suites
Before this commit, we waited for 10 seconds before defining the boot test (checking that all JS modules have been correctly loaded). However, small test suites (like the mobile one) ended before this test was defined. So we could end up with a green branch with tests not being executed (e.g. if a testing module had missing dependencies, and was part of a small suite). This commit removes the boot tests and instead does the check at the end of the suite, before logging that the suite passed. closes odoo/odoo#50109 X-original-commit: 048557eef32df94715ab464614c9d9d34c4a2689 Signed-off-by: Géry Debongnie (ged) <ged@openerp.com> Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
-rw-r--r--addons/web/static/tests/boot_tests.js18
-rw-r--r--addons/web/static/tests/helpers/qunit_config.js54
-rw-r--r--addons/web/views/webclient_templates.xml1
3 files changed, 50 insertions, 23 deletions
diff --git a/addons/web/static/tests/boot_tests.js b/addons/web/static/tests/boot_tests.js
deleted file mode 100644
index 7103c1dd5f9..00000000000
--- a/addons/web/static/tests/boot_tests.js
+++ /dev/null
@@ -1,18 +0,0 @@
-(function () {
-"use strict";
-
-odoo.__DEBUG__.didLogInfo.then(function () {
- var modulesInfo = odoo.__DEBUG__.jsModules;
-
- QUnit.module('Odoo JS Modules');
-
- QUnit.test('all modules are properly loaded', function (assert) {
- assert.expect(2);
-
- assert.deepEqual(modulesInfo.missing, [],
- "no js module should be missing");
- assert.deepEqual(modulesInfo.failed, [],
- "no js module should have failed");
- });
-});
-})();
diff --git a/addons/web/static/tests/helpers/qunit_config.js b/addons/web/static/tests/helpers/qunit_config.js
index 664808c3cb1..ce235ab3ecf 100644
--- a/addons/web/static/tests/helpers/qunit_config.js
+++ b/addons/web/static/tests/helpers/qunit_config.js
@@ -41,16 +41,62 @@ QUnit.config.hidepassed = (window.location.href.match(/[?&]testId=/) === null);
var sortButtonAppended = false;
/**
+ * If we want to log several errors, we have to log all of them at once, as
+ * browser_js is closed as soon as an error is logged.
+ */
+const errorMessages = [];
+
+/**
+ * Waits for the module system to end processing the JS modules, so that we can
+ * make the suite fail if some modules couldn't be loaded (e.g. because of a
+ * missing dependency).
+ *
+ * @returns {Promise<boolean>}
+ */
+async function checkModules() {
+ // do not mark the suite as successful already, as we still need to ensure
+ // that all modules have been correctly loaded
+ $('#qunit-banner').removeClass('qunit-pass');
+ const $modulesAlert = $('<div>')
+ .addClass('alert alert-info')
+ .text('Waiting for modules check...');
+ $modulesAlert.appendTo('#qunit');
+
+ // wait for the module system to end processing the JS modules
+ await odoo.__DEBUG__.didLogInfo;
+
+ const info = odoo.__DEBUG__.jsModules;
+ if (info.missing.length || info.failed.length) {
+ $('#qunit-banner').addClass('qunit-fail');
+ $modulesAlert.toggleClass('alert-info alert-danger');
+ const failingModules = info.missing.concat(info.failed);
+ const error = `Some modules couldn't be started: ${failingModules.join(', ')}.`;
+ $modulesAlert.text(error);
+ errorMessages.unshift(error);
+ return false;
+ } else {
+ $modulesAlert.toggleClass('alert-info alert-success');
+ $modulesAlert.text('All modules have been correctly loaded.');
+ $('#qunit-banner').addClass('qunit-pass');
+ return true;
+ }
+}
+
+/**
* This is the way the testing framework knows that tests passed or failed. It
* only look in the phantomJS console and check if there is a ok or an error.
*
* Someday, we should devise a safer strategy...
*/
-QUnit.done(function(result) {
- if (!result.failed) {
+QUnit.done(async function (result) {
+ const allModulesLoaded = await checkModules();
+ if (result.failed) {
+ errorMessages.push(`${result.failed} / ${result.total} tests failed.`);
+ }
+ if (!result.failed && allModulesLoaded) {
console.log('test successful');
} else {
- console.error(result.failed, "/", result.total, "tests failed");
+ console.error(errorMessages.join('\n'));
}
if (!sortButtonAppended) {
@@ -73,7 +119,7 @@ QUnit.log(function (result) {
info += ', expected: "' + result.expected + '"';
}
info += ']';
- console.error(info);
+ errorMessages.push(info);
}
});
diff --git a/addons/web/views/webclient_templates.xml b/addons/web/views/webclient_templates.xml
index 275a1ccd59f..27f38be597a 100644
--- a/addons/web/views/webclient_templates.xml
+++ b/addons/web/views/webclient_templates.xml
@@ -657,7 +657,6 @@
<script type="text/javascript" src="/web/static/tests/helpers/test_env.js"></script>
<script type="text/javascript" src="/web/static/tests/component_extension_tests.js"></script>
- <script type="text/javascript" src="/web/static/tests/boot_tests.js"></script>
</template>
<template id="web.qunit_suite">