/
ava.config.cjs
70 lines (62 loc) · 1.8 KB
/
ava.config.cjs
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
/* eslint-disable no-console */
const runSerialTestCases = process.argv.includes('--serial') || process.argv.includes('-s')
if (runSerialTestCases) {
startServer()
}
module.exports = {
extensions: ['ts', 'tsx'],
require: ['./tools/ava.setup'],
environmentVariables: {
TS_NODE_PROJECT: './tsconfigs/tsconfig.cjs.json',
NODE_ENV: 'test',
PERFSEE_SERVER_PORT: '3001',
MYSQL_DB: 'perfsee_testing',
},
timeout: '300s',
files: runSerialTestCases
? ['packages/**/*.spec.serial.{ts,tsx}', 'packages/**/*.spec.e2e.{ts,tsx}']
: ['packages/**/*.spec.{ts,tsx}'],
}
function startServer() {
const { execSync, fork } = require('child_process')
const path = require('path')
const MYSQL_DB = 'perfsee_testing'
console.info('initializing testing database...')
execSync(`yarn typeorm migration:run && yarn typeorm query "SET GLOBAL FOREIGN_KEY_CHECKS = 0;"`, {
stdio: 'inherit',
env: {
...process.env,
MYSQL_DB,
},
})
const server = fork(`${path.resolve(__dirname, 'tools/e2e-server.entry.js')}`, {
stdio: 'inherit',
env: {
...process.env,
TS_NODE_PROJECT: './tsconfigs/tsconfig.cjs.json',
NODE_ENV: 'test',
PERFSEE_SERVER_PORT: 3001,
MYSQL_DB,
},
})
server.unref()
server.channel.unref()
process.on('beforeExit', () => {
// `server.kill()` will prevent v8 from generate coverage data
// replace it with AbortController after switching to node@16
server.send('exit')
})
// wait on server ready
console.log('waiting for e2e server ready')
try {
execSync('wait-on tcp:3001', {
shell: true,
timeout: 1000 * 60 /* 30s */,
})
console.log('e2e server ready, start testing')
} catch (e) {
console.error('start e2e server timeout, exiting', e)
server.kill()
process.exit(1)
}
}