I was looking at: Mocha run after all tests in all classes run and wondering if this was the only solution? It would be great to not have to nest all my tests.
I found this: https://levelup.gitconnected.com/typescript-and-mocha-hooks-c5d9ccffd58f and was able to get it working:
export const mochaHooks = (): Mocha.RootHookObject => {
return {
afterAll(this: Mocha.Context) {
console.log('In afterAll');
const suite = runnable.parent;
if (suite?.suites) {
for (const innerSuite of suite?.suites) {
console.log(innerSuite.title);
for (const test of innerSuite.tests) {
console.log(test.title);
console.log(test.isPassed());
}
}
}
},
};
};
but it's being triggered after every file instead of after all files. Does anyone know if there is a trick to make this work? Can I somehow aggregate the data in memory over many calls to this hook?