Skip to content

Commit 26c4892

Browse files
authored
ci: fix isolated-env test (#4883)
This test in firefox started to fail all of a sudden, and [almost consistently](#4881). I couldn't figure out why the test kept failing, so after playing around with the order of operations I figured out that the iframe is loading axe and calling the `axe-loaded` event [_before_ mocha runs the `before`](https://app.circleci.com/pipelines/github/dequelabs/axe-core/7369/workflows/8fa125f3-2a32-43d9-8ec9-d5a9ccd172df/jobs/79258?invite=true#step-109-11841_78) where we look for the event. So to fix it I changed up the loading order so the script runs first and adds the event tracking, and now the event tracking now happens outside the `before` function and keeps track of the logs. Then inside the `before` we see if the message has already been fired, otherwise we listen to the event as we were doing before.
1 parent 828e96c commit 26c4892

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

test/integration/full/isolated-env/isolated-env.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ <h2>Ok</h2>
116116
</main>
117117
<footer></footer>
118118

119+
<script src="/test/testutils.js"></script>
120+
<script src="isolated-env.js"></script>
121+
119122
<iframe
120123
id="isolated-frame"
121124
title="foo"
@@ -130,8 +133,6 @@ <h2>Ok</h2>
130133
<p>Paragraph with a <a href="#">link</a>.</p>
131134
</div>
132135
<div id="mocha"></div>
133-
<script src="/test/testutils.js"></script>
134-
<script src="isolated-env.js"></script>
135136
<script src="/test/integration/adapter.js"></script>
136137
</body>
137138
</html>

test/integration/full/isolated-env/isolated-env.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
/* global chai */
2+
var messages = [];
3+
window.addEventListener('message', function (msg) {
4+
messages.push(msg.data);
5+
});
26

37
describe('isolated-env test', function () {
48
'use strict';
@@ -40,11 +44,16 @@ describe('isolated-env test', function () {
4044
});
4145

4246
var isloadedPromise = new Promise(function (resolve, reject) {
43-
window.addEventListener('message', function (msg) {
44-
if (msg.data === 'axe-loaded') {
45-
resolve();
46-
}
47-
});
47+
if (messages.includes('axe-loaded')) {
48+
resolve();
49+
} else {
50+
window.addEventListener('message', function (msg) {
51+
if (msg.data === 'axe-loaded') {
52+
resolve();
53+
}
54+
});
55+
}
56+
4857
setTimeout(function () {
4958
reject(new Error('axe-loaded message not called'));
5059
}, 5000);

0 commit comments

Comments
 (0)