@camperaid/watest 2.4.6 → 2.4.8
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/.prettierrc.js +1 -3
- package/.watestrc.js +1 -3
- package/bin/watest.js +3 -8
- package/core/base.js +79 -56
- package/core/core.js +25 -45
- package/core/format.js +96 -56
- package/core/process_args.js +1 -5
- package/core/series.js +60 -56
- package/core/settings.js +27 -32
- package/core/spawn.js +14 -21
- package/core/util.js +12 -19
- package/eslint.config.js +27 -0
- package/index.js +15 -17
- package/interfaces/logger.js +1 -3
- package/interfaces/servicer.js +1 -3
- package/logging/filestream.js +3 -7
- package/logging/logging.js +5 -11
- package/logging/logpipe.js +21 -21
- package/package.json +12 -11
- package/tests/base/t_api.js +3 -6
- package/tests/base/t_contains.js +12 -12
- package/tests/base/t_core.js +11 -8
- package/tests/base/t_format.js +13 -14
- package/tests/base/t_is.js +9 -11
- package/tests/base/t_is_object.js +23 -25
- package/tests/base/t_is_primitive.js +12 -14
- package/tests/base/t_is_string.js +6 -8
- package/tests/base/t_ok.js +4 -6
- package/tests/base/t_stringify.js +6 -8
- package/tests/base/t_test_.js +3 -5
- package/tests/base/t_throws.js +73 -0
- package/tests/base/test.js +8 -18
- package/tests/e2e/samples/{loader/.watestrc.cjs → folder/.watestrc.js} +1 -1
- package/tests/e2e/samples/folder/package-lock.json +1019 -5940
- package/tests/e2e/samples/folder/package.json +3 -2
- package/tests/e2e/samples/folder/tests/meta.js +1 -1
- package/tests/e2e/samples/folder/tests/unit/t_test.js +3 -3
- package/tests/e2e/samples/{loader_mixed/.watestrc.cjs → loader/.watestrc.js} +1 -1
- package/tests/e2e/samples/loader/package-lock.json +1751 -28
- package/tests/e2e/samples/loader/package.json +2 -2
- package/tests/e2e/samples/{folder/.watestrc.cjs → loader_mixed/.watestrc.js} +1 -1
- package/tests/e2e/samples/loader_mixed/package-lock.json +1751 -28
- package/tests/e2e/samples/loader_multiple/{.watestrc.cjs → .watestrc.js} +1 -1
- package/tests/e2e/samples/loader_multiple/package-lock.json +1751 -28
- package/tests/e2e/samples/loader_multiple/package.json +2 -2
- package/tests/e2e/samples/single/.watestrc.js +5 -0
- package/tests/e2e/samples/single/package-lock.json +1017 -5938
- package/tests/e2e/samples/single/package.json +5 -2
- package/tests/e2e/samples/wd_mixed/{.watestrc.cjs → .watestrc.js} +1 -1
- package/tests/e2e/samples/wd_mixed/package-lock.json +779 -4862
- package/tests/e2e/samples/wd_mixed/package.json +2 -2
- package/tests/e2e/samples/wd_single/{.watestrc.cjs → .watestrc.js} +1 -1
- package/tests/e2e/samples/wd_single/package-lock.json +779 -4862
- package/tests/e2e/samples/wd_single/package.json +2 -2
- package/tests/e2e/t_folder.js +4 -6
- package/tests/e2e/t_loader.js +4 -6
- package/tests/e2e/t_loader_mixed.js +4 -6
- package/tests/e2e/t_loader_multiple.js +4 -6
- package/tests/e2e/t_loader_multiple_patterns.js +4 -6
- package/tests/e2e/t_single.js +4 -6
- package/tests/e2e/t_wd_firefox.js +4 -6
- package/tests/e2e/t_wd_firefox_chrome.js +4 -6
- package/tests/e2e/t_wd_firefox_chrome_pattern.js +4 -6
- package/tests/e2e/t_wd_mixed_firefox.js +4 -6
- package/tests/e2e/t_wd_mixed_firefox_chrome.js +4 -6
- package/tests/e2e/test.js +15 -16
- package/tests/meta.js +1 -3
- package/tests/series/build/t_adjust_names.js +4 -6
- package/tests/series/build/t_adjust_names_webdriver.js +6 -10
- package/tests/series/build/t_expected_failures.js +4 -6
- package/tests/series/build/t_loader.js +4 -6
- package/tests/series/build/t_loader_mixed.js +4 -6
- package/tests/series/build/t_mixed.js +4 -6
- package/tests/series/build/t_nested.js +4 -6
- package/tests/series/build/t_patterns_loader.js +4 -6
- package/tests/series/build/t_patterns_webdriver.js +4 -6
- package/tests/series/build/t_webdriver.js +4 -6
- package/tests/series/build/t_webdriver_firefox_mixed.js +4 -6
- package/tests/series/build/t_webdriver_nested.js +4 -6
- package/tests/series/build/t_webdriver_services.js +4 -6
- package/tests/series/generic/t_failures_info.js +9 -12
- package/tests/series/logging/t_failures.js +18 -20
- package/tests/series/logging/t_success.js +15 -17
- package/tests/series/logging/t_verify.js +17 -14
- package/tests/series/meta.js +1 -3
- package/tests/series/mock_series.js +7 -13
- package/tests/series/perform/t_failure.js +4 -6
- package/tests/series/perform/t_failure_notest.js +4 -6
- package/tests/series/perform/t_intermittent.js +5 -7
- package/tests/series/perform/t_intermittent_global.js +4 -6
- package/tests/series/perform/t_missing_perma.js +5 -7
- package/tests/series/perform/t_nested.js +4 -10
- package/tests/series/perform/t_perma.js +4 -6
- package/tests/series/perform/t_success.js +5 -11
- package/tests/series/run/t_debunk_failure.js +7 -6
- package/tests/series/run/t_debunk_success.js +7 -6
- package/tests/series/run/t_nested.js +7 -6
- package/tests/series/run/t_verify.js +7 -6
- package/tests/series/run/t_verify_webdriver.js +7 -6
- package/tests/series/test.js +29 -40
- package/tests/webdriver/meta.js +1 -3
- package/tests/webdriver/t_app_driver.js +3 -5
- package/tests/webdriver/t_app_driver_selectors.js +3 -5
- package/tests/webdriver/t_attribute.js +5 -7
- package/tests/webdriver/t_attribute_all.js +6 -8
- package/tests/webdriver/t_doubleclick.js +3 -5
- package/tests/webdriver/t_doubleclickat.js +3 -5
- package/tests/webdriver/t_execute.js +4 -6
- package/tests/webdriver/t_if_has_elements.js +6 -8
- package/tests/webdriver/t_if_no_elements.js +6 -8
- package/tests/webdriver/t_no_elements_or_not_visible.js +7 -9
- package/tests/webdriver/t_properties.js +11 -13
- package/tests/webdriver/t_script.js +8 -10
- package/tests/webdriver/t_select_all.js +6 -11
- package/tests/webdriver/t_selection.js +4 -6
- package/tests/webdriver/t_text.js +12 -14
- package/tests/webdriver/t_text_all.js +6 -8
- package/tests/webdriver/test.js +32 -41
- package/webdriver/app_driver.js +15 -19
- package/webdriver/control_driver.js +4 -8
- package/webdriver/driver.js +58 -61
- package/webdriver/driver_base.js +50 -60
- package/webdriver/session.js +6 -11
- package/webdriver/util.js +7 -8
- package/.eslintrc.js +0 -45
- package/index.mjs +0 -5
- package/tests/e2e/samples/folder/node_modules/.package-lock.json +0 -3871
- package/tests/e2e/samples/loader/node_modules/.package-lock.json +0 -36
- package/tests/e2e/samples/loader_mixed/node_modules/.package-lock.json +0 -36
- package/tests/e2e/samples/loader_multiple/node_modules/.package-lock.json +0 -36
- package/tests/e2e/samples/single/.watestrc.cjs +0 -5
- package/tests/e2e/samples/single/node_modules/.package-lock.json +0 -3871
- package/tests/e2e/samples/wd_mixed/node_modules/.package-lock.json +0 -3586
- package/tests/e2e/samples/wd_single/node_modules/.package-lock.json +0 -3586
package/core/series.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const { assert, fail } = testflow;
|
|
17
|
-
|
|
18
|
-
const {
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import nodepath from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
|
|
5
|
+
import { assert, fail, testflow } from './core.js';
|
|
6
|
+
import { parse, parse_failure } from './format.js';
|
|
7
|
+
import { ProcessArgs } from './process_args.js';
|
|
8
|
+
import settings from './settings.js';
|
|
9
|
+
import { spawn } from './spawn.js';
|
|
10
|
+
import { stringify } from './util.js';
|
|
11
|
+
import { log, log_error } from '../logging/logging.js';
|
|
12
|
+
import { LogPipe } from '../logging/logpipe.js';
|
|
13
|
+
import { DriverBase } from '../webdriver/driver_base.js';
|
|
14
|
+
|
|
15
|
+
import {
|
|
19
16
|
format_started,
|
|
20
17
|
format_completed,
|
|
21
18
|
format_failure,
|
|
@@ -25,10 +22,13 @@ const {
|
|
|
25
22
|
format_todos,
|
|
26
23
|
format_warnings,
|
|
27
24
|
colorify,
|
|
28
|
-
}
|
|
25
|
+
} from './format.js';
|
|
26
|
+
|
|
27
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
28
|
+
const __dirname = nodepath.dirname(__filename);
|
|
29
29
|
|
|
30
30
|
const root_folder = 'tests';
|
|
31
|
-
const root_dir =
|
|
31
|
+
const root_dir = nodepath.resolve('.');
|
|
32
32
|
|
|
33
33
|
const kKungFuDeathGripTimeout = {};
|
|
34
34
|
const kKungFuDeathGripCancelled = {};
|
|
@@ -44,7 +44,7 @@ process.on('unhandledRejection', error => {
|
|
|
44
44
|
class Series {
|
|
45
45
|
static run(patterns, options) {
|
|
46
46
|
if (!('LogPipe' in options)) {
|
|
47
|
-
options.LogPipe =
|
|
47
|
+
options.LogPipe = LogPipe;
|
|
48
48
|
}
|
|
49
49
|
options.LogPipe.suppress_logging = options.childProcess;
|
|
50
50
|
|
|
@@ -57,7 +57,7 @@ class Series {
|
|
|
57
57
|
.run()
|
|
58
58
|
.then(() =>
|
|
59
59
|
// shutdown returns list of failures or null if no failures
|
|
60
|
-
options.LogPipe.release()
|
|
60
|
+
options.LogPipe.release(),
|
|
61
61
|
)
|
|
62
62
|
.then(
|
|
63
63
|
() => series.shutdown(),
|
|
@@ -66,7 +66,7 @@ class Series {
|
|
|
66
66
|
fail(e.message);
|
|
67
67
|
log_error(e);
|
|
68
68
|
return failures;
|
|
69
|
-
}
|
|
69
|
+
},
|
|
70
70
|
);
|
|
71
71
|
});
|
|
72
72
|
}
|
|
@@ -86,7 +86,7 @@ class Series {
|
|
|
86
86
|
LogPipe,
|
|
87
87
|
webdriver,
|
|
88
88
|
webdrivers = settings.webdrivers,
|
|
89
|
-
}
|
|
89
|
+
},
|
|
90
90
|
) {
|
|
91
91
|
this.debunk = debunk;
|
|
92
92
|
this.invocation = invocation || settings.invocation;
|
|
@@ -107,7 +107,7 @@ class Series {
|
|
|
107
107
|
this.ocnt = 0;
|
|
108
108
|
|
|
109
109
|
this.core = core || testflow.core;
|
|
110
|
-
testflow.lock(this.core);
|
|
110
|
+
testflow.lock({ core: this.core });
|
|
111
111
|
|
|
112
112
|
this.core.setTimeout(timeout);
|
|
113
113
|
this.core.clearStats();
|
|
@@ -128,7 +128,7 @@ class Series {
|
|
|
128
128
|
this.patterns.map(pattern => ({
|
|
129
129
|
path: pattern,
|
|
130
130
|
webdriver: this.webdriver,
|
|
131
|
-
}))
|
|
131
|
+
})),
|
|
132
132
|
);
|
|
133
133
|
|
|
134
134
|
// In debunk mode re-run tests until it fails.
|
|
@@ -171,8 +171,8 @@ class Series {
|
|
|
171
171
|
colorify(
|
|
172
172
|
'failures',
|
|
173
173
|
'!Failed:',
|
|
174
|
-
`no tests matching '${stringify(patterns)}' pattern(s) found
|
|
175
|
-
)
|
|
174
|
+
`no tests matching '${stringify(patterns)}' pattern(s) found`,
|
|
175
|
+
),
|
|
176
176
|
);
|
|
177
177
|
return Promise.resolve();
|
|
178
178
|
}
|
|
@@ -206,7 +206,7 @@ class Series {
|
|
|
206
206
|
|
|
207
207
|
if (test_module.expected_failures) {
|
|
208
208
|
inherited_expected_failures = inherited_expected_failures.concat(
|
|
209
|
-
test_module.expected_failures.filter(v => v[0] == '**')
|
|
209
|
+
test_module.expected_failures.filter(v => v[0] == '**'),
|
|
210
210
|
);
|
|
211
211
|
}
|
|
212
212
|
|
|
@@ -251,7 +251,7 @@ class Series {
|
|
|
251
251
|
// A separate folder for the webdriver tests.
|
|
252
252
|
assert(
|
|
253
253
|
this.webdrivers instanceof Array,
|
|
254
|
-
`Webdrivers are misconfigured, got: ${JSON.stringify(this.webdrivers)}
|
|
254
|
+
`Webdrivers are misconfigured, got: ${JSON.stringify(this.webdrivers)}`,
|
|
255
255
|
);
|
|
256
256
|
|
|
257
257
|
// Build the tests for webdrivers. Filter the list according traversed
|
|
@@ -378,8 +378,8 @@ class Series {
|
|
|
378
378
|
}).then(subtests => ({
|
|
379
379
|
subfolder,
|
|
380
380
|
subtests,
|
|
381
|
-
}))
|
|
382
|
-
)
|
|
381
|
+
})),
|
|
382
|
+
),
|
|
383
383
|
);
|
|
384
384
|
|
|
385
385
|
return subtests_for_subfolders
|
|
@@ -425,7 +425,7 @@ class Series {
|
|
|
425
425
|
}
|
|
426
426
|
|
|
427
427
|
const expected_failures = inherited_expected_failures.concat(
|
|
428
|
-
test_module.expected_failures || []
|
|
428
|
+
test_module.expected_failures || [],
|
|
429
429
|
);
|
|
430
430
|
|
|
431
431
|
// Initialize
|
|
@@ -494,7 +494,7 @@ class Series {
|
|
|
494
494
|
await Promise.all(
|
|
495
495
|
[...(test_module.services || [])]
|
|
496
496
|
.reverse()
|
|
497
|
-
.map(s => settings.servicer.stop(s))
|
|
497
|
+
.map(s => settings.servicer.stop(s)),
|
|
498
498
|
);
|
|
499
499
|
};
|
|
500
500
|
tests.push({
|
|
@@ -533,7 +533,7 @@ class Series {
|
|
|
533
533
|
list = list.filter(
|
|
534
534
|
test =>
|
|
535
535
|
this.matchedPatterns({ path: test.path, webdriver, patterns })
|
|
536
|
-
.length != 0
|
|
536
|
+
.length != 0,
|
|
537
537
|
);
|
|
538
538
|
}
|
|
539
539
|
|
|
@@ -545,7 +545,7 @@ class Series {
|
|
|
545
545
|
pattern =>
|
|
546
546
|
(!webdriver || !pattern.webdriver || pattern.webdriver == webdriver) &&
|
|
547
547
|
(path.startsWith(pattern.path) ||
|
|
548
|
-
(path_is_not_final && pattern.path.startsWith(path)))
|
|
548
|
+
(path_is_not_final && pattern.path.startsWith(path))),
|
|
549
549
|
);
|
|
550
550
|
}
|
|
551
551
|
|
|
@@ -647,18 +647,18 @@ class Series {
|
|
|
647
647
|
// If timeout is given then race it against the test.
|
|
648
648
|
if (settings.timeout) {
|
|
649
649
|
kungFuDeathGrip = new Promise(
|
|
650
|
-
resolve => (kungFuDeathGripResolve = resolve)
|
|
650
|
+
resolve => (kungFuDeathGripResolve = resolve),
|
|
651
651
|
).then(value => {
|
|
652
652
|
if (value != kKungFuDeathGripCancelled) {
|
|
653
653
|
fail(
|
|
654
|
-
`Test ${name} takes longer than ${settings.timeout}ms. It's either slow or never ends
|
|
654
|
+
`Test ${name} takes longer than ${settings.timeout}ms. It's either slow or never ends.`,
|
|
655
655
|
);
|
|
656
656
|
return kKungFuDeathGripTimeout;
|
|
657
657
|
}
|
|
658
658
|
});
|
|
659
659
|
kungFuDeathGripTimer = setTimeout(
|
|
660
660
|
kungFuDeathGripResolve,
|
|
661
|
-
settings.timeout
|
|
661
|
+
settings.timeout,
|
|
662
662
|
);
|
|
663
663
|
let retval = await Promise.race([func(), kungFuDeathGrip]);
|
|
664
664
|
if (retval != kKungFuDeathGripTimeout) {
|
|
@@ -825,8 +825,8 @@ class Series {
|
|
|
825
825
|
format_failures(
|
|
826
826
|
this.core.failureCount - fcnt,
|
|
827
827
|
this.core.okCount - ocnt,
|
|
828
|
-
!is_root && folder
|
|
829
|
-
)
|
|
828
|
+
!is_root && folder,
|
|
829
|
+
),
|
|
830
830
|
);
|
|
831
831
|
} else {
|
|
832
832
|
log_func(format_success(this.core.okCount - ocnt, !is_root && folder));
|
|
@@ -835,7 +835,7 @@ class Series {
|
|
|
835
835
|
|
|
836
836
|
static failuresInfo({ failures, webdriver, platform, testname }) {
|
|
837
837
|
let filtered_failures = failures.filter(
|
|
838
|
-
v => testname.includes(v[0]) || v[0] == '*' || v[0] == '**'
|
|
838
|
+
v => testname.includes(v[0]) || v[0] == '*' || v[0] == '**',
|
|
839
839
|
);
|
|
840
840
|
|
|
841
841
|
return (
|
|
@@ -865,13 +865,14 @@ class Series {
|
|
|
865
865
|
async loadTestMeta(folder) {
|
|
866
866
|
try {
|
|
867
867
|
return await import(this.getTestMetaPath(folder));
|
|
868
|
+
// eslint-disable-next-line no-unused-vars
|
|
868
869
|
} catch (e) {
|
|
869
870
|
return {}; // no meta.js
|
|
870
871
|
}
|
|
871
872
|
}
|
|
872
873
|
|
|
873
874
|
loadTest(test_path) {
|
|
874
|
-
return import(
|
|
875
|
+
return import(nodepath.join(root_dir, test_path)).then(
|
|
875
876
|
test_module => {
|
|
876
877
|
if (!test_module.test) {
|
|
877
878
|
throw new Error(`No test was found in ${test_path}`);
|
|
@@ -881,25 +882,25 @@ class Series {
|
|
|
881
882
|
e => {
|
|
882
883
|
log_error(e);
|
|
883
884
|
throw new Error(`Failed to load test: ${test_path}`);
|
|
884
|
-
}
|
|
885
|
+
},
|
|
885
886
|
);
|
|
886
887
|
}
|
|
887
888
|
|
|
888
889
|
getTestMetaPath(folder) {
|
|
889
|
-
let meta_path =
|
|
890
|
+
let meta_path = nodepath.join(root_dir, `${folder}/meta.js`);
|
|
890
891
|
return (
|
|
891
892
|
(fs.existsSync(meta_path) && meta_path) ||
|
|
892
|
-
|
|
893
|
+
nodepath.join(root_dir, `${folder}/meta.mjs`)
|
|
893
894
|
);
|
|
894
895
|
}
|
|
895
896
|
|
|
896
897
|
getTestFileList(folder) {
|
|
897
898
|
return fs
|
|
898
|
-
.readdirSync(
|
|
899
|
+
.readdirSync(nodepath.join(root_dir, folder))
|
|
899
900
|
.filter(
|
|
900
901
|
n =>
|
|
901
902
|
n.startsWith('t_') &&
|
|
902
|
-
(!settings.ignorePattern || !settings.ignorePattern.test(n))
|
|
903
|
+
(!settings.ignorePattern || !settings.ignorePattern.test(n)),
|
|
903
904
|
);
|
|
904
905
|
}
|
|
905
906
|
|
|
@@ -916,14 +917,14 @@ class Series {
|
|
|
916
917
|
'--root-folder',
|
|
917
918
|
nodepath.join(name, '../'),
|
|
918
919
|
...ProcessArgs.controlArguments,
|
|
919
|
-
path
|
|
920
|
+
path,
|
|
920
921
|
);
|
|
921
922
|
if (webdriver) {
|
|
922
923
|
args.push('--webdriver', webdriver);
|
|
923
924
|
}
|
|
924
925
|
|
|
925
926
|
return spawn('node', args, {}, buffer =>
|
|
926
|
-
this.processChildProcessOutput(name, buffer)
|
|
927
|
+
this.processChildProcessOutput(name, buffer),
|
|
927
928
|
).catch(e => {
|
|
928
929
|
log_error(e);
|
|
929
930
|
fail(`Failed to process child process output`);
|
|
@@ -944,22 +945,22 @@ class Series {
|
|
|
944
945
|
if (line.startsWith('console.debug')) {
|
|
945
946
|
line = line.replace(
|
|
946
947
|
/console\.debug: "(.+)"/,
|
|
947
|
-
(match, p) => `[DEBUG] ${p}
|
|
948
|
+
(match, p) => `[DEBUG] ${p}`,
|
|
948
949
|
);
|
|
949
950
|
} else if (line.startsWith('console.log')) {
|
|
950
951
|
line = line.replace(
|
|
951
952
|
/console\.log: "(.+)"/,
|
|
952
|
-
(match, p) => `[INFO] ${p}
|
|
953
|
+
(match, p) => `[INFO] ${p}`,
|
|
953
954
|
);
|
|
954
955
|
} else if (line.startsWith('console.assert')) {
|
|
955
956
|
line = line.replace(
|
|
956
957
|
/console\.assert: "(.+)"/,
|
|
957
|
-
(match, p) => `[SEVERE] ${p}
|
|
958
|
+
(match, p) => `[SEVERE] ${p}`,
|
|
958
959
|
);
|
|
959
960
|
} else if (line.startsWith('console.error')) {
|
|
960
961
|
line = line.replace(
|
|
961
962
|
/console\.error: "(.+)"/,
|
|
962
|
-
(match, p) => `[SEVERE] ${p}
|
|
963
|
+
(match, p) => `[SEVERE] ${p}`,
|
|
963
964
|
);
|
|
964
965
|
} else if (line.startsWith('data:text/html,')) {
|
|
965
966
|
line = line.replace(/\S*/, '@dataurl_placeholder');
|
|
@@ -1018,5 +1019,8 @@ class Series {
|
|
|
1018
1019
|
}
|
|
1019
1020
|
}
|
|
1020
1021
|
|
|
1021
|
-
|
|
1022
|
-
|
|
1022
|
+
export { Series };
|
|
1023
|
+
|
|
1024
|
+
export function runSeries(...args) {
|
|
1025
|
+
return Series.run(...args);
|
|
1026
|
+
}
|
package/core/settings.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
|
|
5
|
-
let rc = null;
|
|
6
|
-
try {
|
|
7
|
-
rc = require(path.resolve('.', './.watestrc.js'));
|
|
8
|
-
} catch (e) {
|
|
9
|
-
rc = require(path.resolve('.', './.watestrc.cjs'));
|
|
10
|
-
}
|
|
1
|
+
import path from 'path';
|
|
11
2
|
|
|
12
3
|
class Settings {
|
|
13
4
|
constructor() {
|
|
@@ -16,20 +7,22 @@ class Settings {
|
|
|
16
7
|
this.tmp_storage_dir = '';
|
|
17
8
|
this.logger = null;
|
|
18
9
|
this.servicer = null;
|
|
19
|
-
|
|
20
|
-
this.setupTmpStorageDir();
|
|
21
|
-
this.setupLogDir();
|
|
22
|
-
this.setupWebdrivers();
|
|
23
10
|
}
|
|
24
11
|
|
|
25
12
|
async initialize() {
|
|
13
|
+
this.rc = (await import(path.resolve('.', './.watestrc.js'))).default;
|
|
14
|
+
|
|
26
15
|
this.logger = (
|
|
27
|
-
await import(rc.logger || '../interfaces/logger.js')
|
|
16
|
+
await import(this.rc.logger || '../interfaces/logger.js')
|
|
28
17
|
).default;
|
|
29
18
|
|
|
30
19
|
this.servicer = (
|
|
31
|
-
await import(rc.servicer || '../interfaces/servicer.js')
|
|
20
|
+
await import(this.rc.servicer || '../interfaces/servicer.js')
|
|
32
21
|
).default;
|
|
22
|
+
|
|
23
|
+
this.setupTmpStorageDir();
|
|
24
|
+
this.setupLogDir();
|
|
25
|
+
this.setupWebdrivers();
|
|
33
26
|
}
|
|
34
27
|
|
|
35
28
|
get invocation() {
|
|
@@ -41,64 +34,66 @@ class Settings {
|
|
|
41
34
|
break;
|
|
42
35
|
}
|
|
43
36
|
|
|
44
|
-
this._invocation = rc.invocation || `${platform}`;
|
|
37
|
+
this._invocation = this.rc.invocation || `${platform}`;
|
|
45
38
|
}
|
|
46
39
|
return this._invocation;
|
|
47
40
|
}
|
|
48
41
|
|
|
49
42
|
get ignorePattern() {
|
|
50
|
-
return rc.ignore_pattern && new RegExp(rc.ignore_pattern);
|
|
43
|
+
return this.rc.ignore_pattern && new RegExp(this.rc.ignore_pattern);
|
|
51
44
|
}
|
|
52
45
|
|
|
53
46
|
get debunkLimit() {
|
|
54
|
-
return parseInt(rc.debunk_limit) || 5;
|
|
47
|
+
return parseInt(this.rc.debunk_limit) || 5;
|
|
55
48
|
}
|
|
56
49
|
|
|
57
50
|
get timeout() {
|
|
58
|
-
return parseInt(rc.timeout) || 0;
|
|
51
|
+
return parseInt(this.rc.timeout) || 0;
|
|
59
52
|
}
|
|
60
53
|
|
|
61
54
|
setupTmpStorageDir() {
|
|
62
|
-
if (!rc.tmp_dir) {
|
|
55
|
+
if (!this.rc.tmp_dir) {
|
|
63
56
|
console.log(`Settings: no temporary storage dir`);
|
|
64
57
|
return;
|
|
65
58
|
}
|
|
66
59
|
|
|
67
|
-
this.tmp_storage_dir = path.join(rc.tmp_dir, 'watest-tmpstorage');
|
|
60
|
+
this.tmp_storage_dir = path.join(this.rc.tmp_dir, 'watest-tmpstorage');
|
|
68
61
|
console.log(
|
|
69
|
-
`Settings: temporary storage dir is at ${this.tmp_storage_dir}
|
|
62
|
+
`Settings: temporary storage dir is at ${this.tmp_storage_dir}`,
|
|
70
63
|
);
|
|
71
64
|
}
|
|
72
65
|
|
|
73
66
|
setupLogDir() {
|
|
74
|
-
const log_dir = rc.log_dir;
|
|
67
|
+
const log_dir = this.rc.log_dir;
|
|
75
68
|
if (!log_dir) {
|
|
76
69
|
console.log('Settings: no file logging');
|
|
77
70
|
return;
|
|
78
71
|
}
|
|
79
72
|
|
|
80
|
-
this.run = rc.run || `${parseInt(Date.now() / 1000)}`;
|
|
73
|
+
this.run = this.rc.run || `${parseInt(Date.now() / 1000)}`;
|
|
81
74
|
|
|
82
75
|
this.log_dir = path.join(log_dir, this.run);
|
|
83
76
|
console.log(`Settings: logging into ${log_dir}`);
|
|
84
77
|
}
|
|
85
78
|
|
|
86
79
|
setupWebdrivers() {
|
|
87
|
-
this.webdrivers = rc.webdrivers;
|
|
88
|
-
if (typeof rc.webdrivers == 'string') {
|
|
80
|
+
this.webdrivers = this.rc.webdrivers;
|
|
81
|
+
if (typeof this.rc.webdrivers == 'string') {
|
|
89
82
|
try {
|
|
90
|
-
this.webdrivers = JSON.parse(rc.webdrivers);
|
|
83
|
+
this.webdrivers = JSON.parse(this.rc.webdrivers);
|
|
91
84
|
} catch (e) {
|
|
92
85
|
console.error(
|
|
93
|
-
`Settings: failed to parse webdrivers '${rc.webdrivers}'
|
|
86
|
+
`Settings: failed to parse webdrivers '${this.rc.webdrivers}'`,
|
|
87
|
+
e,
|
|
94
88
|
);
|
|
95
89
|
}
|
|
96
90
|
}
|
|
97
91
|
|
|
98
92
|
this.webdriver = null;
|
|
99
93
|
this.webdriver_headless =
|
|
100
|
-
rc.webdriver_headless == true ||
|
|
101
|
-
|
|
94
|
+
this.rc.webdriver_headless == true ||
|
|
95
|
+
this.rc.webdriver_headless == 'true';
|
|
96
|
+
this.webdriver_loglevel = this.rc.webdriver_loglevel;
|
|
102
97
|
|
|
103
98
|
if (this.webdrivers) {
|
|
104
99
|
console.log(`Settings: ${this.webdrivers.join(', ')} webdrivers`);
|
|
@@ -106,4 +101,4 @@ class Settings {
|
|
|
106
101
|
}
|
|
107
102
|
}
|
|
108
103
|
|
|
109
|
-
|
|
104
|
+
export default new Settings();
|
package/core/spawn.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { spawn } = require('child_process');
|
|
4
|
-
|
|
5
|
-
const { log_error } = require('../logging/logging.js');
|
|
1
|
+
import { spawn as spawn_process } from 'child_process';
|
|
2
|
+
import { log_error } from '../logging/logging.js';
|
|
6
3
|
|
|
7
4
|
class ChildProcess {
|
|
8
5
|
constructor(on_output) {
|
|
@@ -12,17 +9,17 @@ class ChildProcess {
|
|
|
12
9
|
|
|
13
10
|
spawn(cmd, args, options) {
|
|
14
11
|
return new Promise((resolve, reject) => {
|
|
15
|
-
const cp =
|
|
12
|
+
const cp = spawn_process(cmd, args, options);
|
|
16
13
|
cp.on('close', (code, signal) =>
|
|
17
14
|
Promise.resolve(this.processChildProcessOutputPromise).then(() =>
|
|
18
|
-
signal == 'SIGUSR1' ? reject(code) : resolve(code)
|
|
19
|
-
)
|
|
15
|
+
signal == 'SIGUSR1' ? reject(code) : resolve(code),
|
|
16
|
+
),
|
|
20
17
|
);
|
|
21
18
|
cp.stdout.on('data', data =>
|
|
22
|
-
this.bufferizeChildProcesOutput(cp, data, true)
|
|
19
|
+
this.bufferizeChildProcesOutput(cp, data, true),
|
|
23
20
|
);
|
|
24
21
|
cp.stderr.on('data', data =>
|
|
25
|
-
this.bufferizeChildProcesOutput(cp, data, false)
|
|
22
|
+
this.bufferizeChildProcesOutput(cp, data, false),
|
|
26
23
|
);
|
|
27
24
|
cp.on('error', reject);
|
|
28
25
|
});
|
|
@@ -31,9 +28,8 @@ class ChildProcess {
|
|
|
31
28
|
bufferizeChildProcesOutput(cp, data, is_stdout) {
|
|
32
29
|
let str_data = data.toString();
|
|
33
30
|
|
|
34
|
-
let lastChunk =
|
|
35
|
-
this.childProcessOutputBuffer.length - 1
|
|
36
|
-
];
|
|
31
|
+
let lastChunk =
|
|
32
|
+
this.childProcessOutputBuffer[this.childProcessOutputBuffer.length - 1];
|
|
37
33
|
if (lastChunk && lastChunk.is_stdout == is_stdout) {
|
|
38
34
|
lastChunk.str_data += str_data;
|
|
39
35
|
} else {
|
|
@@ -57,9 +53,8 @@ class ChildProcess {
|
|
|
57
53
|
}
|
|
58
54
|
|
|
59
55
|
async processChildProcessBuffer() {
|
|
60
|
-
let lastChunk =
|
|
61
|
-
this.childProcessOutputBuffer.length - 1
|
|
62
|
-
];
|
|
56
|
+
let lastChunk =
|
|
57
|
+
this.childProcessOutputBuffer[this.childProcessOutputBuffer.length - 1];
|
|
63
58
|
if (!lastChunk || !lastChunk.str_data.endsWith('\n')) {
|
|
64
59
|
return null;
|
|
65
60
|
}
|
|
@@ -72,8 +67,6 @@ class ChildProcess {
|
|
|
72
67
|
}
|
|
73
68
|
}
|
|
74
69
|
|
|
75
|
-
|
|
76
|
-
spawn(cmd, args, options
|
|
77
|
-
|
|
78
|
-
},
|
|
79
|
-
};
|
|
70
|
+
export function spawn(cmd, args, options, on_output) {
|
|
71
|
+
return new ChildProcess(on_output).spawn(cmd, args, options);
|
|
72
|
+
}
|
package/core/util.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import querystring from 'querystring';
|
|
3
|
+
import util from 'util';
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const cfg = require('./settings.js');
|
|
5
|
+
import { log } from '../logging/logging.js';
|
|
6
|
+
import settings from './settings.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Logs object in console colored.
|
|
9
10
|
*/
|
|
10
11
|
function inspect(obj) {
|
|
11
|
-
log(
|
|
12
|
+
log(util.inspect(obj, false, null, true /* enable colors */));
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -38,7 +39,7 @@ function stringify(obj, traces = new Set()) {
|
|
|
38
39
|
}
|
|
39
40
|
if (obj instanceof Map) {
|
|
40
41
|
let entries = Array.from(obj.entries()).map(
|
|
41
|
-
([k, v]) => `${k}: ${stringify(v, traces)}
|
|
42
|
+
([k, v]) => `${k}: ${stringify(v, traces)}`,
|
|
42
43
|
);
|
|
43
44
|
return `Map{${entries.join(', ')}}`;
|
|
44
45
|
}
|
|
@@ -74,9 +75,9 @@ function stringify(obj, traces = new Set()) {
|
|
|
74
75
|
* A temporary storage dir.
|
|
75
76
|
*/
|
|
76
77
|
function initTmpStorage() {
|
|
77
|
-
if (
|
|
78
|
-
removeDir(
|
|
79
|
-
fs.mkdirSync(
|
|
78
|
+
if (settings.tmp_storage_dir) {
|
|
79
|
+
removeDir(settings.tmp_storage_dir);
|
|
80
|
+
fs.mkdirSync(settings.tmp_storage_dir);
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
|
|
@@ -102,15 +103,7 @@ function is_mac() {
|
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
function toDataURL(html) {
|
|
105
|
-
return `data:text/html,${
|
|
106
|
+
return `data:text/html,${querystring.escape(html)}`;
|
|
106
107
|
}
|
|
107
108
|
|
|
108
|
-
|
|
109
|
-
inspect,
|
|
110
|
-
stringify,
|
|
111
|
-
is_mac,
|
|
112
|
-
toDataURL,
|
|
113
|
-
|
|
114
|
-
removeDir,
|
|
115
|
-
initTmpStorage,
|
|
116
|
-
};
|
|
109
|
+
export { inspect, stringify, is_mac, toDataURL, removeDir, initTmpStorage };
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import js from '@eslint/js'; // eslint-disable-line n/no-unpublished-import
|
|
2
|
+
import nodePlugin from 'eslint-plugin-n'; // eslint-disable-line n/no-unpublished-import
|
|
3
|
+
|
|
4
|
+
export default [
|
|
5
|
+
js.configs.recommended,
|
|
6
|
+
nodePlugin.configs['flat/recommended-script'],
|
|
7
|
+
{
|
|
8
|
+
languageOptions: {
|
|
9
|
+
ecmaVersion: 2021,
|
|
10
|
+
sourceType: 'module',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
files: ['bin/watest.js'],
|
|
15
|
+
rules: {
|
|
16
|
+
'n/no-process-exit': 'off',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
files: ['tests/e2e/samples/**'],
|
|
21
|
+
settings: {
|
|
22
|
+
node: {
|
|
23
|
+
allowModules: ['watest'],
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
];
|
package/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {
|
|
1
|
+
import {
|
|
4
2
|
assert,
|
|
5
3
|
group,
|
|
6
4
|
fail,
|
|
@@ -10,30 +8,28 @@ const {
|
|
|
10
8
|
success,
|
|
11
9
|
todo,
|
|
12
10
|
warn,
|
|
13
|
-
}
|
|
11
|
+
} from './core/core.js';
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
import {
|
|
16
14
|
ok,
|
|
17
15
|
is,
|
|
18
16
|
contains,
|
|
19
17
|
is_output,
|
|
20
|
-
|
|
18
|
+
no_throws,
|
|
19
|
+
throws,
|
|
21
20
|
test_is,
|
|
22
21
|
test_contains,
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const { inspect } = require('./core/util.js');
|
|
22
|
+
} from './core/base.js';
|
|
26
23
|
|
|
27
|
-
|
|
24
|
+
import settings from './core/settings.js';
|
|
25
|
+
import { inspect } from './core/util.js';
|
|
26
|
+
import { AppDriver } from './webdriver/app_driver.js';
|
|
27
|
+
import { ControlDriver } from './webdriver/control_driver.js';
|
|
28
|
+
import { start_session, scope } from './webdriver/session.js';
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
const { ControlDriver } = require('./webdriver/control_driver.js');
|
|
31
|
-
const { start_session, scope } = require('./webdriver/session.js');
|
|
32
|
-
|
|
33
|
-
module.exports = {
|
|
30
|
+
export {
|
|
34
31
|
AppDriver,
|
|
35
32
|
ControlDriver,
|
|
36
|
-
|
|
37
33
|
assert,
|
|
38
34
|
contains,
|
|
39
35
|
failed,
|
|
@@ -44,6 +40,7 @@ module.exports = {
|
|
|
44
40
|
info,
|
|
45
41
|
inspect,
|
|
46
42
|
not_reached,
|
|
43
|
+
no_throws,
|
|
47
44
|
ok,
|
|
48
45
|
scope,
|
|
49
46
|
start_session,
|
|
@@ -51,6 +48,7 @@ module.exports = {
|
|
|
51
48
|
todo,
|
|
52
49
|
test_is,
|
|
53
50
|
test_contains,
|
|
54
|
-
|
|
51
|
+
throws,
|
|
55
52
|
warn,
|
|
53
|
+
settings,
|
|
56
54
|
};
|