(contextOrFileName: string | Mocha.Context)
| 273 | |
| 274 | const screenShotCount = new Map<string, number>(); |
| 275 | export async function generateScreenShotFileName(contextOrFileName: string | Mocha.Context) { |
| 276 | const fullTestNameHash = |
| 277 | typeof contextOrFileName === 'string' |
| 278 | ? '' |
| 279 | : (await computeHash(contextOrFileName.currentTest?.fullTitle() || '', 'SHA-256')).substring(0, 10); // Ensure file names are short enough for windows. |
| 280 | const testTitle = typeof contextOrFileName === 'string' ? '' : contextOrFileName.currentTest?.title || ''; |
| 281 | const counter = (screenShotCount.get(fullTestNameHash) || 0) + 1; |
| 282 | screenShotCount.set(fullTestNameHash, counter); |
| 283 | const fileNamePrefix = |
| 284 | typeof contextOrFileName === 'string' ? contextOrFileName : `${testTitle}_${fullTestNameHash}`; |
| 285 | const name = `${fileNamePrefix}_${counter}`.replace(/[\W]+/g, '_'); |
| 286 | return `${name}-screenshot.png`; |
| 287 | } |
no test coverage detected