-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathwdio.conf.ts
155 lines (136 loc) · 3.61 KB
/
wdio.conf.ts
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
155
import {Options} from '@wdio/types';
import * as fs from 'fs';
import * as path from 'path';
import * as selfsigned from 'selfsigned';
import {WebSocketServer} from 'ws';
import {startMockServer} from './test-server/server';
import {randomUUID} from 'crypto';
const {
USE_BROWSERSTACK,
USE_HEADLESS_BROWSER,
BROWSERSTACK_USERNAME,
BROWSERSTACK_KEY,
BROWSER_NAME,
BROWSERSTACK_BROWSER_VERSION,
BROWSERSTACK_OS,
BROWSERSTACK_OS_VERSION,
} = process.env;
const useBrowserstack = USE_BROWSERSTACK === 'true';
let mockServer: WebSocketServer | undefined;
export const config: Options.Testrunner = {
runner: [
'browser',
{
headless: USE_HEADLESS_BROWSER === 'true',
viteConfig: {
optimizeDeps: {
include: ['nice-grpc-common'],
},
build: {
commonjsOptions: {
include: [/nice-grpc-common/, /node_modules/],
},
},
},
},
],
autoCompileOpts: {
autoCompile: true,
tsNodeOpts: {
project: './tsconfig.json',
transpileOnly: true,
},
},
specs: ['src/__tests__/**/*.ts', 'src/**/*.test.ts'],
exclude: [
'src/__tests__/utils/**/*.ts',
/**
* Exclude tests of legacy grpc-web protoc codegen because Vite (used by
* wdio) does not support loading of non-ESM modules.
*
* We still test it in Node.js environment.
*/
'src/__tests__/grpc-web.ts',
],
user: useBrowserstack ? BROWSERSTACK_USERNAME : undefined,
key: useBrowserstack ? BROWSERSTACK_KEY : undefined,
bail: 1,
maxInstances: 1,
services: compact([
useBrowserstack && [
'browserstack',
{
browserstackLocal: true,
testObservability: true,
testObservabilityOptions: {
projectName: 'nice-grpc-web',
},
opts: {
localIdentifier: randomUUID(),
},
},
],
]),
capabilities: [
{
browserName: BROWSER_NAME ?? 'chrome',
acceptInsecureCerts: true,
'bstack:options': {
local: true,
disableCorsRestrictions: true,
idleTimeout: 300,
// wsLocalSupport: true,
// networkLogs: true,
browserVersion: BROWSERSTACK_BROWSER_VERSION,
os: BROWSERSTACK_OS,
osVersion: BROWSERSTACK_OS_VERSION,
},
},
],
logLevel: 'info',
framework: 'mocha',
mochaOpts: {
ui: 'bdd',
retries: 2,
timeout: 300_000,
},
reporters: ['spec'],
async onPrepare(config) {
let hostname: string;
let certPath: string;
let keyPath: string;
if (useBrowserstack) {
hostname = 'nice-grpc-web-tests.deeplay.io';
certPath = path.resolve(__dirname, './test-server/cert/tls.crt');
keyPath = path.resolve(__dirname, './test-server/cert/tls.key');
} else {
hostname = '127.0.0.1';
certPath = path.resolve(__dirname, './test-server/cert/self-signed.crt');
keyPath = path.resolve(__dirname, './test-server/cert/self-signed.key');
const cert = selfsigned.generate(
[{name: 'commonName', value: hostname}],
{
keySize: 2048,
},
);
fs.writeFileSync(certPath, cert.cert);
fs.writeFileSync(keyPath, cert.private);
process.on('beforeExit', () => {
fs.unlinkSync(certPath);
fs.unlinkSync(keyPath);
});
}
mockServer = startMockServer({
certPath,
keyPath,
enableDebugLogs:
config.logLevel === 'debug' || config.logLevel === 'trace',
});
},
onComplete() {
mockServer?.close();
},
};
function compact<T>(array: Array<T | null | undefined | false>): T[] {
return array.filter((value): value is T => !!value);
}