Skip to content

Commit

Permalink
Make esm-amd-loader dynamic require 404 test less flaky.
Browse files Browse the repository at this point in the history
Previously this test used a 1 second timeout to wait to see how many
times the error callback was called, which was flaky on CI. Now we
capture 404 errors and check callback calls after two 404s.

Fixes #507
  • Loading branch information
aomarks committed Jun 12, 2018
1 parent c7f1f04 commit 2598cd1
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions packages/esm-amd-loader/test/src/suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,25 @@ suite('dynamic require', () => {
});

test('calls error callback only once on multiple 404s', (done) => {
let numErrors = 0;
let num404s = 0;
let numCallbackCalls = 0;

window.addEventListener('error', on404, true);

function on404() {
if (++num404s === 2) {
window.removeEventListener('error', on404);
assert.equal(numCallbackCalls, 1);
done();
}
}

define(['require'], (require: any) => {
require(
['./not-found-a.js', './not-found-b.js'],
() => assert.fail(),
() => numErrors++);
() => numCallbackCalls++);
});

setTimeout(() => {
assert.equal(numErrors, 1);
done();
}, 1000);
});
});

Expand Down

0 comments on commit 2598cd1

Please sign in to comment.