-
Notifications
You must be signed in to change notification settings - Fork 840
/
suite.js
73 lines (57 loc) · 1.94 KB
/
suite.js
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
const Fly = require('./fly');
const Web = require('./web');
const { v4: uuidv4 } = require('uuid');
// silence warning caused by starting many puppeteer
process.setMaxListeners(Infinity);
class Suite {
constructor() {
this.url = process.env.ATC_URL || 'http://localhost:8080';
this.adminUsername = process.env.ATC_ADMIN_USERNAME || 'test';
this.adminPassword = process.env.ATC_ADMIN_PASSWORD || 'test';
this.guestUsername = process.env.ATC_GUEST_USERNAME || 'guest';
this.guestPassword = process.env.ATC_GUEST_PASSWORD || 'guest';
this.teamName = `watsjs-team-${uuidv4()}`;
this.guestTeamName = `watsjs-non-main-team-${uuidv4()}`;
this.teams = [];
this.fly = new Fly(this.url, this.adminUsername, this.adminPassword, this.teamName);
this.web = new Web(this.url, this.adminUsername, this.adminPassword);
}
async init(t) {
await this.newTeam(this.adminUsername, this.teamName);
await this.newTeam(this.guestUsername, this.guestTeamName);
await this.fly.init();
await this.web.init();
await this.web.login(t);
this.succeeded = false;
}
async newTeam(username = this.adminUsername, teamName) {
if (!teamName) {
teamName = `watsjs-team-${uuidv4()}`;
}
let fly = await Fly.build(this.url, this.adminUsername, this.adminPassword, 'main');
await fly.newTeam(teamName, username);
this.teams.push(teamName);
return teamName;
}
async destroyTeams() {
let fly = await Fly.build(this.url, this.adminUsername, this.adminPassword, 'main');
var team;
while (team = this.teams.pop()) {
await fly.destroyTeam(team);
}
}
passed(t) {
this.succeeded = true;
}
async finish(t) {
if (this.web.page && !this.succeeded) {
await this.web.page.screenshot({path: 'failure.png'});
}
if (this.web.browser) {
await this.web.browser.close();
}
await this.destroyTeams();
await this.fly.cleanup();
}
}
module.exports = Suite;