@mablhq/mabl-cli 1.31.3 → 1.32.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Globals.js +45 -0
- package/api/basicApiClient.js +2 -0
- package/api/mablApiClient.js +9 -1
- package/commands/tests/testsUtil.js +11 -39
- package/commands/tests/tests_cmds/run-cloud.js +14 -10
- package/commands/tests/tests_cmds/run.js +11 -2
- package/core/messaging/logLineMessaging.js +4 -1
- package/execution/index.js +1 -1
- package/package.json +2 -1
- package/util/fileUploadUtil.js +109 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mablhq/mabl-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.32.3",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"description": "The official mabl command line interface tool",
|
|
6
6
|
"main": "index.js",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"postinstall": "node ./util/postInstallMessage.js"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
+
"@mablhq/newman-reporter-mabl-console": "0.1.0",
|
|
28
29
|
"@playwright/test": "1.25.1",
|
|
29
30
|
"@types/fs-extra": "8.1.1",
|
|
30
31
|
"@types/serve-handler": "6.1.0",
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.removeUploadDirs = exports.cleanupOldFiles = exports.downloadFileUpload = void 0;
|
|
30
|
+
const axios_1 = __importDefault(require("axios"));
|
|
31
|
+
const httpUtil_1 = require("./httpUtil");
|
|
32
|
+
const path_1 = __importDefault(require("path"));
|
|
33
|
+
const fs = __importStar(require("fs-extra"));
|
|
34
|
+
const stream_1 = require("stream");
|
|
35
|
+
const loggingProvider_1 = require("../providers/logging/loggingProvider");
|
|
36
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
37
|
+
const Globals_1 = require("../Globals");
|
|
38
|
+
const logUtils_1 = require("./logUtils");
|
|
39
|
+
async function downloadFileUpload(fileUploadUrl, fileUpload, downloadDirectory, mablApiClient) {
|
|
40
|
+
let client;
|
|
41
|
+
if (mablApiClient) {
|
|
42
|
+
client = mablApiClient.httpClient;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
client = axios_1.default.create(await (0, httpUtil_1.currentProxyConfig)());
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const finalDirectory = path_1.default.normalize(`${downloadDirectory}/${fileUpload.id}`);
|
|
49
|
+
try {
|
|
50
|
+
fs.mkdirSync(finalDirectory);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (!error.message.includes('file already exists')) {
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const finalPath = path_1.default.normalize(`${finalDirectory}/${fileUpload.name}`);
|
|
58
|
+
const writer = fs.createWriteStream(finalPath);
|
|
59
|
+
const response = await client.get(fileUploadUrl, {
|
|
60
|
+
responseType: 'stream',
|
|
61
|
+
});
|
|
62
|
+
if (response.data.pipe) {
|
|
63
|
+
response.data.pipe(writer);
|
|
64
|
+
}
|
|
65
|
+
else if (!(response.status >= 400)) {
|
|
66
|
+
stream_1.Readable.from(response.data).pipe(writer);
|
|
67
|
+
}
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
writer.on('finish', () => resolve(finalPath));
|
|
70
|
+
writer.on('error', reject);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
loggingProvider_1.logger.error(chalk_1.default.red.bold('Error encountered downloading file for File Upload Step replay'));
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.downloadFileUpload = downloadFileUpload;
|
|
79
|
+
function cleanupOldFiles(ageInMs) {
|
|
80
|
+
try {
|
|
81
|
+
const dir = Globals_1.Globals.getUploadDirectory();
|
|
82
|
+
const prefix = Globals_1.Globals.getUploadDirectoryPrefix();
|
|
83
|
+
fs.readdirSync(dir)
|
|
84
|
+
.filter((file) => file.startsWith(prefix) && uploadDirTooOld(file, ageInMs))
|
|
85
|
+
.forEach((file) => fs.rmSync(`${dir}/${file}`, { recursive: true, force: true }));
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
const msg = `WARNING: error received when cleaning up old files from a previous test`;
|
|
89
|
+
(0, logUtils_1.logCliOutput)(loggingProvider_1.LogLevel.Warn, msg);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.cleanupOldFiles = cleanupOldFiles;
|
|
93
|
+
function uploadDirTooOld(dirFullPath, ageInMs) {
|
|
94
|
+
const now = Date.now();
|
|
95
|
+
const parts = dirFullPath.split('-');
|
|
96
|
+
return (parts.length === 3 &&
|
|
97
|
+
!Number.isNaN(parseInt(parts[1])) &&
|
|
98
|
+
(ageInMs === 0 || now - parseInt(parts[1]) > ageInMs));
|
|
99
|
+
}
|
|
100
|
+
function removeUploadDirs(dirFullPath) {
|
|
101
|
+
const MAX_RETRIES = 5;
|
|
102
|
+
const rmOpts = {
|
|
103
|
+
recursive: true,
|
|
104
|
+
maxRetries: MAX_RETRIES,
|
|
105
|
+
force: true,
|
|
106
|
+
};
|
|
107
|
+
fs.rmSync(dirFullPath, rmOpts);
|
|
108
|
+
}
|
|
109
|
+
exports.removeUploadDirs = removeUploadDirs;
|