@mablhq/mabl-cli 1.31.3 → 1.31.11

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 CHANGED
@@ -1,6 +1,30 @@
1
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
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.Globals = void 0;
27
+ const os = __importStar(require("os"));
4
28
  class Globals {
5
29
  static getFindOverallTimeoutMs() {
6
30
  return Globals.findOverallTimeoutMs;
@@ -14,7 +38,28 @@ class Globals {
14
38
  static setPlaywrightInteractionWarningMs(timeout) {
15
39
  Globals.playwrightInteractionWarningMs = timeout;
16
40
  }
41
+ static getUploadDirectory() {
42
+ return Globals.uploadDirectory;
43
+ }
44
+ static setUploadDirectory(dir) {
45
+ Globals.uploadDirectory = dir;
46
+ }
47
+ static getUploadDirectoryPrefix() {
48
+ return Globals.uploadDirectoryPrefix;
49
+ }
50
+ static setUploadDirectoryPrefix(prefix) {
51
+ Globals.uploadDirectoryPrefix = prefix;
52
+ }
53
+ static getTestMaxAgeMs() {
54
+ return Globals.testMaxAgeMs;
55
+ }
56
+ static setTestMaxAgeMs(age) {
57
+ Globals.testMaxAgeMs = age;
58
+ }
17
59
  }
18
60
  exports.Globals = Globals;
19
61
  Globals.findOverallTimeoutMs = 18.5 * 60 * 1000;
20
62
  Globals.playwrightInteractionWarningMs = 30 * 1000;
63
+ Globals.uploadDirectory = os.tmpdir();
64
+ Globals.uploadDirectoryPrefix = `mablTestRunUploads-`;
65
+ Globals.testMaxAgeMs = 1000 * 60 * 60 * 24;
@@ -65,6 +65,8 @@ class BasicApiClient {
65
65
  }
66
66
  config.timeout =
67
67
  (_d = (_b = options.requestTimeoutMillis) !== null && _b !== void 0 ? _b : (_c = options.retryConfig) === null || _c === void 0 ? void 0 : _c.requestTimeoutMillis) !== null && _d !== void 0 ? _d : DEFAULT_RETRYABLE_REQUEST_TIMEOUT_MILLISECONDS;
68
+ config.maxBodyLength = Infinity;
69
+ config.maxContentLength = Infinity;
68
70
  switch (options.authType) {
69
71
  case types_1.AuthType.ApiKey:
70
72
  config.auth = {
@@ -453,7 +453,7 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
453
453
  throw toApiError(`Failed to get Branches`, error);
454
454
  }
455
455
  }
456
- async getUploadFileUrl(fileId) {
456
+ async getFileUploadUrl(fileId) {
457
457
  try {
458
458
  return await this.makeGetRequest(`${this.baseApiUrl}/files/fileUpload/url/${fileId}`);
459
459
  }
@@ -609,6 +609,14 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
609
609
  requestBody.actions = actions;
610
610
  return requestBody;
611
611
  }
612
+ async getTestRunsForPlan(planRunId) {
613
+ try {
614
+ return this.makeGetRequest(`${this.baseApiUrl}/journeyRuns/planRun/${planRunId}`);
615
+ }
616
+ catch (error) {
617
+ throw toApiError(`Failed to retrieve tests for plan`, error);
618
+ }
619
+ }
612
620
  async postPlanRun(organizationId, testId, branchName, browserTypes, appUrl, apiUrl, deploymentId, credentialsId, deploymentIds, basicAuthCredentialsId) {
613
621
  try {
614
622
  const requestBody = this.buildAdHocPlanRunRequestBody(organizationId, testId, browserTypes, branchName, appUrl, apiUrl, deploymentId, credentialsId, deploymentIds, basicAuthCredentialsId);
@@ -26,14 +26,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.toBasicHttpAuthenticationCredentials = exports.generateChromiumPreferencesFile = exports.logTestInfoIfPresent = exports.milliSecondsToSeconds = exports.calculateTotalTimeSeconds = exports.extractTestRunConfig = exports.pullDownTestRunConfig = exports.validateRunCommandWithLabels = exports.validateRunEditCommand = exports.downloadUploadFile = exports.sleep = exports.editTheTest = exports.runTheTest = exports.prepareTrainerForSplitPlayback = exports.createTrainingSession = exports.cleanUpInitialPages = exports.getExtensionBackgroundPageWithCliTool = exports.createBrowserForExecutionEngine = exports.addExecutionEngineLaunchArgs = exports.createBrowser = exports.prepareChromePreferencesDirectory = exports.findChrome = exports.searchForChrome = exports.getFinalUrl = exports.getTempChromePrefDirectory = void 0;
29
+ exports.toBasicHttpAuthenticationCredentials = exports.generateChromiumPreferencesFile = exports.logTestInfoIfPresent = exports.milliSecondsToSeconds = exports.calculateTotalTimeSeconds = exports.extractTestRunConfig = exports.pullDownTestRunConfig = exports.validateRunCommandWithLabels = exports.validateRunEditCommand = exports.cleanupTestResources = exports.sleep = exports.editTheTest = exports.runTheTest = exports.prepareTrainerForSplitPlayback = exports.createTrainingSession = exports.cleanUpInitialPages = exports.getExtensionBackgroundPageWithCliTool = exports.createBrowserForExecutionEngine = exports.addExecutionEngineLaunchArgs = exports.createBrowser = exports.prepareChromePreferencesDirectory = exports.findChrome = exports.searchForChrome = exports.getFinalUrl = exports.getTempChromePrefDirectory = void 0;
30
30
  const async_retry_1 = __importDefault(require("async-retry"));
31
- const axios_1 = __importDefault(require("axios"));
32
31
  const cli_table3_1 = __importDefault(require("cli-table3"));
33
32
  const fs = __importStar(require("fs-extra"));
34
33
  const os = __importStar(require("os"));
35
34
  const path = __importStar(require("path"));
36
- const stream_1 = require("stream");
37
35
  const browserLauncher_1 = require("../../browserLauncher/browserLauncher");
38
36
  const trainingSessionActions_1 = require("../../core/messaging/actions/trainingSessionActions");
39
37
  const logLineMessaging_1 = require("../../core/messaging/logLineMessaging");
@@ -41,12 +39,13 @@ const messaging_1 = require("../../core/messaging/messaging");
41
39
  const env_1 = require("../../env/env");
42
40
  const cliConfigProvider_1 = require("../../providers/cliConfigProvider");
43
41
  const loggingProvider_1 = require("../../providers/logging/loggingProvider");
44
- const httpUtil_1 = require("../../util/httpUtil");
45
42
  const resourceUtil_1 = require("../../util/resourceUtil");
46
43
  const configKeys_1 = require("../config/config_cmds/configKeys");
47
44
  const constants_1 = require("../constants");
48
45
  const mobileEmulationUtil_1 = require("./mobileEmulationUtil");
49
46
  const trainerUtil_1 = require("./tests_cmds/trainerUtil");
47
+ const logUtils_1 = require("../../util/logUtils");
48
+ const fileUploadUtil_1 = require("../../util/fileUploadUtil");
50
49
  const chalk = require('chalk');
51
50
  const chromeFinder = require('chrome-launcher/dist/chrome-finder');
52
51
  const launchUtils = require('chrome-launcher/dist/utils');
@@ -497,46 +496,19 @@ function handleExtensionMessage(message, trainingBrowser) {
497
496
  break;
498
497
  }
499
498
  }
500
- async function downloadUploadFile(fileUploadUrl, fileUpload, downloadDirectory, mablApiClient) {
501
- let client;
502
- if (mablApiClient) {
503
- client = mablApiClient.httpClient;
504
- }
505
- else {
506
- client = axios_1.default.create(await (0, httpUtil_1.currentProxyConfig)());
507
- }
499
+ function cleanupTestResources(testContext) {
508
500
  try {
509
- const finalDirectory = path.normalize(`${downloadDirectory}/${fileUpload.id}`);
510
- try {
511
- fs.mkdirSync(finalDirectory);
512
- }
513
- catch (error) {
514
- if (!error.message.includes('file already exists')) {
515
- throw error;
516
- }
517
- }
518
- const finalPath = path.normalize(`${finalDirectory}/${fileUpload.name}`);
519
- const writer = fs.createWriteStream(finalPath);
520
- const response = await client.get(fileUploadUrl, {
521
- responseType: 'stream',
522
- });
523
- if (response.data.pipe) {
524
- response.data.pipe(writer);
501
+ if (testContext) {
502
+ testContext.getFileUploadDirs().forEach((dir) => (0, fileUploadUtil_1.removeUploadDirs)(dir));
503
+ testContext.clearFileUploadDirs();
525
504
  }
526
- else if (!(response.status >= 400)) {
527
- stream_1.Readable.from(response.data).pipe(writer);
528
- }
529
- return new Promise((resolve, reject) => {
530
- writer.on('finish', () => resolve(finalPath));
531
- writer.on('error', reject);
532
- });
533
505
  }
534
- catch (error) {
535
- loggingProvider_1.logger.error(chalk.red.bold('Error encountered downloading file for File Upload Step replay'));
536
- throw error;
506
+ catch (e) {
507
+ const msg = `WARNING: error received when cleaning up after tests: ${e.message}`;
508
+ (0, logUtils_1.logCliOutput)(loggingProvider_1.LogLevel.Warn, msg);
537
509
  }
538
510
  }
539
- exports.downloadUploadFile = downloadUploadFile;
511
+ exports.cleanupTestResources = cleanupTestResources;
540
512
  function validateRunEditCommand(idArg, testRunIdArg) {
541
513
  if (!idArg && !testRunIdArg) {
542
514
  throw new Error(chalk.red(`Please specify a test ID (--${constants_1.CommandArgId}) or test run ID (--${constants_1.CommandArgTestRunId})\n`));
@@ -180,22 +180,27 @@ async function runInCloud(parsed) {
180
180
  loggingProvider_1.logger.info(chalk.white('---'));
181
181
  const resultUrls = [];
182
182
  for (const test of tests) {
183
- const urls = await executeRunCloudTest(test, browsers, branchName, apiClient, maybeDeploymentId, maybeUrlApp, maybeUrlApi, credentialsId, applicationId, environmentId, basicAuthCredentialsId);
184
- resultUrls.push(...urls);
183
+ const testRuns = await executeRunCloudTest(test, browsers, branchName, apiClient, maybeDeploymentId, maybeUrlApp, maybeUrlApi, credentialsId, applicationId, environmentId, basicAuthCredentialsId);
184
+ testRuns.forEach((testRun) => resultUrls.push(`${env_1.BASE_APP_URL}/workspaces/${testRun.organization_id}/test/journey-runs/${testRun.id}`));
185
185
  loggingProvider_1.logger.info(chalk.white('---'));
186
186
  }
187
187
  let outputUrl;
188
- if (resultUrls.length > 1) {
189
- outputUrl = `${env_1.BASE_APP_URL}/workspaces/${workspaceId}/output`;
190
- loggingProvider_1.logger.info(`See mabl results page to view tests [${chalk.magenta(outputUrl)}]`);
191
- }
192
- else {
188
+ if (resultUrls.length === 1) {
193
189
  outputUrl = resultUrls[0];
194
190
  loggingProvider_1.logger.info(`See mabl test output page for results [${chalk.magenta(outputUrl)}]`);
195
191
  }
192
+ else {
193
+ let filter = '';
194
+ if (labelsInclude.length === 1) {
195
+ filter = `?labels=${labelsInclude[0]}`;
196
+ }
197
+ outputUrl = `${env_1.BASE_APP_URL}/workspaces/${workspaceId}/output${filter}`;
198
+ loggingProvider_1.logger.info(`See mabl results page to view tests [${chalk.magenta(outputUrl)}]`);
199
+ }
196
200
  return outputUrl;
197
201
  }
198
202
  async function executeRunCloudTest(test, browsers, branchName, apiClient, maybeDeploymentId, appUrl, apiUrl, credentialsId, applicationId, environmentId, basicAuthCredentialsId) {
203
+ var _a;
199
204
  const effectiveAppUrl = appUrl !== null && appUrl !== void 0 ? appUrl : test === null || test === void 0 ? void 0 : test.url;
200
205
  const workspaceId = test.organization_id;
201
206
  const testId = test.invariant_id;
@@ -222,9 +227,8 @@ async function executeRunCloudTest(test, browsers, branchName, apiClient, maybeD
222
227
  deploymentIds = foundDeployments.map((deployment) => deployment.id);
223
228
  }
224
229
  const planRun = await apiClient.postPlanRun(workspaceId, testId, branchName, browsers, effectiveAppUrl, apiUrl, maybeDeploymentId, credentialsId, deploymentIds, basicAuthCredentialsId);
225
- return planRun.scripts
226
- ? planRun.scripts.map((script) => `${env_1.BASE_APP_URL}/workspaces/${planRun.organization_id}/test/journey-runs/${script.id}`)
227
- : [];
230
+ const testRunsQueryResult = await apiClient.getTestRunsForPlan(planRun.id);
231
+ return (_a = testRunsQueryResult.test_script_executions) !== null && _a !== void 0 ? _a : [];
228
232
  }
229
233
  async function getJourneysForLabels(workspaceId, branchName, branchChangesOnly, labelsInclude, labelsExclude, limit, prompt, apiClient) {
230
234
  var _a;
@@ -8,6 +8,7 @@ const loggingProvider_1 = require("../../../providers/logging/loggingProvider");
8
8
  const mablApi_1 = require("../../../mablApi");
9
9
  const reporter_1 = require("../../../reporters/reporter");
10
10
  const browserTypes_1 = require("../../browserTypes");
11
+ const execution_1 = require("../../../execution");
11
12
  const chalk = require('chalk');
12
13
  const execution = require('../../../execution/index');
13
14
  exports.command = `run`;
@@ -236,8 +237,16 @@ async function run(parsed) {
236
237
  workspaceId,
237
238
  };
238
239
  loggingProvider_1.logger.info('Warming up test runner...');
239
- const mablTestRunner = await execution.createMablTestRunner(testRunnerConfig);
240
- const results = await mablTestRunner.run();
240
+ const mablTestsRunner = await execution.createMablTestRunner(testRunnerConfig);
241
+ const results = await mablTestsRunner.run();
242
+ if ((mablTestsRunner === null || mablTestsRunner === void 0 ? void 0 : mablTestsRunner.mablTestRunners) !== undefined) {
243
+ mablTestsRunner.mablTestRunners
244
+ .filter((tr) => tr instanceof execution_1.MablTestRunner)
245
+ .forEach((tr) => {
246
+ const testContext = tr.testContext;
247
+ (0, testsUtil_1.cleanupTestResources)(testContext);
248
+ });
249
+ }
241
250
  loggingProvider_1.logger.logNewLine();
242
251
  loggingProvider_1.logger.info(`Test count: ${results.numTotalTests}`);
243
252
  loggingProvider_1.logger.info(`Passed: ${results.numPassedTests}`);