-
Notifications
You must be signed in to change notification settings - Fork 10
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
fix: make test runner work even if there is no AbortSignal
support
#36
Changes from 2 commits
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 |
---|---|---|
@@ -1,6 +1,28 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
AbortController, | ||
AbortSignal | ||
if (typeof AbortController === 'undefined') { | ||
module.exports = { | ||
AbortController: class AbortController { | ||
#eventListeners = new Set() | ||
signal = { | ||
aborted: false, | ||
addEventListener: (_, listener) => { | ||
this.#eventListeners.add(listener) | ||
}, | ||
removeEventListener: (_, listener) => { | ||
this.#eventListeners.delete(listener) | ||
} | ||
} | ||
|
||
abort () { | ||
this.signal.aborted = true | ||
this.#eventListeners.forEach(listener => listener()) | ||
} | ||
} | ||
} | ||
} else { | ||
module.exports = { | ||
AbortController, | ||
AbortSignal | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,10 @@ const main = async () => { | |
for await (const dirent of dir) { | ||
const ext = extname(dirent.name) | ||
if (ext === '.js' || ext === '.mjs') { | ||
if (typeof AbortSignal === 'undefined' && dirent.name.startsWith('test_runner_abort')) { | ||
console.log('no AbortSignal support, skipping', dirent.name) | ||
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. would the smoothest flow be to include an AbortSignal ponyfill for node 14? Are there any major concerns including one? 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 think this would be the nicest option, as long as node 14 is in maintenance lts 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 couldn't find any satisfying ponyfill. Note that we are running tests both with and without 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. right, I think this is a good compromise 👍 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. +1 |
||
continue | ||
} | ||
const filePath = join(MESSAGE_FOLDER, dirent.name) | ||
const expected = filePath.replace(/\.m?js$/, '.out') | ||
const testFile = await fs.open(filePath) | ||
|
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.
I believe the previous statement wasn't correct?
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.
Well now that I think about it, users are still allowed to pass an
AbortSignal
, which they can't pass if they don't haveAbortController
support themselves anyway. The part that doesn't work iscontext.signal
, I should put the warning on that section instead.