@mablhq/mabl-cli 1.12.33 → 1.12.38

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.
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.BrowserLauncherFactory = void 0;
4
7
  const puppeteerBrowserLauncher_1 = require("./puppeteerBrowserLauncher/puppeteerBrowserLauncher");
@@ -6,6 +9,7 @@ const playwrightBrowserLauncher_1 = require("./playwrightBrowserLauncher/playwri
6
9
  const runnerType_1 = require("./runnerType");
7
10
  const logUtils_1 = require("../util/logUtils");
8
11
  const loggingProvider_1 = require("../providers/logging/loggingProvider");
12
+ const chalk_1 = __importDefault(require("chalk"));
9
13
  class BrowserLauncherFactory {
10
14
  static getRunnerFromEnvironment() {
11
15
  var _a;
@@ -16,10 +20,10 @@ class BrowserLauncherFactory {
16
20
  const runner = runnerFromEnv ? runnerFromEnv : runnerType;
17
21
  loggerFunc = loggerFunc !== null && loggerFunc !== void 0 ? loggerFunc : ((line) => logUtils_1.logCliOutput(loggingProvider_1.LogLevel.Info, line));
18
22
  if (runner === runnerType_1.RunnerType.Playwright) {
19
- loggerFunc('Browser launcher: Playwright');
23
+ loggerFunc(chalk_1.default.cyan(`Browser launcher:`, chalk_1.default.magenta('Playwright')));
20
24
  return new playwrightBrowserLauncher_1.PlaywrightBrowserLauncher();
21
25
  }
22
- loggerFunc('Browser launcher: Puppeteer');
26
+ loggerFunc(chalk_1.default.cyan(`Browser launcher:`, chalk_1.default.magenta('Puppeteer')));
23
27
  return new puppeteerBrowserLauncher_1.PuppeteerBrowserLauncher();
24
28
  }
25
29
  }
@@ -31,6 +31,7 @@ class PlaywrightBrowserLauncher {
31
31
  viewport,
32
32
  acceptDownloads: true,
33
33
  httpCredentials: options.credentials,
34
+ extraHTTPHeaders: options.extraHttpHeaders,
34
35
  isMobile: (_a = options.defaultDeviceDescriptor) === null || _a === void 0 ? void 0 : _a.isMobile,
35
36
  deviceScaleFactor: (_b = options.defaultDeviceDescriptor) === null || _b === void 0 ? void 0 : _b.deviceScaleFactor,
36
37
  hasTouch: (_c = options.defaultDeviceDescriptor) === null || _c === void 0 ? void 0 : _c.hasTouch,
@@ -19,5 +19,8 @@ class PlaywrightHttpResponse {
19
19
  url() {
20
20
  return this.response.url();
21
21
  }
22
+ json() {
23
+ return this.response.json();
24
+ }
22
25
  }
23
26
  exports.PlaywrightHttpResponse = PlaywrightHttpResponse;
@@ -20,5 +20,8 @@ class PuppeteerHttpResponse {
20
20
  request() {
21
21
  return new puppeteerHttpRequest_1.PuppeteerHttpRequest(this.response.request(), this.parentPage);
22
22
  }
23
+ json() {
24
+ return this.response.json();
25
+ }
23
26
  }
24
27
  exports.PuppeteerHttpResponse = PuppeteerHttpResponse;
@@ -134,11 +134,12 @@ async function createBrowserWithAuthedExtension(accessToken, browserWidth, brows
134
134
  }
135
135
  exports.createBrowserWithAuthedExtension = createBrowserWithAuthedExtension;
136
136
  async function launchBrowserInstance(chromePath, launchArgs, userDataDir, headless, credentials, options) {
137
- const { defaultDeviceDescriptor, ignoreDefaultArgs, runnerType, loggerFunc } = options || {};
137
+ const { defaultDeviceDescriptor, extraHttpHeaders, ignoreDefaultArgs, runnerType, loggerFunc, } = options || {};
138
138
  let browser;
139
139
  try {
140
140
  browser = await maybeLaunchBrowser(chromePath, launchArgs, userDataDir, headless, credentials, {
141
141
  defaultDeviceDescriptor,
142
+ extraHttpHeaders,
142
143
  ignoreDefaultArgs,
143
144
  runnerType,
144
145
  loggerFunc,
@@ -161,10 +162,11 @@ async function launchBrowserInstance(chromePath, launchArgs, userDataDir, headle
161
162
  return browser;
162
163
  }
163
164
  function maybeLaunchBrowser(chromePath, launchArgs, userDataDir, headless, credentials, options) {
164
- const { defaultDeviceDescriptor, ignoreDefaultArgs, runnerType, loggerFunc } = options || {};
165
+ const { defaultDeviceDescriptor, extraHttpHeaders, ignoreDefaultArgs, runnerType, loggerFunc, } = options || {};
165
166
  return browserLauncher_1.BrowserLauncherFactory.createRunner(runnerType, loggerFunc).launch({
166
167
  defaultDeviceDescriptor,
167
168
  executablePath: chromePath,
169
+ extraHttpHeaders,
168
170
  headless,
169
171
  args: launchArgs,
170
172
  ignoreDefaultArgs,
@@ -195,7 +197,7 @@ function removeTempBrowserPreferencesDirectory(tempDirPath) {
195
197
  }
196
198
  }
197
199
  async function createBrowser(browserWidth, browserHeight, headless, containerTesting, tempBrowserPreferencesDirectory, options) {
198
- const { credentials, browserPath, disableIsolation, ignoreCertificateErrors, emulationConfig, enableExtensions, runnerType, loggerFunc, } = options || {};
200
+ const { credentials, browserPath, disableIsolation, extraHttpHeaders, ignoreCertificateErrors, emulationConfig, enableExtensions, runnerType, loggerFunc, } = options || {};
199
201
  const chromePath = browserPath !== null && browserPath !== void 0 ? browserPath : findChrome();
200
202
  if (!chromePath.length) {
201
203
  messaging_1.mablEventEmitter.log(chalk.yellow('Could not find a local install of Chrome to use, please ensure you have it installed and try again'));
@@ -220,6 +222,7 @@ async function createBrowser(browserWidth, browserHeight, headless, containerTes
220
222
  }
221
223
  const maybeBrowser = await launchBrowserInstance(chromePath, launchArgs, tempBrowserPreferencesDirectory, headless, credentials, {
222
224
  defaultDeviceDescriptor,
225
+ extraHttpHeaders,
223
226
  ignoreDefaultArgs,
224
227
  runnerType,
225
228
  loggerFunc,
@@ -237,7 +237,7 @@ async function getJourneysForLabels(workspaceId, branchName, branchChangesOnly,
237
237
  organization_id: workspaceId,
238
238
  include_labels: labelsInclude,
239
239
  exclude_labels: labelsExclude,
240
- source_control_tag: branchName,
240
+ branch: branchName,
241
241
  branch_changes_only: branchChangesOnly,
242
242
  });
243
243
  switch (journeys.length) {
@@ -145,20 +145,37 @@ exports.builder = (yargs) => {
145
145
  describe: 'Enable browser extensions on [Chrome]',
146
146
  default: false,
147
147
  type: 'boolean',
148
+ })
149
+ .option(constants_1.CommandArgHttpHeaders, {
150
+ describe: 'Space delimited HTTP headers added to browser requests (e.g. "x-header:foo")',
151
+ type: 'array',
148
152
  })
149
153
  .option(constants_1.CommandArgTestInteractionSpeed, {
150
154
  describe: 'Set the speed that mabl interacts with webpages. Overrides test run settings if specified.',
151
155
  type: 'string',
152
156
  choices: Object.keys(mablApi_1.JourneyParameters.PageLoadWaitEnum).map((pageLoadWait) => pageLoadWait.toLowerCase()),
153
157
  })
154
- .check((argv) => testsUtil_1.validateRunCommandWithLabels(argv[constants_1.CommandArgId], argv[constants_1.CommandArgLabelsInclude], argv[constants_1.CommandArgLabelsExclude], argv[constants_1.CommandArgTestRunId], argv[constants_1.CommandArgFromPlanId], true, argv[constants_1.CommandArgTestFile]));
158
+ .check((argv) => {
159
+ testsUtil_1.validateRunCommandWithLabels(argv[constants_1.CommandArgId], argv[constants_1.CommandArgLabelsInclude], argv[constants_1.CommandArgLabelsExclude], argv[constants_1.CommandArgTestRunId], argv[constants_1.CommandArgFromPlanId], true, argv[constants_1.CommandArgTestFile]);
160
+ const httpHeaders = argv[constants_1.CommandArgHttpHeaders];
161
+ util_1.validateArrayInputs(httpHeaders, 'HTTP headers must be SPACE delimited, e.g. "--http-headers "foo:bar" "baz:qux"');
162
+ argv[constants_1.CommandArgHttpHeaders] = util_1.validateValuePairInputs('HTTP header', httpHeaders);
163
+ return true;
164
+ });
155
165
  };
156
166
  const exitCodeOnError = 1;
157
167
  exports.handler = util_1.failWrapper(run, exitCodeOnError);
158
168
  async function run(parsed) {
159
- var _a, _b;
169
+ var _a, _b, _c;
160
170
  const commandStartTime = Date.now();
161
171
  const workspaceId = (_a = parsed['workspace-id']) !== null && _a !== void 0 ? _a : (_b = cliConfigProvider_1.CliConfigProvider.getWorkspace()) === null || _b === void 0 ? void 0 : _b.id;
172
+ const extraHttpHeaders = {};
173
+ ((_c = parsed['http-headers']) !== null && _c !== void 0 ? _c : []).forEach((header) => {
174
+ const headerParts = header.split(':');
175
+ if (headerParts.length === 2 && headerParts[0] && headerParts[1]) {
176
+ extraHttpHeaders[headerParts[0].toLowerCase()] = headerParts[1];
177
+ }
178
+ });
162
179
  const testRunnerConfig = {
163
180
  _cliCreated: true,
164
181
  branchName: parsed['mabl-branch'],
@@ -174,6 +191,7 @@ async function run(parsed) {
174
191
  ignoreCertificateErrors: parsed[constants_1.CommandArgBrowserIgnoreCertificateErrors],
175
192
  interactionSpeed: parsed[constants_1.CommandArgTestInteractionSpeed],
176
193
  enableExtensions: parsed[constants_1.CommandArgBrowserEnableExtensions],
194
+ extraHttpHeaders,
177
195
  keepBrowserOpen: parsed['keep-browser-open'],
178
196
  labelsExclude: parsed['exclude-labels'],
179
197
  labelsInclude: parsed.labels,