-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathworld.ts
64 lines (50 loc) · 1.91 KB
/
world.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
import { setWorldConstructor, IWorldOptions } from '@cucumber/cucumber'
import * as utils from '../../../shared/support/utils'
import { ClonedRepository } from '../../../shared/classes/repository'
import { BundleServerWorldBase, BundleServerParameters } from '../../../shared/support/world'
export enum User {
Me = 1,
Another,
}
export class EndToEndBundleServerWorld extends BundleServerWorldBase {
// Users
repoMap: Map<User, ClonedRepository>
constructor(options: IWorldOptions<BundleServerParameters>) {
super(options)
this.repoMap = new Map<User, ClonedRepository>()
}
cloneRepositoryFor(user: User, bundleUri?: string): void {
if (!this.remote) {
throw new Error("Remote repository is not initialized")
}
const repoRoot = `${this.trashDirectory}/${User[user]}`
this.repoMap.set(user, new ClonedRepository(this.remote, repoRoot, bundleUri))
}
getRepo(user: User): ClonedRepository {
const repo = this.repoMap.get(user)
if (!repo) {
throw new Error("Cloned repository has not been initialized")
}
return repo
}
getRepoAtBranch(user: User, branch: string): ClonedRepository {
if (this.remote && !this.remote.isLocal) {
throw new Error("Remote is not initialized or does not allow pushes")
}
if (!this.repoMap.has(user)) {
this.cloneRepositoryFor(user)
utils.assertStatus(0, this.getRepo(user).cloneResult)
}
const clonedRepo = this.getRepo(user)
const result = clonedRepo.runGit("rev-list", "--all", "-n", "1")
if (result.stdout.toString().trim() == "") {
// Repo is empty, so make sure we're on the right branch
utils.assertStatus(0, clonedRepo.runGit("branch", "-m", branch))
} else {
utils.assertStatus(0, clonedRepo.runGit("switch", branch))
utils.assertStatus(0, clonedRepo.runGit("pull", "origin", branch))
}
return clonedRepo
}
}
setWorldConstructor(EndToEndBundleServerWorld)