forked from MapComplete/MapComplete
		
	Refactoring: improve codeQuality.spec.ts to use promises
This commit is contained in:
		
							parent
							
								
									82a860cbf5
								
							
						
					
					
						commit
						6f3285fbd7
					
				
					 1 changed files with 18 additions and 9 deletions
				
			
		| 
						 | 
					@ -7,8 +7,8 @@ import { describe, it } from "vitest"
 | 
				
			||||||
 * @param reason
 | 
					 * @param reason
 | 
				
			||||||
 * @private
 | 
					 * @private
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function detectInCode(forbidden: string, reason: string): (done: () => void) => void {
 | 
					function detectInCode(forbidden: string, reason: string): Promise<void> {
 | 
				
			||||||
    return (done: () => void) => {
 | 
					    return new Promise<void>((done) => {
 | 
				
			||||||
        const excludedDirs = [
 | 
					        const excludedDirs = [
 | 
				
			||||||
            ".git",
 | 
					            ".git",
 | 
				
			||||||
            "node_modules",
 | 
					            "node_modules",
 | 
				
			||||||
| 
						 | 
					@ -49,14 +49,23 @@ function detectInCode(forbidden: string, reason: string): (done: () => void) =>
 | 
				
			||||||
                    console.error(found.length, "issues found")
 | 
					                    console.error(found.length, "issues found")
 | 
				
			||||||
                    throw msg
 | 
					                    throw msg
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                done()
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
    }
 | 
					    })
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function wrap(promise: Promise<void>): ((done: () => void) => void) {
 | 
				
			||||||
 | 
					    return (done => {
 | 
				
			||||||
 | 
					        promise.then(done)
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function itAsync(name: string, promise: Promise<void>){
 | 
				
			||||||
 | 
					    it(name, wrap(promise))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
describe("Code quality", () => {
 | 
					describe("Code quality", () => {
 | 
				
			||||||
    it(
 | 
					    itAsync(
 | 
				
			||||||
        "should not contain reverse",
 | 
					        "should not contain reverse",
 | 
				
			||||||
        detectInCode(
 | 
					        detectInCode(
 | 
				
			||||||
            "reverse()",
 | 
					            "reverse()",
 | 
				
			||||||
| 
						 | 
					@ -64,12 +73,12 @@ describe("Code quality", () => {
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it(
 | 
					    itAsync(
 | 
				
			||||||
        "should not contain 'constructor.name'",
 | 
					        "should not contain 'constructor.name'",
 | 
				
			||||||
        detectInCode("constructor\\.name", "This is not allowed, as minification does erase names.")
 | 
					        detectInCode("constructor\\.name", "This is not allowed, as minification does erase names.")
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it(
 | 
					    itAsync(
 | 
				
			||||||
        "should not contain 'innerText'",
 | 
					        "should not contain 'innerText'",
 | 
				
			||||||
        detectInCode(
 | 
					        detectInCode(
 | 
				
			||||||
            "innerText",
 | 
					            "innerText",
 | 
				
			||||||
| 
						 | 
					@ -77,7 +86,7 @@ describe("Code quality", () => {
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it(
 | 
					    itAsync(
 | 
				
			||||||
        "should not contain 'import * as name from \"xyz.json\"'",
 | 
					        "should not contain 'import * as name from \"xyz.json\"'",
 | 
				
			||||||
        detectInCode(
 | 
					        detectInCode(
 | 
				
			||||||
            'import \\* as [a-zA-Z0-9_]\\+ from \\"[.-_/a-zA-Z0-9]\\+\\.json\\"',
 | 
					            '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\"]'",
 | 
					        "should not contain '[\"default\"]'",
 | 
				
			||||||
        detectInCode('\\[\\"default\\"\\]', "Possible leftover of faulty default import")
 | 
					        detectInCode('\\[\\"default\\"\\]', "Possible leftover of faulty default import")
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue