From deea912e896245b14dcb3c765f57eb344f8965fd Mon Sep 17 00:00:00 2001 From: Peter Wagenet Date: Wed, 23 Sep 2020 21:38:09 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#47888=20[qunit]=20?= =?UTF-8?q?Explicitly=20support=20Promise=20callbacks=20by=20@wagenet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The lack of explicit support is generally not problematic except when used in conjunction with @typescript-eslint/no-misused-promises which complains when a Promise is provided to a function that doesn't allow for it. --- types/qunit/index.d.ts | 12 ++++++------ types/qunit/test/global-test.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/types/qunit/index.d.ts b/types/qunit/index.d.ts index 88b80ce427..c4a1e2b75e 100644 --- a/types/qunit/index.d.ts +++ b/types/qunit/index.d.ts @@ -429,7 +429,7 @@ declare global { * * @callback callback Callback to execute. */ - begin(callback: (details: QUnit.BeginDetails) => void): void; + begin(callback: (details: QUnit.BeginDetails) => void | Promise): void; /** * Configuration for QUnit @@ -444,7 +444,7 @@ declare global { * * @param callback Callback to execute */ - done(callback: (details: QUnit.DoneDetails) => void): void; + done(callback: (details: QUnit.DoneDetails) => void | Promise): void; /** * Advanced and extensible data dumping for JavaScript. @@ -535,14 +535,14 @@ declare global { * * @param callback Callback to execute */ - moduleDone(callback: (details: QUnit.ModuleDoneDetails) => void): void; + moduleDone(callback: (details: QUnit.ModuleDoneDetails) => void | Promise): void; /** * Register a callback to fire whenever a module begins. * * @param callback Callback to execute */ - moduleStart(callback: (details: QUnit.ModuleStartDetails) => void): void; + moduleStart(callback: (details: QUnit.ModuleStartDetails) => void | Promise): void; /** * Adds a test to exclusively run, preventing all other tests from running. @@ -651,14 +651,14 @@ declare global { passed: number; total: number; runtime: number; - }) => void): void; + }) => void | Promise): void; /** * Register a callback to fire whenever a test begins. * * @param callback Callback to execute */ - testStart(callback: (details: QUnit.TestStartDetails) => void): void; + testStart(callback: (details: QUnit.TestStartDetails) => void | Promise): void; /** * Adds a test which expects at least one failing assertion during its run. diff --git a/types/qunit/test/global-test.ts b/types/qunit/test/global-test.ts index 9a80e31c13..563254a3f7 100644 --- a/types/qunit/test/global-test.ts +++ b/types/qunit/test/global-test.ts @@ -270,6 +270,37 @@ QUnit.testStart(function( details: QUnit.TestStartDetails ) { console.log( "Now running: ", details.name, ' from module ', details.module ); }); +async function timeout() { + return new Promise(resolve => setTimeout(resolve, 1)); +} + +// These async tests are intended to ensure the appropriate behavior for @typescript-eslint/no-misused-promises. +// However, we don't actually use typescript-eslint in this project and tslint has no equivalent, +// so we can't properly test it. +QUnit.begin(async function() { + await timeout(); +}); + +QUnit.done(async function() { + await timeout(); +}); + +QUnit.moduleDone(async function() { + await timeout(); +}); + +QUnit.moduleStart(async function() { + await timeout(); +}); + +QUnit.testDone(async function() { + await timeout(); +}); + +QUnit.testStart(async function() { + await timeout(); +}); + let Robot: any = () => {}; QUnit.module( "robot", {