[devtools] qunit: show helpful data when an assertion fails

Related to #5533333.

authorRémi Cardona <remi.cardona@logilab.fr>
changesetf5ec46a6867a
branchdefault
phasepublic
hiddenno
parent revision#7628a14d2209 [web/test] Use shorter $() instead of jQuery()
child revision#523a7f098066 [js] lint : make it explicit that typeof is an operator, not a function.
files modified by this revision
devtools/qunit.py
# HG changeset patch
# User Rémi Cardona <remi.cardona@logilab.fr>
# Date 1432218004 -7200
# Thu May 21 16:20:04 2015 +0200
# Node ID f5ec46a6867a89028987c4e67959de8a2e1a793e
# Parent 7628a14d220952282b08bf1f557977d83b163d95
[devtools] qunit: show helpful data when an assertion fails

Related to #5533333.

diff --git a/devtools/qunit.py b/devtools/qunit.py
@@ -210,11 +210,19 @@
1          self.tc.test_queue.put((None, None, None))
2 
3      def handle_log(self):
4          result = self._cw.form['result']
5          message = self._cw.form.get('message', '<no message>')
6 -        self._log_stack.append('%s: %s' % (result, message))
7 +        actual = self._cw.form.get('actual')
8 +        expected = self._cw.form.get('expected')
9 +        source = self._cw.form.get('source')
10 +        log = '%s: %s' % (result, message)
11 +        if result == 'false' and actual is not None and expected is not None:
12 +            log += ' (got: %s, expected: %s)' % (actual, expected)
13 +            if source is not None:
14 +                log += '\n' + source
15 +        self._log_stack.append(log)
16 
17 
18  class QUnitView(View):
19      __regid__ = 'qunit'
20 
@@ -274,10 +282,13 @@
21              QUnit.log(function (details) {
22                jQuery.ajax({
23                             url: BASE_URL + 'qunit_result',
24                             data: {"event": "log",
25                                    "result": details.result,
26 +                                  "actual": details.actual,
27 +                                  "expected": details.expected,
28 +                                  "source": details.source,
29                                    "message": details.message},
30                             async: false});
31              });''')
32          w(u'</script>')
33          w(u'<!-- Test script dependencies (tested code for example) -->')