1- import Mocha from "mocha" ;
2- import * as path from "node:path" ;
31import { getCursorlessRepoRoot } from "@cursorless/node-common" ;
4- import { runTestSubset , testSubsetGrepString } from "./testSubset" ;
52import { glob } from "glob" ;
3+ import Mocha from "mocha" ;
4+ import * as path from "node:path" ;
5+ import {
6+ logFailedTests ,
7+ runTestSubset ,
8+ shouldLogFailedTests ,
9+ testSubsetGrepString ,
10+ } from "./testSubset" ;
611
712/**
813 * Type of test to run, eg unit, vscode, talon
@@ -24,7 +29,7 @@ export enum TestType {
2429 neovim ,
2530}
2631
27- export function runAllTests ( ...types : TestType [ ] ) {
32+ export function runAllTests ( ...types : TestType [ ] ) : Promise < void > {
2833 return runTestsInDir (
2934 path . join ( getCursorlessRepoRoot ( ) , "packages" ) ,
3035 ( files ) =>
@@ -68,14 +73,23 @@ async function runTestsInDir(
6873
6974 try {
7075 // Run the mocha test
71- await new Promise < void > ( ( c , e ) => {
72- mocha . run ( ( failures ) => {
76+ await new Promise < void > ( ( resolve , reject ) => {
77+ const failedTests : string [ ] = [ ] ;
78+
79+ const runner = mocha . run ( ( failures ) => {
7380 if ( failures > 0 ) {
74- e ( new Error ( `${ failures } tests failed.` ) ) ;
81+ if ( shouldLogFailedTests ( ) ) {
82+ logFailedTests ( failedTests ) ;
83+ }
84+ reject ( `${ failures } tests failed.` ) ;
7585 } else {
76- c ( ) ;
86+ resolve ( ) ;
7787 }
7888 } ) ;
89+
90+ if ( shouldLogFailedTests ( ) ) {
91+ runner . on ( "fail" , ( test ) => failedTests . push ( test . fullTitle ( ) ) ) ;
92+ }
7993 } ) ;
8094 } catch ( err ) {
8195 console . error ( err ) ;
0 commit comments