UNPKG

1.32 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const axios_1 = require("axios");
4const path = require("path");
5const constants_1 = require("../services/constants");
6const logger_1 = require("./logger");
7function agentJsFilename() {
8 try {
9 return require.resolve('@percy/agent/dist/public/percy-agent.js');
10 }
11 catch (_a) {
12 return path.resolve(__dirname, '../../dist/public/percy-agent.js');
13 }
14}
15exports.agentJsFilename = agentJsFilename;
16async function isAgentRunning() {
17 return axios_1.default({
18 method: 'get',
19 url: `http://localhost:${constants_1.default.PORT}${constants_1.default.HEALTHCHECK_PATH}`,
20 }).then(() => {
21 return true;
22 }).catch((error) => {
23 return false;
24 });
25}
26exports.isAgentRunning = isAgentRunning;
27async function postSnapshot(body) {
28 const URL = `http://localhost:${constants_1.default.PORT}${constants_1.default.SNAPSHOT_PATH}`;
29 const ONE_HUNDRED_MB_IN_BYTES = 100000000;
30 return axios_1.default({
31 method: 'post',
32 maxContentLength: ONE_HUNDRED_MB_IN_BYTES,
33 url: URL,
34 data: body,
35 }).then(() => {
36 return true;
37 }).catch((error) => {
38 logger_1.logError(error);
39 return false;
40 });
41}
42exports.postSnapshot = postSnapshot;