-
Notifications
You must be signed in to change notification settings - Fork 3
/
e2e.ts
62 lines (48 loc) · 1.24 KB
/
e2e.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
import { ServiceContext } from '@vtex/api'
import parse = require('co-body')
export async function onSpecComplete(ctx: ServiceContext, next: () => Promise<any>) {
const {
vtex: {
logger,
route: {
params: { spec },
},
},
} = ctx
console.log('EVIDENCE ID:', ctx.headers['x-vtex-evidence'])
const specReport = await parse.json(ctx.req) as SpecReport
const testsByState: { [state: string]: string[] } = {}
if (specReport.report?.tests) {
specReport.report.tests.forEach(t => {
testsByState[t.state] = (testsByState[t.state] ?? []).concat(t.title.join(''))
})
}
logger.info({
spec,
state: specReport.state,
testsByState,
})
ctx.status = 200
await next()
}
export async function onTestComplete(ctx: ServiceContext, next: () => Promise<any>) {
const {
vtex: {
logger,
route: {
params: { testId },
},
},
} = ctx
const app = await parse.json(ctx.req) as AppReport
const specsByState: { [state: string]: string[] } = {}
Object.entries(app).forEach(([spec, report]) => {
specsByState[report.state] = (specsByState[report.state] ?? []).concat(spec)
})
logger.info({
specsByState,
testId,
})
ctx.status = 200
await next()
}