From 6f3285fbd742e6b8e638b25e0470d2931b6f6395 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Tue, 16 May 2023 01:34:57 +0200 Subject: [PATCH] Refactoring: improve codeQuality.spec.ts to use promises --- test/CodeQuality.spec.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/test/CodeQuality.spec.ts b/test/CodeQuality.spec.ts index 4be39f914..dbe177efa 100644 --- a/test/CodeQuality.spec.ts +++ b/test/CodeQuality.spec.ts @@ -7,8 +7,8 @@ import { describe, it } from "vitest" * @param reason * @private */ -function detectInCode(forbidden: string, reason: string): (done: () => void) => void { - return (done: () => void) => { +function detectInCode(forbidden: string, reason: string): Promise { + return new Promise((done) => { const excludedDirs = [ ".git", "node_modules", @@ -49,14 +49,23 @@ function detectInCode(forbidden: string, reason: string): (done: () => void) => console.error(found.length, "issues found") throw msg } - done() } ) - } + }) +} + +function wrap(promise: Promise): ((done: () => void) => void) { + return (done => { + promise.then(done) + }) +} + +function itAsync(name: string, promise: Promise){ + it(name, wrap(promise)) } describe("Code quality", () => { - it( + itAsync( "should not contain reverse", detectInCode( "reverse()", @@ -64,12 +73,12 @@ describe("Code quality", () => { ) ) - it( + itAsync( "should not contain 'constructor.name'", detectInCode("constructor\\.name", "This is not allowed, as minification does erase names.") ) - it( + itAsync( "should not contain 'innerText'", detectInCode( "innerText", @@ -77,7 +86,7 @@ describe("Code quality", () => { ) ) - it( + itAsync( "should not contain 'import * as name from \"xyz.json\"'", detectInCode( 'import \\* as [a-zA-Z0-9_]\\+ from \\"[.-_/a-zA-Z0-9]\\+\\.json\\"', @@ -85,7 +94,7 @@ describe("Code quality", () => { ) ) - it( + itAsync( "should not contain '[\"default\"]'", detectInCode('\\[\\"default\\"\\]', "Possible leftover of faulty default import") )