forked from motss/app-datepicker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-tests.js
More file actions
119 lines (99 loc) · 2.98 KB
/
run-tests.js
File metadata and controls
119 lines (99 loc) · 2.98 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
const { createConfig, startServer } = require('es-dev-server');
const { performance } = require('perf_hooks');
const Launcher = require('@wdio/cli').default;
function debug(message, ...args) {
const timestamp = new Date().toJSON()
.replace('T', ' ')
.replace('Z', '')
console.debug(
`[${timestamp}] ${message}`,
...args
);
}
function to3Dp(x) {
return Math.floor(x * 1e3) / 1e3;
}
function toHumanTime(timestamp) {
if (timestamp < 1e3) return `${timestamp}ms`;
if (timestamp < (1e3 * 60)) return `${to3Dp(timestamp / 1e3)}s`;
if (timestamp < (1e3 * 60 * 60)) return `${to3Dp(timestamp / (1e3 * 60))}m`;
if (timestamp < (1e3 * 60 * 60 * 24)) return `${to3Dp(timestamp / (1e3 * 60 * 60))}h`;
return `${to3Dp(timestamp / (1e3 * 60 * 60 * 24))}`;
}
function readArg(argName) {
const args = process.argv;
const configFileIdx = process.argv.findIndex(n => n === argName);
if (configFileIdx < 0 || configFileIdx === args.length - 1) {
throw new Error(`${argName} is not defined`);
}
return args[configFileIdx + 1];
}
async function main() {
/**
* Not all ports are supported by Sauce Connect Proxy.
*
* @see https://wiki.saucelabs.com/display/DOCS/Sauce+Connect+Proxy+FAQs,
*/
const PORT = process.env.PORT || 4000;
const mainStartAt = performance.now();
const config = createConfig({
port: PORT,
nodeResolve: true,
logStartup: false,
logCompileErrors: false,
logErrorsToBrowser: true,
// babel = false,
// babelConfig,
// babelExclude = [],
// babelModernExclude = [],
// babelModuleExclude = [],
// basePath,
// compress = true,
// fileExtensions = [],
// hostname,
// http2 = false,
// logStartup,
// moduleDirs = ['node_modules'],
// nodeResolve = false,
// open = false,
// port,
// preserveSymlinks = false,
// sslCert,
// sslKey,
// watch = false,
// logErrorsToBrowser = false,
// polyfills = _constants.polyfillsModes.AUTO,
// responseTransformers,
// debug = false
});
const { server } = await startServer(config);
const gracefulShutdown = (code) => {
server.close((err) => {
const mainDuration = performance.now() - mainStartAt;
debug(`Finished in ${toHumanTime(mainDuration)}`);
if (err) console.error(`[ERROR] Failed to close server`, err);
else {
debug(`Server closed`);
}
process.exit(code);
});
// force shutdown after 15s timeout
setTimeout(() => {
debug(`Could not close server in time, forcefully shutting down`);
process.exit(code);
}, (15e3));
};
debug(`es-dev-server running at port ${PORT}...`);
[
'SIGTERM', // kill
'SIGINT', // Ctrl or Cmd + C
].forEach(n => process.on(n, gracefulShutdown));
const wdio = new Launcher(readArg('--config-file'));
const code = await wdio.run();
debug(`Completed. Closing server...`);
gracefulShutdown(code);
}
main().catch((err) => {
console.error('Fail to run tests', err);
process.exit(1);
});