-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathtest-runner.ts
More file actions
111 lines (105 loc) · 3.77 KB
/
test-runner.ts
File metadata and controls
111 lines (105 loc) · 3.77 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
import * as uuid from 'uuid'
import { testSessions } from '../rest/api'
import AbstractCheckRunner, { RunLocation, SequenceId } from './abstract-check-runner'
import { GitInformation } from './util'
import { Check } from '../constructs/check'
import { RetryStrategy, SharedFile } from '../constructs'
import { ProjectBundle, ResourceDataBundle } from '../constructs/project-bundle'
import { pullSnapshots } from '../services/snapshot-service'
import { PlaywrightCheckBundle } from '../constructs/playwright-check-bundle'
export default class TestRunner extends AbstractCheckRunner {
projectBundle: ProjectBundle
checkBundles: ResourceDataBundle<Check>[]
sharedFiles: SharedFile[]
location: RunLocation
shouldRecord: boolean
repoInfo: GitInformation | null
environment: string | null
updateSnapshots: boolean
baseDirectory: string
testRetryStrategy: RetryStrategy | null
streamLogs?: boolean
constructor (
accountId: string,
projectBundle: ProjectBundle,
checkBundles: ResourceDataBundle<Check>[],
sharedFiles: SharedFile[],
location: RunLocation,
timeout: number,
verbose: boolean,
shouldRecord: boolean,
repoInfo: GitInformation | null,
environment: string | null,
updateSnapshots: boolean,
baseDirectory: string,
testRetryStrategy: RetryStrategy | null,
streamLogs?: boolean,
) {
super(accountId, timeout, verbose)
this.projectBundle = projectBundle
this.checkBundles = checkBundles
this.sharedFiles = sharedFiles
this.location = location
this.shouldRecord = shouldRecord
this.repoInfo = repoInfo
this.environment = environment
this.updateSnapshots = updateSnapshots
this.baseDirectory = baseDirectory
this.testRetryStrategy = testRetryStrategy
this.streamLogs = streamLogs ?? false
}
async scheduleChecks (
checkRunSuiteId: string,
): Promise<{
testSessionId?: string,
checks: Array<{ check: any, sequenceId: SequenceId }>,
}> {
const checkRunJobs = this.checkBundles.map(({ construct: check, bundle }) => {
// Playwright checks lazy load groups so they're only present in the
// bundle. This is a hack but for now it works.
const groupId = bundle instanceof PlaywrightCheckBundle
? bundle.groupId
: check.groupId
return {
...bundle.synthesize(),
testRetryStrategy: this.testRetryStrategy,
group: groupId ? this.projectBundle.data['check-group'][groupId.ref].bundle.synthesize() : undefined,
groupId: undefined,
sourceInfo: {
checkRunSuiteId,
checkRunId: uuid.v4(),
updateSnapshots: this.updateSnapshots,
},
logicalId: check.logicalId,
filePath: check.getSourceFile(),
}
})
try {
if (!checkRunJobs.length) {
throw new Error('Unable to find checks to run.')
}
const { data } = await testSessions.run({
name: this.projectBundle.project.name,
checkRunJobs,
project: { logicalId: this.projectBundle.project.logicalId },
sharedFiles: this.sharedFiles,
runLocation: this.location,
repoInfo: this.repoInfo,
environment: this.environment,
shouldRecord: this.shouldRecord,
streamLogs: this.streamLogs,
})
const { testSessionId, sequenceIds } = data
const checks = this.checkBundles.map(({ construct: check }) => ({ check, sequenceId: sequenceIds?.[check.logicalId] }))
return { testSessionId, checks }
} catch (err: any) {
throw new Error(err.response?.data?.message ?? err.response?.data?.error ?? err.message)
}
}
async processCheckResult (result: any) {
await super.processCheckResult(result)
if (this.updateSnapshots) {
await pullSnapshots(this.baseDirectory, result.assets?.snapshots)
}
}
}