Skip to content

Commit

Permalink
feat(test-kit): save browser screenshots of failed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zetmate committed Nov 15, 2023
1 parent 1a925b6 commit dfacc7d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/test-kit/src/with-feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,18 @@ export function withFeature(withFeatureOptions: IWithFeatureOptions = {}) {
},
);
}
dispose(
async () => {
const ctx = mochaCtx();

if (ctx?.currentTest?.state === 'failed') {
const screenshotDirPath = `${process.cwd()}/screenshots-of-failed`;
const testPath = ctx.currentTest.titlePath().join('/');
await featurePage.screenshot({ path: `${screenshotDirPath}/${testPath}.png` });
}
},
{ timeout: 3_000 },
);

function onPageError(e: Error) {
if (
Expand Down

0 comments on commit dfacc7d

Please sign in to comment.