-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workarounds for TypeScript shortcomings: * `@typedef` can't be namespaced in JS files, thus mandating awkward constructs like `/** @import { Logger } from './qtap.js' */`. * There is no way to apply a type to a `catch` clause in JS files. The workaround is to re-assign it to a local variable and type that like `catch (e) { /* @type {any} */ const err = e;`. * There is no way to disable type checking for an entire block, function, or otherwise multiple lines, thus mandating lots of `// @ts-ignore` lines for the same problem, or to move the code out into a separate file where the entire file is ignored (as I ended up doing for client.js). Reported 8y ago, microsoft/TypeScript#19573. * `@types/node` lacks Error.code or Error.stack definitinos, thus regularly requiring use of the above workarounds. Reported 3y ago, DefinitelyTyped/DefinitelyTyped#59692. * The `noUnusedLocals` rule is broken, making a paradoxal claim. ``` /** @import { Logger } from './qtap.js' */ /** * @param {Logger} logger */ ``` The above makes sense, and passes, until noUnusedLocals is enabled. Then it fails: ``` error TS6133: 'Logger' is declared but its value is never read. /** @import { Logger } from './qtap.js' */ ``` Removing the import, of course, causes a more severe error instead: ``` error TS2304: Cannot find name 'Logger'. * @param {Logger} logger ``` Reported 2y ago, closed as wontfix. microsoft/TypeScript#54042 * The `noUnusedParameters` errors on unused arguments before arguments that are required and used. It appears to be unconfigurable and thus serves no purpose. Leave disabled in favor of ESLint no-unused-vars.
- Loading branch information
Showing
10 changed files
with
165 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* eslint-disable no-undef, no-var -- Browser code */ | ||
// @ts-nocheck | ||
|
||
export function qtapClientHead () { | ||
// Support QUnit 3.0+: Enable TAP reporter, declaratively. | ||
window.qunit_config_reporters_tap = true; | ||
|
||
// See ARCHITECTURE.md#qtap-internal-client-send | ||
var qtapNativeLog = console.log; | ||
var qtapBuffer = ''; | ||
var qtapShouldSend = true; | ||
function qtapSend () { | ||
var body = qtapBuffer; | ||
qtapBuffer = ''; | ||
qtapShouldSend = false; | ||
|
||
var xhr = new XMLHttpRequest(); | ||
xhr.onload = xhr.onerror = () => { | ||
qtapShouldSend = true; | ||
if (qtapBuffer) { | ||
qtapSend(); | ||
} | ||
}; | ||
xhr.open('POST', '{{QTAP_URL}}', true); | ||
xhr.send(body); | ||
} | ||
console.log = function qtapLog (str) { | ||
if (typeof str === 'string') { | ||
qtapBuffer += str + '\n'; | ||
if (qtapShouldSend) { | ||
qtapShouldSend = false; | ||
setTimeout(qtapSend, 0); | ||
} | ||
} | ||
return qtapNativeLog.apply(this, arguments); | ||
}; | ||
|
||
// TODO: Forward console.warn, console.error, and onerror to server. | ||
// TODO: Report window.onerror as TAP comment, visible by default. | ||
// TODO: Report console.warn/console.error in --verbose mode. | ||
window.addEventListener('error', function (error) { | ||
console.log('Script error: ' + (error.message || 'Unknown error')); | ||
}); | ||
} | ||
|
||
export function qtapClientBody () { | ||
// Support QUnit 2.16 - 2.22: Enable TAP reporter, procedurally. | ||
if (typeof QUnit !== 'undefined' && QUnit.reporters && QUnit.reporters.tap && (!QUnit.config.reporters || !QUnit.config.reporters.tap)) { | ||
QUnit.reporters.tap.init(QUnit); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.