source: trip-planner-front/node_modules/karma/lib/launchers/capture_timeout.js@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1const log = require('../logger').create('launcher')
2
3/**
4 * Kill browser if it does not capture in given `captureTimeout`.
5 */
6function CaptureTimeoutLauncher (timer, captureTimeout) {
7 if (!captureTimeout) {
8 return
9 }
10
11 let pendingTimeoutId = null
12
13 this.on('start', () => {
14 pendingTimeoutId = timer.setTimeout(() => {
15 pendingTimeoutId = null
16 if (this.state !== this.STATE_BEING_CAPTURED) {
17 return
18 }
19
20 log.warn(`${this.name} have not captured in ${captureTimeout} ms, killing.`)
21 this.error = 'timeout'
22 this.kill()
23 }, captureTimeout)
24 })
25
26 this.on('done', () => {
27 if (pendingTimeoutId) {
28 timer.clearTimeout(pendingTimeoutId)
29 pendingTimeoutId = null
30 }
31 })
32}
33
34CaptureTimeoutLauncher.decoratorFactory = function (timer,
35 /* config.captureTimeout */ captureTimeout) {
36 return function (launcher) {
37 CaptureTimeoutLauncher.call(launcher, timer, captureTimeout)
38 }
39}
40
41CaptureTimeoutLauncher.decoratorFactory.$inject = ['timer', 'config.captureTimeout']
42
43module.exports = CaptureTimeoutLauncher
Note: See TracBrowser for help on using the repository browser.