This repository has been archived by the owner on Feb 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
e2e.js
executable file
·154 lines (140 loc) · 3.29 KB
/
e2e.js
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
const app = require('./server/app');
const child = require('child_process');
const path = require('path');
const yargs = require('yargs');
const argv = yargs
.usage('Usage: $0 [browser]')
.help('help')
.alias('help', 'h')
.option('headless', {
description: 'forcefully enable headless mode',
default: false,
type: 'boolean'
})
.option('no_headless', {
description: 'forcefully disable headless mode',
default: false,
type: 'boolean',
hidden: true
})
.option('no_build', {
description: 'do not run `npm run build` before running tests',
default: false,
type: 'boolean'
})
.option('no_server', {
description: 'do not run `node server` before running tests',
default: false,
type: 'boolean'
})
.option('port', {
description: 'specify port number to bind e2e server to',
default: 9000,
type: 'number'
})
.implies('no_server', 'port')
.option('browser', {
description: 'selenium compatible browser string',
default: 'chrome',
type: 'string'
})
.nargs('browser', 1)
.option('t', {
description: 'jest test regular expression',
default: 'e2e.*',
type: 'string'
})
.nargs('t', 1)
.check(function(args) {
if (args.headless === true && args.no_headless === true) {
throw new TypeError('--headless and --no_headless are mutually exclusive');
}
if (process.env.CI === 'true') {
if (args.no_headless) {
args.headless = false;
} else {
args.headless = true;
}
} else {
if (args.headless) {
args.headless = true;
} else {
args.headless = false;
}
}
return true;
})
.argv;
console.log(argv);
let listener;
let processes = [];
const cleanup = () => {
if (listener) {
listener.close();
}
processes.forEach((p) => {
p.kill('SIGTERM');
});
processes = [];
};
process.on('SIGTERM', () => {
cleanup();
process.exit(143);
});
process.on('exit', () => {
cleanup();
});
function test() {
let testcmd = 'test';
if (process.env.CI === 'true') {
testcmd = 'test:ci';
}
const e2eProcess = child.spawn('npm', ['run', testcmd, '--', '-t', argv.t, ...argv._], {
'env': {
...process.env,
...this
},
stdio: 'inherit'
});
processes.push(e2eProcess);
e2eProcess.on('close', process.exit);
}
function build(env, callback) {
const buildProcess = child.spawn('npm', ['run', 'build'], {
'env': {
...process.env,
...env
},
stdio: 'inherit'
});
processes.push(buildProcess);
buildProcess.on('close', callback);
}
function run(l) {
listener = l;
const port = listener ? listener.address().port : argv.port;
console.log(`Testing lobster server on port: ${port}`);
const uiBase = `http://localhost:${port}`;
const env = {
LOBSTER_E2E_SERVER_PORT: port,
LOBSTER_E2E_BROWSER: argv.browser,
LOBSTER_E2E_HEADLESS: argv.headless,
REACT_APP_LOGKEEPER_BASE: `${uiBase}/logkeeper`,
REACT_APP_EVERGREEN_BASE: `${uiBase}/evergreen`
};
if (argv.no_build) {
return test.call(env);
}
return build(env, test.bind(env));
}
if (argv.no_server === true) {
run(null);
} else {
const e2eLogPath = path.join(path.resolve('.'), '/e2e');
app.makeListener({
bind_address: '127.0.0.1',
port: 0,
logs: e2eLogPath,
e2e: true
}, run);
}