Skip to content

Commit

Permalink
tests: webui: Load qunit only once
Browse files Browse the repository at this point in the history
webui unit tests fail with grunt-contrib-qunit:
```
Testing test/all_tests.html

>> Error: Error: QUnit has already been defined.
>>     at exportQUnit (file:///home/test/freeipa/install/ui/js/qunit.js:2475:12)
>>     at file:///home/test/freeipa/install/ui/js/qunit.js:2946:3
>>     at file:///home/test/freeipa/install/ui/js/qunit.js:5061:2

>> Error: TypeError: Cannot set properties of undefined (setting 'reorder')
>>     at <anonymous>:175:24
>>     at runFactory (file:///home/test/freeipa/install/ui/js/dojo/dojo.js:1:17157)
>>     at execModule (file:///home/test/freeipa/install/ui/js/dojo/dojo.js:1:19541)
>>     at file:///home/test/freeipa/install/ui/js/dojo/dojo.js:1:20002
>>     at guardCheckComplete (file:///home/test/freeipa/install/ui/js/dojo/dojo.js:1:19707)
>>     at checkComplete (file:///home/test/freeipa/install/ui/js/dojo/dojo.js:1:19854)
>>     at onLoadCallback (file:///home/test/freeipa/install/ui/js/dojo/dojo.js:1:22296)
>>     at HTMLScriptElement.onLoad (file:///home/test/freeipa/install/ui/js/dojo/dojo.js:1:26209)
```

Load `qunit` with `dojo.require` that among other useful things helps
> Preventing loading Dojo packages twice.
  dojo.require will simply return if the package is already loaded.

See also https://github.com/gruntjs/grunt-contrib-qunit#loading-qunit-with-amd

Related: https://pagure.io/freeipa/issue/9329
Signed-off-by: Stanislav Levin <[email protected]>
  • Loading branch information
stanislavlevin committed Feb 16, 2023
1 parent 070166a commit b3ac2d4
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions install/ui/test/all_tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,14 @@

<script type="text/javascript" src="../js/libs/loader.js"></script>
<script type="text/javascript" src="../js/libs/jquery.js"></script>
<script>
// import qunit.js only in situations it is not imported by grunt-contrib-qunit
// allows to run tests using grunt and using Firefox (FF needs explicit import)
if (window.QUnit === undefined) {
var s = document.createElement("script");
s.type = "text/javascript";
s.src = "qunit.js";
$("head script:last-of-type").before(s); // insert qunit.js import before dojo import
}
</script>
<script type="text/javascript" src="../js/libs/jquery.ordered-map.js"></script>
<script type="text/javascript" src="../js/libs/bootstrap.js"></script>
<script type="text/javascript" src="config.js"></script>
<script class='insertBefore' type="text/javascript" src="../js/dojo/dojo.js"></script>
<script type="text/javascript" src="../js/dojo/dojo.js"></script>

<script type="text/javascript">
require([
'qunit',
'test/ordered_map_tests',
'test/ipa_tests',
'test/details_tests',
Expand All @@ -36,7 +27,7 @@
'test/build_tests',
'test/binding_tests',
'test/topology_tests',
], function(om, ipa, details, entity, as, cert, aci, wid, ip, ut, bt, bi, topo){
], function(qunit, om, ipa, details, entity, as, cert, aci, wid, ip, ut, bt, bi, topo){
QUnit.start();
om();
ipa();
Expand Down

0 comments on commit b3ac2d4

Please sign in to comment.