From: Nicolas Coden Date: Sat, 16 Jun 2018 08:17:03 +0000 (+0200) Subject: Use pull request #11279 from ncoden/test/fix-interchange-debonce-test-race-condition... X-Git-Tag: v6.5.0-rc.1^2~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a127e22a87bae2c8195100a6a198b41b735c6d09;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Use pull request #11279 from ncoden/test/fix-interchange-debonce-test-race-condition for v6.5.0 2bebd870a feat: add `testInterval` test utility ad2a282e6 test: wait for debounce for slow browsers in Interval debounce test 33d009a48 docs: add doc for "tryInterval" test utility Signed-off-by: Nicolas Coden --- diff --git a/test/javascript/components/interchange.js b/test/javascript/components/interchange.js index 5ef9fd9a3..a08b2bca5 100755 --- a/test/javascript/components/interchange.js +++ b/test/javascript/components/interchange.js @@ -1,4 +1,4 @@ -describe('Interchange', function() { +describe('Interchange', function () { var plugin; var $html; @@ -180,9 +180,11 @@ describe('Interchange', function() { // Trigger several window resize synchrnously and asynchronously. // --- - // Functions are nested to control when the check is made after the last resize - // more precisely (after 10ms). Timeout delays are most often not respected - // and the differences between several timeouts running in parrallel can be huge. + // Timeout delays are most often not respected and the differences between several + // timeouts running in parrallel can be huge. To prevent race conditions we: + // * nest timeout in order to make the delay between them more precise + // * run the test several time to wait for the debounce, which may be finally + // called way after the expected time. setTimeout(function () { let spy = sinon.spy(plugin, '_reflow'); $(window).trigger('resize'); @@ -192,12 +194,18 @@ describe('Interchange', function() { $(window).trigger('resize'); $(window).trigger('resize'); - setTimeout(function () { - sinon.assert.calledOnce(spy); + tryInterval({ + interval: debounce, + timeout: 1000, + try: () => { + sinon.assert.calledOnce(spy); + }, + then: () => { + $.triggersInitialized = false; + done(); + }, + }); - $.triggersInitialized = false; - done(); - }, debounce + 1); }); }); }); diff --git a/test/javascript/index.html b/test/javascript/index.html index 42c828b93..9d27a78f2 100644 --- a/test/javascript/index.html +++ b/test/javascript/index.html @@ -21,6 +21,7 @@ chai.should(); +