-
-
Notifications
You must be signed in to change notification settings - Fork 752
Expand file tree
/
Copy pathtimeout_test.js
More file actions
119 lines (105 loc) · 4.51 KB
/
timeout_test.js
File metadata and controls
119 lines (105 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import * as chai from 'chai';
chai.should();
import { expect } from 'expect';
import { exec } from 'child_process';
import path from 'path';
import { codecept_dir, codecept_run } from './consts.js';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const debug_this_test = false
const config_run_config = (config, grep, verbose = false) => `${codecept_run} ${verbose || debug_this_test ? '--verbose' : ''} --config ${codecept_dir}/configs/timeouts/${config} ${grep ? `--grep "${grep}"` : ''}`
describe('CodeceptJS Timeouts', function () {
this.timeout(10000)
// some times messages are different
this.retries(2)
it('should stop test when timeout exceeded', done => {
exec(config_run_config('codecept.conf.cjs', 'timed out'), (err, stdout) => {
debug_this_test && console.log(stdout)
expect(stdout).toContain('Timeout 2s exceeded (with Before hook)')
// The second scenario can show either format depending on which timeout triggers first
expect(stdout.includes('Timeout 1s exceeded (with Before hook)') || stdout.includes('timed out after 1s')).toBeTruthy()
expect(err).toBeTruthy()
done()
})
})
it('should take --no-timeouts option', done => {
exec(`${config_run_config('codecept.conf.cjs', 'timed out')} --no-timeouts`, (err, stdout) => {
debug_this_test && console.log(stdout)
expect(stdout).toContain('Timeouts were disabled')
expect(stdout).not.toContain('Timeout 2s exceeded (with Before hook)')
expect(stdout).not.toContain('Timeout 1s exceeded (with Before hook)')
expect(err).toBeFalsy()
done()
})
})
it('should ignore timeouts if no timeout', done => {
exec(config_run_config('codecept.conf.cjs', 'no timeout test'), (err, stdout) => {
debug_this_test && console.log(stdout)
expect(stdout).not.toContain('TimeoutError')
expect(stdout).not.toContain('was interrupted on')
expect(err).toBeFalsy()
done()
})
})
it('should use global timeouts if timeout is set', done => {
this.retries(3)
exec(config_run_config('codecept.timeout.conf.cjs', 'no timeout test'), (err, stdout) => {
debug_this_test && console.log(stdout)
expect(stdout).toContain('Timeout 0.1')
expect(err).toBeTruthy()
done()
})
})
it('should prefer step timeout', done => {
exec(config_run_config('codecept.conf.cjs', 'timeout step', true), (err, stdout) => {
debug_this_test && console.log(stdout)
expect(stdout).toContain('was interrupted on timeout 200ms')
expect(err).toBeTruthy()
done()
})
})
it('should keep timeout with steps', done => {
exec(config_run_config('codecept.timeout.conf.cjs', 'timeout step', true), (err, stdout) => {
debug_this_test && console.log(stdout)
expect(stdout).toContain('was interrupted on timeout 100ms')
expect(err).toBeTruthy()
done()
})
})
it('should override timeout config from global object', done => {
exec(config_run_config('codecept.timeout.obj.conf.cjs', '#first', false), (err, stdout) => {
debug_this_test && console.log(stdout)
expect(stdout).toContain('Timeout 0.3s exceeded (with Before hook)')
expect(err).toBeTruthy()
done()
})
})
it('should override timeout config from global object but respect local value', done => {
exec(config_run_config('codecept.timeout.obj.conf.cjs', '#second'), (err, stdout) => {
debug_this_test && console.log(stdout)
expect(stdout).not.toContain('Timeout 0.3s exceeded (with Before hook)')
expect(stdout).toContain('Timeout 0.5s exceeded (with Before hook)')
expect(err).toBeTruthy()
done()
})
})
it('should respect grep when overriding config from global config', done => {
exec(config_run_config('codecept.timeout.obj.conf.cjs', '#fourth'), (err, stdout) => {
debug_this_test && console.log(stdout)
expect(stdout).not.toContain('Timeout 0.3s exceeded (with Before hook)')
expect(stdout).toContain('Timeout 1s exceeded (with Before hook)')
expect(err).toBeTruthy()
done()
})
})
it('should enforce global timeout even with BeforeSuite', done => {
exec(config_run_config('codecept.beforeSuiteTimeout.conf.cjs', 'enforce global timeout with BeforeSuite', true), (err, stdout) => {
debug_this_test && console.log(stdout)
expect(stdout).toContain('Timeout 2s exceeded')
expect(stdout).toContain('TestTimeoutError')
expect(err).toBeTruthy()
done()
})
})
})