@camperaid/watest 2.5.4 → 2.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/series.js +14 -6
- package/core/settings.js +2 -2
- package/package.json +1 -1
- package/tests/series/perform/t-timeout.js +107 -0
- package/webdriver/driver-base.js +1 -1
package/core/series.js
CHANGED
|
@@ -500,13 +500,17 @@ class Series {
|
|
|
500
500
|
testname: path,
|
|
501
501
|
});
|
|
502
502
|
|
|
503
|
-
|
|
503
|
+
const testObj = {
|
|
504
504
|
name,
|
|
505
505
|
path,
|
|
506
506
|
func: test_wrap,
|
|
507
507
|
webdriver,
|
|
508
508
|
failures_info,
|
|
509
|
-
}
|
|
509
|
+
};
|
|
510
|
+
if (test_module.timeout) {
|
|
511
|
+
testObj.timeout = test_module.timeout;
|
|
512
|
+
}
|
|
513
|
+
tests.push(testObj);
|
|
510
514
|
}
|
|
511
515
|
|
|
512
516
|
// Add tests from subfolders.
|
|
@@ -653,6 +657,7 @@ class Series {
|
|
|
653
657
|
skip_on_fail,
|
|
654
658
|
run_in_child_process,
|
|
655
659
|
init_or_uninit,
|
|
660
|
+
timeout,
|
|
656
661
|
} = test;
|
|
657
662
|
|
|
658
663
|
if (stop && !name.endsWith('uninit')) {
|
|
@@ -678,6 +683,7 @@ class Series {
|
|
|
678
683
|
|
|
679
684
|
// Invoke a test.
|
|
680
685
|
log(`\n!Running: ${name}, path: ${path}\n`);
|
|
686
|
+
|
|
681
687
|
let start_time = new Date();
|
|
682
688
|
let kungFuDeathGrip = null;
|
|
683
689
|
let kungFuDeathGripResolve = null;
|
|
@@ -695,21 +701,23 @@ class Series {
|
|
|
695
701
|
try {
|
|
696
702
|
this.core.setExpectedFailures(failures_info);
|
|
697
703
|
|
|
698
|
-
// If timeout is given then race it against the test.
|
|
699
|
-
|
|
704
|
+
// If timeout is given (from meta.js or settings) then race it against the test.
|
|
705
|
+
const effectiveTimeout = timeout ?? settings.timeout;
|
|
706
|
+
if (effectiveTimeout) {
|
|
707
|
+
const timeoutMs = effectiveTimeout * 1000;
|
|
700
708
|
kungFuDeathGrip = new Promise(
|
|
701
709
|
resolve => (kungFuDeathGripResolve = resolve),
|
|
702
710
|
).then(value => {
|
|
703
711
|
if (value != kKungFuDeathGripCancelled) {
|
|
704
712
|
fail(
|
|
705
|
-
`Test ${name} takes longer than ${
|
|
713
|
+
`Test ${name} takes longer than ${effectiveTimeout}s. It's either slow or never ends.`,
|
|
706
714
|
);
|
|
707
715
|
return kKungFuDeathGripTimeout;
|
|
708
716
|
}
|
|
709
717
|
});
|
|
710
718
|
kungFuDeathGripTimer = setTimeout(
|
|
711
719
|
kungFuDeathGripResolve,
|
|
712
|
-
|
|
720
|
+
timeoutMs,
|
|
713
721
|
);
|
|
714
722
|
let retval = await Promise.race([func(), kungFuDeathGrip]);
|
|
715
723
|
if (retval != kKungFuDeathGripTimeout) {
|
package/core/settings.js
CHANGED
|
@@ -54,11 +54,11 @@ class Settings {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
get testFilePattern() {
|
|
57
|
-
return this.rc
|
|
57
|
+
return this.rc?.test_file_pattern || /^t[-_]/;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
get timeout() {
|
|
61
|
-
return parseInt(this.rc
|
|
61
|
+
return parseInt(this.rc?.timeout) || 0;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
setupTmpStorageDir() {
|
package/package.json
CHANGED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { is_test_output } from '../test.js';
|
|
2
|
+
import { success } from '../../../core/core.js';
|
|
3
|
+
import { Core } from '../../../core/core.js';
|
|
4
|
+
import { Series } from '../../../core/series.js';
|
|
5
|
+
|
|
6
|
+
class MockLogPipe {
|
|
7
|
+
attach() {
|
|
8
|
+
return Promise.resolve();
|
|
9
|
+
}
|
|
10
|
+
release() {
|
|
11
|
+
return Promise.resolve();
|
|
12
|
+
}
|
|
13
|
+
logToFile() {}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function make_perform_with_timeout(tests) {
|
|
17
|
+
return async () => {
|
|
18
|
+
const series = new Series('tests/', {
|
|
19
|
+
core: new Core(),
|
|
20
|
+
LogPipe: new MockLogPipe(),
|
|
21
|
+
});
|
|
22
|
+
try {
|
|
23
|
+
await series.perform({ folder: 'tests/', tests });
|
|
24
|
+
} finally {
|
|
25
|
+
series.shutdown();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function test() {
|
|
31
|
+
// Test that timeout from meta.js causes test to fail after specified time
|
|
32
|
+
await is_test_output(
|
|
33
|
+
make_perform_with_timeout([
|
|
34
|
+
{
|
|
35
|
+
name: 't-slow.js',
|
|
36
|
+
path: 'tests/t-slow.js',
|
|
37
|
+
func: () => new Promise(resolve => setTimeout(resolve, 500)),
|
|
38
|
+
failures_info: [],
|
|
39
|
+
timeout: 0.05, // 50ms timeout in seconds
|
|
40
|
+
},
|
|
41
|
+
]),
|
|
42
|
+
[
|
|
43
|
+
'\x1B[38;5;99mStarted\x1B[0m tests/',
|
|
44
|
+
'!Running: t-slow.js, path: tests/t-slow.js',
|
|
45
|
+
'>t-slow.js completed in',
|
|
46
|
+
'\x1B[38;5;243mCompleted\x1B[0m tests/',
|
|
47
|
+
'Testsuite: shutdown',
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
"\x1B[31mFailed:\x1B[0m Test t-slow.js takes longer than 0.05s. It's either slow or never ends.",
|
|
51
|
+
'\x1B[31m>t-slow.js\x1B[0m has 1 failure(s)',
|
|
52
|
+
],
|
|
53
|
+
'meta timeout causes test to fail',
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
// Test that test completes normally when timeout is not exceeded
|
|
57
|
+
await is_test_output(
|
|
58
|
+
make_perform_with_timeout([
|
|
59
|
+
{
|
|
60
|
+
name: 't-fast.js',
|
|
61
|
+
path: 'tests/t-fast.js',
|
|
62
|
+
func: () => {
|
|
63
|
+
success('fast test passes');
|
|
64
|
+
return Promise.resolve();
|
|
65
|
+
},
|
|
66
|
+
failures_info: [],
|
|
67
|
+
timeout: 1, // 1 second timeout
|
|
68
|
+
},
|
|
69
|
+
]),
|
|
70
|
+
[
|
|
71
|
+
'\x1B[38;5;99mStarted\x1B[0m tests/',
|
|
72
|
+
'!Running: t-fast.js, path: tests/t-fast.js',
|
|
73
|
+
'\x1B[32mOk:\x1B[0m fast test passes',
|
|
74
|
+
'>t-fast.js completed in',
|
|
75
|
+
'\x1B[38;5;243mCompleted\x1B[0m tests/',
|
|
76
|
+
'Testsuite: shutdown',
|
|
77
|
+
],
|
|
78
|
+
[],
|
|
79
|
+
'test completes within timeout',
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
// Test that no timeout applies when timeout is undefined
|
|
83
|
+
await is_test_output(
|
|
84
|
+
make_perform_with_timeout([
|
|
85
|
+
{
|
|
86
|
+
name: 't-no-timeout.js',
|
|
87
|
+
path: 'tests/t-no-timeout.js',
|
|
88
|
+
func: () => {
|
|
89
|
+
success('no timeout test passes');
|
|
90
|
+
return new Promise(resolve => setTimeout(resolve, 10));
|
|
91
|
+
},
|
|
92
|
+
failures_info: [],
|
|
93
|
+
// timeout: undefined - no timeout set
|
|
94
|
+
},
|
|
95
|
+
]),
|
|
96
|
+
[
|
|
97
|
+
'\x1B[38;5;99mStarted\x1B[0m tests/',
|
|
98
|
+
'!Running: t-no-timeout.js, path: tests/t-no-timeout.js',
|
|
99
|
+
'\x1B[32mOk:\x1B[0m no timeout test passes',
|
|
100
|
+
'>t-no-timeout.js completed in',
|
|
101
|
+
'\x1B[38;5;243mCompleted\x1B[0m tests/',
|
|
102
|
+
'Testsuite: shutdown',
|
|
103
|
+
],
|
|
104
|
+
[],
|
|
105
|
+
'test runs without timeout when not specified',
|
|
106
|
+
);
|
|
107
|
+
}
|
package/webdriver/driver-base.js
CHANGED
|
@@ -30,7 +30,7 @@ function getChromeOptions() {
|
|
|
30
30
|
height: settings.webdriver_window_height,
|
|
31
31
|
});
|
|
32
32
|
if (settings.webdriver_headless) {
|
|
33
|
-
chromeOptions.addArguments('headless');
|
|
33
|
+
chromeOptions.addArguments('headless=new');
|
|
34
34
|
}
|
|
35
35
|
if (settings.webdriver == 'chrome-mobile') {
|
|
36
36
|
chromeOptions.setMobileEmulation({
|