-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplugin.js
59 lines (51 loc) · 1.47 KB
/
plugin.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
import bufferToDataUrl from "buffer-to-data-url";
const http = require("https");
let apiKey = null;
module.exports = {
configure: function (key) {
apiKey = key;
},
goodlooks: async function (page, assertion) {
let screenshot = await page.screenshot({ encoding: "base64" });
// const url = "http://localhost:3005/v1/lgtm";
const url = "https://lgtm-main-80a621c.d2.zuplo.dev/v1/lgtm";
const options = {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
screenshot: bufferToDataUrl("image/png", screenshot),
assertion,
}),
};
let result = await fetch(url, options);
let json;
try {
json = await result.json();
} catch (e) {
console.log(result);
throw "API Error. Please verify your API key and account https://lgtm-main-80a621c.d2.zuplo.dev/docs/routes/~pricinghttps://lgtm-main-80a621c.d2.zuplo.dev/docs/routes/~pricing.";
}
if (json.indexOf("PASS") > -1) {
let message = `GoodLooks.ai ${json}`;
console.log(message);
return {
pass: true,
message: () => `GoodLooks.ai ${json}`,
name: "GoodLooks.ai",
expected: true,
actual: true,
};
} else {
return {
pass: false,
message: () => `GoodLooks.ai ${json}`,
name: "GoodLooks.ai",
expected: true,
actual: false,
};
}
},
};