@camperaid/watest 2.3.6 → 2.3.9
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/.watestrc.js +5 -0
- package/README.md +13 -0
- package/core/base.js +14 -4
- package/core/core.js +7 -7
- package/core/series.js +17 -1
- package/core/settings.js +4 -0
- package/core/util.js +4 -3
- package/package.json +2 -2
- package/tests/base/t_is_object.js +19 -0
- package/tests/base/t_stringify.js +1 -0
- package/tests/e2e/samples/folder/node_modules/.package-lock.json +1 -1
- package/tests/e2e/samples/folder/package-lock.json +1 -1
- package/tests/e2e/samples/loader/node_modules/.package-lock.json +1 -1
- package/tests/e2e/samples/loader/package-lock.json +1 -1
- package/tests/e2e/samples/loader_mixed/node_modules/.package-lock.json +1 -1
- package/tests/e2e/samples/loader_mixed/package-lock.json +1 -1
- package/tests/e2e/samples/loader_multiple/node_modules/.package-lock.json +1 -1
- package/tests/e2e/samples/loader_multiple/package-lock.json +1 -1
- package/tests/e2e/samples/single/node_modules/.package-lock.json +1 -1
- package/tests/e2e/samples/single/package-lock.json +1 -1
- package/tests/e2e/samples/wd_mixed/node_modules/.package-lock.json +3551 -1
- package/tests/e2e/samples/wd_mixed/package-lock.json +5818 -12
- package/tests/e2e/samples/wd_single/node_modules/.package-lock.json +3551 -1
- package/tests/e2e/samples/wd_single/package-lock.json +5818 -12
- package/tests/series/build/t_loader_mixed.js +1 -1
- package/tests/webdriver/t_app_driver.js +2 -2
- package/webdriver/app_driver.js +17 -2
- package/webdriver/driver.js +35 -1
- package/webdriver/driver_base.js +34 -7
package/.watestrc.js
CHANGED
|
@@ -18,6 +18,11 @@ const cfg = {
|
|
|
18
18
|
*/
|
|
19
19
|
log_dir: process.env.WATEST_LOG_DIR,
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* If a test takes longer than the given number, the test will fail.
|
|
23
|
+
*/
|
|
24
|
+
timeout: process.env.WATEST_TIMEOUT,
|
|
25
|
+
|
|
21
26
|
/**
|
|
22
27
|
* Temporary storage dir. Recreated each test run. Shall be used to store
|
|
23
28
|
* files generated by tests if any.
|
package/README.md
CHANGED
|
@@ -49,6 +49,19 @@ Pre-defined webdrivers:
|
|
|
49
49
|
- `firefox` to run tests in Firefox
|
|
50
50
|
- `safari` to run tests in Safari
|
|
51
51
|
|
|
52
|
+
You can create `.env` file in the root directory to
|
|
53
|
+
define enviropment variables used for configuration.
|
|
54
|
+
Here's an example of `.env` file:
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
WATEST_DEBUNK_LIMIT=5
|
|
58
|
+
WATEST_LOG_DIR=/tmp
|
|
59
|
+
WATEST_TIMEOUT=3000
|
|
60
|
+
WATEST_WEBDRIVERS=["chrome", "firefox"]
|
|
61
|
+
WATEST_WEBDRIVER_HEADLESS=true
|
|
62
|
+
WATEST_WEBDRIVER_LOGLEVEL=info
|
|
63
|
+
```
|
|
64
|
+
|
|
52
65
|
## Unit testing
|
|
53
66
|
|
|
54
67
|
The testsuite has basic functions:
|
package/core/base.js
CHANGED
|
@@ -311,7 +311,8 @@ function is_object_impl(
|
|
|
311
311
|
// allowed to be an Object or in case of Set and Map it can be an Array.
|
|
312
312
|
if (
|
|
313
313
|
got instanceof Object &&
|
|
314
|
-
!(
|
|
314
|
+
(!(got.constructor instanceof Function) ||
|
|
315
|
+
!(expected instanceof got.constructor)) &&
|
|
315
316
|
(!expected ||
|
|
316
317
|
(expected.constructor != Object &&
|
|
317
318
|
(expected.constructor != Array ||
|
|
@@ -324,6 +325,17 @@ function is_object_impl(
|
|
|
324
325
|
return false;
|
|
325
326
|
}
|
|
326
327
|
|
|
328
|
+
// Date
|
|
329
|
+
if (got instanceof Date) {
|
|
330
|
+
if (got.valueOf() == expected.valueOf()) {
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
let got_str = stringify(got);
|
|
334
|
+
let expected_str = `expected: ${stringify(expected)}`;
|
|
335
|
+
fail_(`${contextmsg} unexpected value: ${got_str}, ${expected_str}`);
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
|
|
327
339
|
// Convert Set and Map to Arrays.
|
|
328
340
|
if (got instanceof Set) {
|
|
329
341
|
got = Array.from(got.values());
|
|
@@ -537,9 +549,7 @@ function is_out(got, expected, msg) {
|
|
|
537
549
|
|
|
538
550
|
let min = Math.min(got_i.length, exp_i.length);
|
|
539
551
|
for (let j = 0; j < min; j++) {
|
|
540
|
-
log_error(
|
|
541
|
-
`${j}\t'${got_i[j]}'\t'${exp_i[j]}'\t${exp_i[j] == got_i[j]}`
|
|
542
|
-
);
|
|
552
|
+
log_error(`${j}\t'${got_i[j]}'\t'${exp_i[j]}'\t${exp_i[j] == got_i[j]}`);
|
|
543
553
|
}
|
|
544
554
|
|
|
545
555
|
for (let j = min; j < got_i.length; j++) {
|
package/core/core.js
CHANGED
|
@@ -57,11 +57,16 @@ class Core {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
fail(msg) {
|
|
60
|
-
|
|
60
|
+
if (typeof msg == 'object') {
|
|
61
|
+
inspect(msg);
|
|
62
|
+
this.unconditional_fail('Unexpected exception');
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
61
66
|
for (let v of this.expectedFailures) {
|
|
62
67
|
if (v.group == '*' || v.group == this.currgroup) {
|
|
63
68
|
let f = v.list.find(f => f[1] == 0 || f[0] == '*');
|
|
64
|
-
if (f && (f[0] == '*' ||
|
|
69
|
+
if (f && (f[0] == '*' || msg.includes(f[0]))) {
|
|
65
70
|
f[1]++;
|
|
66
71
|
this.warn(msg);
|
|
67
72
|
|
|
@@ -78,11 +83,6 @@ class Core {
|
|
|
78
83
|
}
|
|
79
84
|
}
|
|
80
85
|
|
|
81
|
-
if (typeof msg == 'object') {
|
|
82
|
-
inspect(msg);
|
|
83
|
-
msg = 'Unexpected exception';
|
|
84
|
-
}
|
|
85
|
-
|
|
86
86
|
this.unconditional_fail(msg);
|
|
87
87
|
}
|
|
88
88
|
|
package/core/series.js
CHANGED
|
@@ -637,7 +637,23 @@ class Series {
|
|
|
637
637
|
let start_time = new Date();
|
|
638
638
|
try {
|
|
639
639
|
this.core.setExpectedFailures(failures_info);
|
|
640
|
-
|
|
640
|
+
|
|
641
|
+
// If timeout is given then race it against the test.
|
|
642
|
+
if (settings.timeout) {
|
|
643
|
+
let kungFuDeathGripTimer = 0;
|
|
644
|
+
let kungFuDeathGrip = new Promise(r => {
|
|
645
|
+
kungFuDeathGripTimer = setTimeout(r, settings.timeout);
|
|
646
|
+
}).then(() =>
|
|
647
|
+
fail(
|
|
648
|
+
`Test ${name} takes longer than ${settings.timeout}ms. It's either slow or never ends.`
|
|
649
|
+
)
|
|
650
|
+
);
|
|
651
|
+
|
|
652
|
+
await Promise.race([func(), kungFuDeathGrip]);
|
|
653
|
+
clearTimeout(kungFuDeathGripTimer);
|
|
654
|
+
} else {
|
|
655
|
+
await func(); // execute the test
|
|
656
|
+
}
|
|
641
657
|
} catch (e) {
|
|
642
658
|
let failmsg = e;
|
|
643
659
|
if (e instanceof Error) {
|
package/core/settings.js
CHANGED
package/core/util.js
CHANGED
|
@@ -8,9 +8,7 @@ const cfg = require('./settings.js');
|
|
|
8
8
|
* Logs object in console colored.
|
|
9
9
|
*/
|
|
10
10
|
function inspect(obj) {
|
|
11
|
-
log(
|
|
12
|
-
require('util').inspect(obj, false, null, true /* enable colors */)
|
|
13
|
-
);
|
|
11
|
+
log(require('util').inspect(obj, false, null, true /* enable colors */));
|
|
14
12
|
}
|
|
15
13
|
|
|
16
14
|
/**
|
|
@@ -31,6 +29,9 @@ function stringify(obj, traces = new Set()) {
|
|
|
31
29
|
if (obj instanceof Array) {
|
|
32
30
|
return `[${obj.map(i => stringify(i, traces)).join(', ')}]`;
|
|
33
31
|
}
|
|
32
|
+
if (obj instanceof Date) {
|
|
33
|
+
return obj.toISOString();
|
|
34
|
+
}
|
|
34
35
|
if (obj instanceof Set) {
|
|
35
36
|
let values = Array.from(obj.values());
|
|
36
37
|
return `Set[${values.map(i => stringify(i, traces)).join(', ')}]`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@camperaid/watest",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.9",
|
|
4
4
|
"description": "Web Application Testsuite",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=14.15.1"
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"watest": "./bin/watest.js"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
-
"
|
|
14
|
+
"postprepare": "bash tests/install.sh",
|
|
15
15
|
"lint": "eslint '**/*.js'",
|
|
16
16
|
"lint:staged": "eslint --",
|
|
17
17
|
"pretty": "prettier --write",
|
|
@@ -27,6 +27,25 @@ module.exports.test = async () => {
|
|
|
27
27
|
`types: Map`
|
|
28
28
|
);
|
|
29
29
|
|
|
30
|
+
// types: Date success
|
|
31
|
+
await is_output(
|
|
32
|
+
() => is_object(new Date('2022-01-01'), new Date('2022-01-01'), 'TstMsg'),
|
|
33
|
+
[`Ok: TstMsg, got: 2022-01-01T00:00:00.000Z`],
|
|
34
|
+
[],
|
|
35
|
+
`types: Date sucess`
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
// types: Date failure
|
|
39
|
+
await is_output(
|
|
40
|
+
() => is_object(new Date('2022-01-01'), new Date('2023-02-02'), 'TstMsg'),
|
|
41
|
+
[],
|
|
42
|
+
[
|
|
43
|
+
`Failed: TstMsg: unexpected value: 2022-01-01T00:00:00.000Z, expected: 2023-02-02T00:00:00.000Z`,
|
|
44
|
+
`Failed: TstMsg`,
|
|
45
|
+
],
|
|
46
|
+
`types: Date failure`
|
|
47
|
+
);
|
|
48
|
+
|
|
30
49
|
// function sucess
|
|
31
50
|
await is_output(
|
|
32
51
|
() => is_object({ field: 'hey' }, () => true, 'TstMsg'),
|
|
@@ -21,6 +21,7 @@ module.exports.test = () => {
|
|
|
21
21
|
is(stringify(new Set(['v1', 'v2'])), `Set['v1', 'v2']`, 'set');
|
|
22
22
|
is(stringify(new Map([['key', 'value']])), `Map{key: 'value'}`, 'map');
|
|
23
23
|
is(stringify(/\d+/), `/\\d+/`, 'regexp');
|
|
24
|
+
is(stringify(new Date('2022-01-01')), '2022-01-01T00:00:00.000Z', `Date`);
|
|
24
25
|
|
|
25
26
|
// functions
|
|
26
27
|
is(
|