(snapshot)
| 193 | } |
| 194 | |
| 195 | async function finalizeScreencast(snapshot) { |
| 196 | const { test, options, mode, steps } = snapshot |
| 197 | let { webmPath, srtPath } = snapshot |
| 198 | |
| 199 | const helper = getBrowserHelper() |
| 200 | if (snapshot.started && helper?.page?.screencast) { |
| 201 | try { |
| 202 | await helper.page.screencast.stop() |
| 203 | } catch (err) { |
| 204 | output.plugin('screencast', `stop failed: ${err.message}`) |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | const shouldKeep = mode === 'test' || (mode === 'fail' && snapshot.failed) |
| 209 | |
| 210 | if (options.video && webmPath) { |
| 211 | if (!shouldKeep) { |
| 212 | try { fs.unlinkSync(webmPath) } catch { /* file may not exist yet */ } |
| 213 | webmPath = null |
| 214 | } else { |
| 215 | ensureArtifactsObject(test) |
| 216 | test.artifacts.screencast = webmPath |
| 217 | attachJUnitArtifact(test, webmPath) |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | if (options.subtitles && steps) { |
| 222 | if (options.video && !shouldKeep) { |
| 223 | try { srtPath && fs.unlinkSync(srtPath) } catch { /* nothing to delete */ } |
| 224 | return |
| 225 | } |
| 226 | |
| 227 | let target = srtPath |
| 228 | if (!options.video) { |
| 229 | if (test.artifacts && test.artifacts.video) { |
| 230 | const { dir, name } = path.parse(test.artifacts.video) |
| 231 | target = path.join(dir, `${name}.srt`) |
| 232 | } else { |
| 233 | const baseDir = path.join(store.outputDir || '_output', 'screencast') |
| 234 | mkdirp.sync(baseDir) |
| 235 | const baseName = testToFileName(test, { suffix: '', unique: true }) |
| 236 | target = path.join(baseDir, `${baseName}.srt`) |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | if (!target) return |
| 241 | try { |
| 242 | await fs.promises.writeFile(target, buildSrt(steps)) |
| 243 | ensureArtifactsObject(test) |
| 244 | test.artifacts.subtitle = target |
| 245 | } catch (err) { |
| 246 | output.plugin('screencast', `failed to write SRT: ${err.message}`) |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | function formatTimestamp(timestampInMs) { |
| 252 | const date = new Date(0, 0, 0, 0, 0, 0, timestampInMs) |
no test coverage detected