/
wait.ts
78 lines (73 loc) · 2.3 KB
/
wait.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { Command, Args, Flags } from "@oclif/core";
import emoji from "node-emoji";
import { getWaitIntervalSecond } from "../../../autify/getWaitIntervalSecond";
import { getMobileClient } from "../../../autify/mobile/getMobileClient";
import { getMobileTestResultUrl } from "../../../autify/mobile/getTestResultUrl";
import { parseTestResultUrl } from "../../../autify/mobile/parseTestResultUrl";
import { waitTestResult } from "../../../autify/mobile/waitTestResult";
export default class MobileTestWait extends Command {
static description = "Wait a test result until it finishes.";
static examples = [
"<%= config.bin %> <%= command.id %> https://mobile-app.autify.com/projects/AAA/results/BBB",
];
static flags = {
timeout: Flags.integer({
char: "t",
description:
"Timeout seconds when waiting for the finish of the test execution.",
default: 300,
}),
verbose: Flags.boolean({
char: "v",
description: "Verbose output",
default: false,
}),
};
static args = {
"test-result-url": Args.string({
description:
"Test result URL e.g. https://mobile-app.autify.com/projects/<ID>/results/<ID>",
required: true,
}),
};
public async run(): Promise<void> {
const { args, flags } = await this.parse(MobileTestWait);
const { configDir, userAgent } = this.config;
const waitIntervalSecond = getWaitIntervalSecond(configDir);
const client = getMobileClient(configDir, userAgent);
const { workspaceId, resultId } = parseTestResultUrl(
args["test-result-url"]
);
const testResultUrl = getMobileTestResultUrl(
configDir,
workspaceId,
resultId
);
this.log(
`${emoji.get("clock1")} Waiting for the test result: ${testResultUrl}`
);
const { isPassed, data } = await waitTestResult(
client,
workspaceId,
resultId,
{
timeoutSecond: flags.timeout,
verbose: flags.verbose,
intervalSecond: waitIntervalSecond,
}
);
if (isPassed) {
this.log(
`${emoji.get("white_check_mark")} Test passed!: ${testResultUrl}`
);
this.exit();
} else {
this.log(
`${emoji.get(
"x"
)} Test didn't pass. See ${testResultUrl}: ${JSON.stringify(data)}`
);
this.exit(1);
}
}
}