-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make esm-amd-loader dynamic require 404 test not flaky. #511
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer inert conditionals. num404s++;
if (num404s === 2) {
... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
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++); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, what we really want to do is wait for the first error callback, and consider the test a success if the error callback isn't called again within the next little while (i.e. using setTimeout). That should be non-flaky. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC that would be more error prone (since network latency between the two fetches could cause the test to incorrectly pass) and slower (since we have to wait for the timeout). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did need to add a tick to let the error handlers get called though. Seems reliably green on sauce now, will see what CI says. |
||
}); | ||
|
||
setTimeout(() => { | ||
assert.equal(numErrors, 1); | ||
done(); | ||
}, 1000); | ||
}); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I don't think this is the expected behavior.
require
should not throw a global error, it should only call the failure callback shouldn't it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, is this the browser doing this? Emitting a window error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you can capture the browser network errors by adding the capture phase listener (the true).