@mablhq/mabl-cli 1.22.1 → 1.23.5
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/browserLauncher/playwrightBrowserLauncher/playwrightDom.js +24 -10
- package/commands/tests/testsUtil.js +25 -64
- package/commands/tests/tests_cmds/run.js +6 -6
- package/commands/tests/tests_cmds/trainerUtil.js +12 -0
- package/execution/index.js +1 -1
- package/execution/index.js.LICENSE.txt +0 -27
- package/mablApi/index.js +1 -1
- package/mablscript/steps/SyntheticStep.js +2 -2
- package/mablscriptFind/index.js +1 -1
- package/package.json +1 -1
- package/resources/mablFind.js +1 -1
- package/commands/tests/executionUtil.js +0 -36
- package/commands/tests/tests_cmds/run-alpha.js +0 -129
- package/commands/tests/tests_cmds/run-legacy.js +0 -109
- package/commands/tests/tests_cmds/trainer.js +0 -5
- package/commands/tests/tests_cmds/trainer_cmds/install.js +0 -14
- package/commands/tests/tests_cmds/trainer_cmds/trainerUtil.js +0 -169
- package/commands/tests/tests_cmds/trainer_cmds/update.js +0 -27
- package/commands/tests/tests_cmds/trainer_cmds/version.js +0 -22
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.runTheTestInNewWindow = exports.DEFAULT_BROWSER_HEIGHT = exports.DEFAULT_BROWSER_WIDTH = void 0;
|
|
7
|
-
const authenticationProvider_1 = require("../../providers/authenticationProvider");
|
|
8
|
-
const testsUtil_1 = require("./testsUtil");
|
|
9
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
-
const loggingProvider_1 = require("../../providers/logging/loggingProvider");
|
|
11
|
-
const mablApiClientFactory_1 = require("../../api/mablApiClientFactory");
|
|
12
|
-
exports.DEFAULT_BROWSER_WIDTH = 1366;
|
|
13
|
-
exports.DEFAULT_BROWSER_HEIGHT = 768;
|
|
14
|
-
async function runTheTestInNewWindow(test, flows, branchName, url, credentialsId, environment, width, height) {
|
|
15
|
-
const authConfig = await new authenticationProvider_1.AuthenticationProvider().getAuthConfigWithAutoRenew();
|
|
16
|
-
const browserPreferences = (0, testsUtil_1.generateChromiumPreferencesFile)();
|
|
17
|
-
const browserPreferencesDirectory = await (0, testsUtil_1.prepareChromePreferencesDirectory)(browserPreferences);
|
|
18
|
-
const apiClient = await mablApiClientFactory_1.MablApiClientFactory.createApiClient();
|
|
19
|
-
if (!test.organization_id) {
|
|
20
|
-
throw new Error('The test workspace ID is required, but it is not set.');
|
|
21
|
-
}
|
|
22
|
-
const featureFlags = await apiClient.getEffectiveFeaturesByWorkspaceId(test.organization_id);
|
|
23
|
-
const runnerType = featureFlags.getRunnerType();
|
|
24
|
-
const trainingBrowser = await (0, testsUtil_1.createBrowserWithAuthedExtension)(authConfig.accessToken, width || exports.DEFAULT_BROWSER_WIDTH, height || exports.DEFAULT_BROWSER_HEIGHT, browserPreferencesDirectory, {
|
|
25
|
-
runnerType,
|
|
26
|
-
});
|
|
27
|
-
const backgroundPage = await (0, testsUtil_1.getExtensionBackgroundPageWithCliTool)(trainingBrowser);
|
|
28
|
-
process.once('SIGINT', function () {
|
|
29
|
-
loggingProvider_1.logger.info(chalk_1.default.yellowBright('Closing local run of test'));
|
|
30
|
-
trainingBrowser
|
|
31
|
-
.close()
|
|
32
|
-
.catch((error) => loggingProvider_1.logger.info('Error shutting down browser on CTRL + C: ' + error));
|
|
33
|
-
});
|
|
34
|
-
await (0, testsUtil_1.runTheTest)(trainingBrowser, backgroundPage, test, flows, branchName, url, credentialsId, environment);
|
|
35
|
-
}
|
|
36
|
-
exports.runTheTestInNewWindow = runTheTestInNewWindow;
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const util_1 = require("../../commandUtil/util");
|
|
4
|
-
const testsUtil_1 = require("../testsUtil");
|
|
5
|
-
const constants_1 = require("../../constants");
|
|
6
|
-
const run_1 = require("./run");
|
|
7
|
-
const loggingProvider_1 = require("../../../providers/logging/loggingProvider");
|
|
8
|
-
const chalk = require('chalk');
|
|
9
|
-
exports.command = `run-alpha`;
|
|
10
|
-
exports.describe =
|
|
11
|
-
"[DEPRECATED] Run a test locally with optional headless support\nCommand will be removed in a future release. Please migrate to 'run' for identical behavior";
|
|
12
|
-
exports.builder = (yargs) => {
|
|
13
|
-
yargs
|
|
14
|
-
.example('$0 tests run-alpha --id <id> --headless', 'run test locally by id in headless mode')
|
|
15
|
-
.example('$0 tests run-alpha --run-id <test-run-id>', 'run a test locally using the test configuration from a cloud run')
|
|
16
|
-
.option(constants_1.CommandArgId, {
|
|
17
|
-
describe: 'The id of the test to run',
|
|
18
|
-
type: 'string',
|
|
19
|
-
})
|
|
20
|
-
.option(constants_1.CommandArgTestFile, {
|
|
21
|
-
describe: 'the source file of the test to run',
|
|
22
|
-
type: 'string',
|
|
23
|
-
hidden: true,
|
|
24
|
-
})
|
|
25
|
-
.option(constants_1.CommandArgTestRunId, {
|
|
26
|
-
describe: 'The id of the test run to pull config from',
|
|
27
|
-
type: 'string',
|
|
28
|
-
})
|
|
29
|
-
.option(constants_1.CommandArgFromPlanId, {
|
|
30
|
-
describe: 'The plan id to get a list of tests from. The environment id and the credentials id will be used as well unless supplied',
|
|
31
|
-
type: 'string',
|
|
32
|
-
})
|
|
33
|
-
.option(constants_1.CommandArgMablBranch, {
|
|
34
|
-
describe: 'Mabl branch to run test against',
|
|
35
|
-
nargs: 1,
|
|
36
|
-
type: 'string',
|
|
37
|
-
})
|
|
38
|
-
.option(constants_1.CommandArgMablBranchChangesOnly, {
|
|
39
|
-
describe: 'Only execute tests changed on specified mabl branch',
|
|
40
|
-
type: 'boolean',
|
|
41
|
-
default: false,
|
|
42
|
-
})
|
|
43
|
-
.implies(constants_1.CommandArgMablBranchChangesOnly, constants_1.CommandArgMablBranch)
|
|
44
|
-
.option(constants_1.CommandArgLabelsInclude, {
|
|
45
|
-
describe: 'Space delimited test labels. Run tests that match any label.',
|
|
46
|
-
type: 'array',
|
|
47
|
-
conflicts: [constants_1.CommandArgId],
|
|
48
|
-
})
|
|
49
|
-
.option(constants_1.CommandArgLabelsExclude, {
|
|
50
|
-
describe: 'Space delimited test labels. Exclude tests that match any label.',
|
|
51
|
-
type: 'array',
|
|
52
|
-
conflicts: [constants_1.CommandArgId],
|
|
53
|
-
})
|
|
54
|
-
.option(constants_1.CommandArgWorkspaceId, {
|
|
55
|
-
alias: constants_1.CommandArgAliases.WorkspaceId,
|
|
56
|
-
describe: 'Workspace to run against',
|
|
57
|
-
nargs: 1,
|
|
58
|
-
type: 'string',
|
|
59
|
-
})
|
|
60
|
-
.option(constants_1.CommandArgEnableLink, {
|
|
61
|
-
describe: 'Enable usage of mabl Link for test run. For local CLI runs link agent label set in the environment is ignored.',
|
|
62
|
-
type: 'boolean',
|
|
63
|
-
hidden: true,
|
|
64
|
-
})
|
|
65
|
-
.option(constants_1.CommandArgEnvironmentId, {
|
|
66
|
-
alias: constants_1.CommandArgAliases.EnvironmentId,
|
|
67
|
-
describe: 'Mabl environment to run under. Specify to ensure the test runs with environment variables and the latest find information.',
|
|
68
|
-
nargs: 1,
|
|
69
|
-
type: 'string',
|
|
70
|
-
})
|
|
71
|
-
.option('width', {
|
|
72
|
-
describe: 'Set the browser width in pixels',
|
|
73
|
-
default: 1366,
|
|
74
|
-
nargs: 1,
|
|
75
|
-
type: 'number',
|
|
76
|
-
})
|
|
77
|
-
.option('height', {
|
|
78
|
-
describe: 'Set the browser height in pixels',
|
|
79
|
-
default: 768,
|
|
80
|
-
nargs: 1,
|
|
81
|
-
type: 'number',
|
|
82
|
-
})
|
|
83
|
-
.option(constants_1.CommandArgUrl, {
|
|
84
|
-
alias: constants_1.CommandArgAliases.Url,
|
|
85
|
-
describe: 'URL to run the mabl test against',
|
|
86
|
-
nargs: 1,
|
|
87
|
-
type: 'string',
|
|
88
|
-
})
|
|
89
|
-
.option(constants_1.CommandArgCredentials, {
|
|
90
|
-
alias: constants_1.CommandArgAliases.Credentials,
|
|
91
|
-
describe: 'Credentials ID to run the test with',
|
|
92
|
-
nargs: 1,
|
|
93
|
-
type: 'string',
|
|
94
|
-
})
|
|
95
|
-
.option('headless', {
|
|
96
|
-
describe: 'Should the test run headless or not',
|
|
97
|
-
default: false,
|
|
98
|
-
type: 'boolean',
|
|
99
|
-
})
|
|
100
|
-
.option('highlights', {
|
|
101
|
-
describe: 'Highlight elements before interacting with them. Highlighting introduces a small delay for each step.',
|
|
102
|
-
default: false,
|
|
103
|
-
type: 'boolean',
|
|
104
|
-
})
|
|
105
|
-
.option('keep-browser-open', {
|
|
106
|
-
describe: 'Prevent the browser from closing at the end of a test.',
|
|
107
|
-
default: false,
|
|
108
|
-
type: 'boolean',
|
|
109
|
-
})
|
|
110
|
-
.option(constants_1.CommandArgBrowserDisableIsolation, {
|
|
111
|
-
hidden: true,
|
|
112
|
-
describe: 'Disable cross origin isolation',
|
|
113
|
-
default: false,
|
|
114
|
-
type: 'boolean',
|
|
115
|
-
})
|
|
116
|
-
.option(constants_1.CommandArgBrowserIgnoreCertificateErrors, {
|
|
117
|
-
hidden: true,
|
|
118
|
-
describe: 'Ignore certificate errors',
|
|
119
|
-
default: false,
|
|
120
|
-
type: 'boolean',
|
|
121
|
-
})
|
|
122
|
-
.check((argv) => (0, 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]));
|
|
123
|
-
};
|
|
124
|
-
const exitCodeOnError = 1;
|
|
125
|
-
exports.handler = (0, util_1.failWrapper)(runAlpha, exitCodeOnError);
|
|
126
|
-
function runAlpha(parsed) {
|
|
127
|
-
loggingProvider_1.logger.info(chalk.bgYellow.black(`DEPRECATION NOTICE: 'run-alpha' moved to 'run'. 'run-alpha' will be removed in a future release`));
|
|
128
|
-
return (0, run_1.run)(parsed);
|
|
129
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const mablApiClientFactory_1 = require("../../../api/mablApiClientFactory");
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const mablApi_1 = require("../../../mablApi");
|
|
9
|
-
const util_1 = require("../../commandUtil/util");
|
|
10
|
-
const testsUtil_1 = require("../testsUtil");
|
|
11
|
-
const executionUtil_1 = require("../executionUtil");
|
|
12
|
-
const branches_1 = require("../../commandUtil/branches");
|
|
13
|
-
const constants_1 = require("../../constants");
|
|
14
|
-
const loggingProvider_1 = require("../../../providers/logging/loggingProvider");
|
|
15
|
-
exports.command = 'run-legacy';
|
|
16
|
-
exports.describe =
|
|
17
|
-
"[DEPRECATED] Run a test locally as the pre v1.0.0 'run' command\nCommand will be removed in a future release. Please migrate to 'run'";
|
|
18
|
-
exports.builder = (yargs) => {
|
|
19
|
-
yargs
|
|
20
|
-
.example('$0 tests run-legacy --id <id>', 'run test locally by id')
|
|
21
|
-
.example('$0 tests run-legacy --run-id <test-run-id>', 'run a test locally using the test configuration from a cloud run')
|
|
22
|
-
.option(constants_1.CommandArgId, {
|
|
23
|
-
describe: 'The id of the test to run',
|
|
24
|
-
type: 'string',
|
|
25
|
-
})
|
|
26
|
-
.option(constants_1.CommandArgTestRunId, {
|
|
27
|
-
describe: 'The id of the test run to pull config from',
|
|
28
|
-
type: 'string',
|
|
29
|
-
})
|
|
30
|
-
.option(constants_1.CommandArgMablBranch, {
|
|
31
|
-
describe: 'Branch to run the mabl test against',
|
|
32
|
-
nargs: 1,
|
|
33
|
-
type: 'string',
|
|
34
|
-
})
|
|
35
|
-
.option(constants_1.CommandArgEnvironmentId, {
|
|
36
|
-
alias: constants_1.CommandArgAliases.EnvironmentId,
|
|
37
|
-
describe: 'Mabl environment to run under. Specify to ensure the test runs with environment variables and the latest find information.',
|
|
38
|
-
nargs: 1,
|
|
39
|
-
type: 'string',
|
|
40
|
-
})
|
|
41
|
-
.option('width', {
|
|
42
|
-
describe: 'Set the browser width in pixels',
|
|
43
|
-
nargs: 1,
|
|
44
|
-
type: 'number',
|
|
45
|
-
})
|
|
46
|
-
.option('height', {
|
|
47
|
-
describe: 'Set the browser height in pixels',
|
|
48
|
-
nargs: 1,
|
|
49
|
-
type: 'number',
|
|
50
|
-
})
|
|
51
|
-
.option(constants_1.CommandArgUrl, {
|
|
52
|
-
alias: constants_1.CommandArgAliases.Url,
|
|
53
|
-
describe: 'URL to run the mabl test against',
|
|
54
|
-
nargs: 1,
|
|
55
|
-
type: 'string',
|
|
56
|
-
})
|
|
57
|
-
.option(constants_1.CommandArgCredentials, {
|
|
58
|
-
alias: constants_1.CommandArgAliases.Credentials,
|
|
59
|
-
describe: 'Credentials ID to run the test with',
|
|
60
|
-
nargs: 1,
|
|
61
|
-
type: 'string',
|
|
62
|
-
})
|
|
63
|
-
.check((argv) => (0, testsUtil_1.validateRunEditCommand)(argv[constants_1.CommandArgId], argv[constants_1.CommandArgTestRunId]));
|
|
64
|
-
};
|
|
65
|
-
exports.handler = (0, util_1.failWrapper)(runLegacy);
|
|
66
|
-
async function runLegacy(parsed) {
|
|
67
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
68
|
-
loggingProvider_1.logger.info(chalk_1.default.bgYellow.black("DEPRECATION NOTICE: 'run-legacy' will be removed in a future release. Please migrate to 'run'"));
|
|
69
|
-
const apiClient = await mablApiClientFactory_1.MablApiClientFactory.createUserApiClient();
|
|
70
|
-
const testRunId = parsed['run-id'];
|
|
71
|
-
let testRunIdConfig = { testId: '', filterHttpRequests: false };
|
|
72
|
-
if (testRunId) {
|
|
73
|
-
testRunIdConfig = await (0, testsUtil_1.pullDownTestRunConfig)(testRunId, apiClient);
|
|
74
|
-
}
|
|
75
|
-
const testId = (_a = parsed.id) !== null && _a !== void 0 ? _a : testRunIdConfig.testId;
|
|
76
|
-
const url = (_b = parsed.url) !== null && _b !== void 0 ? _b : testRunIdConfig.url;
|
|
77
|
-
const credentialsId = (_c = parsed['credentials-id']) !== null && _c !== void 0 ? _c : testRunIdConfig.credentialsId;
|
|
78
|
-
const branchName = (_e = (_d = parsed['mabl-branch']) !== null && _d !== void 0 ? _d : testRunIdConfig.branchName) !== null && _e !== void 0 ? _e : constants_1.DefaultBranchName;
|
|
79
|
-
const environmentId = (_f = parsed[constants_1.CommandArgEnvironmentId]) !== null && _f !== void 0 ? _f : testRunIdConfig.environmentId;
|
|
80
|
-
const test = await apiClient.getJourney(testId, branchName);
|
|
81
|
-
(0, branches_1.printBranchRunningInfo)(branchName);
|
|
82
|
-
(0, branches_1.crossCheckBranchWithTest)(branchName, test);
|
|
83
|
-
let environment;
|
|
84
|
-
if (environmentId) {
|
|
85
|
-
environment = await apiClient.getEnvironment(environmentId, true);
|
|
86
|
-
}
|
|
87
|
-
const flowArray = await (0, util_1.getJourneyFlowArray)(test, apiClient, branchName);
|
|
88
|
-
const finalUrl = (0, testsUtil_1.getFinalUrl)(test, url);
|
|
89
|
-
if (flowArray
|
|
90
|
-
.map((flow) => flow.flow_type === mablApi_1.Flow.FlowTypeEnum.Mablscript)
|
|
91
|
-
.includes(false)) {
|
|
92
|
-
loggingProvider_1.logger.info(chalk_1.default.red('Default mabl tests are not supported for local runs yet including any test with an auto login flow'));
|
|
93
|
-
return 'error';
|
|
94
|
-
}
|
|
95
|
-
loggingProvider_1.logger.info(chalk_1.default.cyan(`Running test: `, chalk_1.default.magenta(`${test.name} - ${test.invariant_id}`)));
|
|
96
|
-
loggingProvider_1.logger.info(chalk_1.default.cyan(`URL: `, chalk_1.default.magenta(finalUrl)));
|
|
97
|
-
loggingProvider_1.logger.info(chalk_1.default.cyan(`Workspace: `, chalk_1.default.magenta((_g = test.organization_id) !== null && _g !== void 0 ? _g : '')));
|
|
98
|
-
if (environmentId) {
|
|
99
|
-
loggingProvider_1.logger.info(chalk_1.default.cyan(`Environment ID: `, chalk_1.default.magenta(environmentId)));
|
|
100
|
-
}
|
|
101
|
-
if (credentialsId) {
|
|
102
|
-
loggingProvider_1.logger.info(chalk_1.default.cyan(`Credentials ID: `, chalk_1.default.magenta(credentialsId)));
|
|
103
|
-
}
|
|
104
|
-
if (test.description) {
|
|
105
|
-
loggingProvider_1.logger.info(chalk_1.default.cyan(`Test description: `, chalk_1.default.magenta(test.description)));
|
|
106
|
-
}
|
|
107
|
-
await (0, executionUtil_1.runTheTestInNewWindow)(test, flowArray, branchName, finalUrl, credentialsId, environment, parsed.width, parsed.height);
|
|
108
|
-
return 'done';
|
|
109
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const update_1 = require("./update");
|
|
4
|
-
const constants_1 = require("../../../constants");
|
|
5
|
-
exports.command = 'install';
|
|
6
|
-
exports.describe = 'Install the mabl Trainer extension for the mabl CLI';
|
|
7
|
-
exports.builder = (yargs) => {
|
|
8
|
-
yargs.option(constants_1.CommandArgTrainerVersion, {
|
|
9
|
-
describe: 'The version to install',
|
|
10
|
-
nargs: 1,
|
|
11
|
-
type: 'string',
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
exports.handler = update_1.updateTrainer;
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.checkForTrainerUpdate = exports.getTrainerVersion = exports.getTrainerId = exports.updateMablTrainer = exports.getMablTrainerExtensionPath = exports.getTrainerZipFile = exports.getTrainerManifestPath = exports.getTrainerUnzippedPath = exports.getTrainerPath = exports.LOCAL_TRAINER_ID = void 0;
|
|
7
|
-
const env_1 = require("../../../../env/env");
|
|
8
|
-
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
9
|
-
const httpUtil_1 = require("../../../../util/httpUtil");
|
|
10
|
-
const messaging_1 = require("../../../../core/messaging/messaging");
|
|
11
|
-
const envPaths = require('env-paths');
|
|
12
|
-
const axios_1 = __importDefault(require("axios"));
|
|
13
|
-
const loggingProvider_1 = require("../../../../providers/logging/loggingProvider");
|
|
14
|
-
const chalk = require('chalk');
|
|
15
|
-
const crypto = require('crypto');
|
|
16
|
-
const fs = require('fs-extra');
|
|
17
|
-
const path = require('path');
|
|
18
|
-
const queryString = require('query-string');
|
|
19
|
-
const DecompressZip = require('decompress-zip');
|
|
20
|
-
const TRAINER_LOCAL_DIR = 'trainer';
|
|
21
|
-
const LOCAL_TRAINER_KEY = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuYOcWMo1tqrDC6lDaPEe+uMcYN/mw6VPJuyyp3P83psslapoHoYALJog/5UN2HbGQA9u5vqOqMS/J3fby2AvtYEUddzorex+1347lijCk9s3EBn0EurFECOdbuKtTxPzlia/2FDFVFVq73qGMPD1/W0JxU8RAEWJKF+n9lnKqWVk456rb/mRZzMLbTOlEXeDB5+ss6Doz/pedDwpKyKE2aqpCcVhXxcVZTo0lapGvp+RtK0rjC9Y6n+Mw7HLZ+lacrUwDK5Zp2mbeBdW/WG1xQvrj1KNSfNjQcWLXCIa9ZtZ1z61dj6KCt49u5eW7dmo6YOTuUayeZn4diwAzSb06QIDAQAB';
|
|
22
|
-
exports.LOCAL_TRAINER_ID = 'jmeffipchlcmnkllcolcbmneknjckcpp';
|
|
23
|
-
function getPaths() {
|
|
24
|
-
return envPaths(env_1.CONF_FILE_PROJECT_NAME);
|
|
25
|
-
}
|
|
26
|
-
function getTrainerPath() {
|
|
27
|
-
let basePath = getPaths().data;
|
|
28
|
-
if (env_1.ENV !== 'prod') {
|
|
29
|
-
basePath = path.normalize(`${basePath}/${env_1.ENV}`);
|
|
30
|
-
}
|
|
31
|
-
return basePath;
|
|
32
|
-
}
|
|
33
|
-
exports.getTrainerPath = getTrainerPath;
|
|
34
|
-
function getTrainerUnzippedPath() {
|
|
35
|
-
return path.normalize(`${getTrainerPath()}/${TRAINER_LOCAL_DIR}`);
|
|
36
|
-
}
|
|
37
|
-
exports.getTrainerUnzippedPath = getTrainerUnzippedPath;
|
|
38
|
-
function getTrainerManifestPath() {
|
|
39
|
-
return path.normalize(`${getTrainerUnzippedPath()}/manifest.json`);
|
|
40
|
-
}
|
|
41
|
-
exports.getTrainerManifestPath = getTrainerManifestPath;
|
|
42
|
-
function getTrainerZipFile() {
|
|
43
|
-
return `${getTrainerUnzippedPath()}.zip`;
|
|
44
|
-
}
|
|
45
|
-
exports.getTrainerZipFile = getTrainerZipFile;
|
|
46
|
-
async function getMablTrainerExtensionPath(version) {
|
|
47
|
-
if (env_1.LOCAL_TRAINER_PATH) {
|
|
48
|
-
messaging_1.mablEventEmitter.log(chalk.black.bgRedBright('[WARNING] developer version of extension in use!'));
|
|
49
|
-
return env_1.LOCAL_TRAINER_PATH;
|
|
50
|
-
}
|
|
51
|
-
if (!trainerExists()) {
|
|
52
|
-
messaging_1.mablEventEmitter.log('Updating the local mabl Trainer...');
|
|
53
|
-
await updateMablTrainer(version);
|
|
54
|
-
messaging_1.mablEventEmitter.log('Update complete!');
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
await checkForTrainerUpdate();
|
|
58
|
-
}
|
|
59
|
-
return getTrainerUnzippedPath();
|
|
60
|
-
}
|
|
61
|
-
exports.getMablTrainerExtensionPath = getMablTrainerExtensionPath;
|
|
62
|
-
async function updateMablTrainer(version) {
|
|
63
|
-
await downloadTrainer(version);
|
|
64
|
-
return getTrainerVersion();
|
|
65
|
-
}
|
|
66
|
-
exports.updateMablTrainer = updateMablTrainer;
|
|
67
|
-
function trainerExists() {
|
|
68
|
-
return fs.existsSync(getTrainerUnzippedPath());
|
|
69
|
-
}
|
|
70
|
-
function getTrainerManifest() {
|
|
71
|
-
return JSON.parse(fs.readFileSync(getTrainerManifestPath()));
|
|
72
|
-
}
|
|
73
|
-
function setTrainerManifestId() {
|
|
74
|
-
const trainerManifest = getTrainerManifest();
|
|
75
|
-
trainerManifest.key = LOCAL_TRAINER_KEY;
|
|
76
|
-
fs.writeFileSync(getTrainerManifestPath(), JSON.stringify(trainerManifest, undefined, 2));
|
|
77
|
-
}
|
|
78
|
-
function getTrainerId() {
|
|
79
|
-
if (env_1.LOCAL_TRAINER_PATH) {
|
|
80
|
-
return env_1.EXTENSION_ID;
|
|
81
|
-
}
|
|
82
|
-
return exports.LOCAL_TRAINER_ID;
|
|
83
|
-
}
|
|
84
|
-
exports.getTrainerId = getTrainerId;
|
|
85
|
-
function getTrainerVersion() {
|
|
86
|
-
if (trainerExists()) {
|
|
87
|
-
const trainerManifest = getTrainerManifest();
|
|
88
|
-
return trainerManifest.version;
|
|
89
|
-
}
|
|
90
|
-
messaging_1.mablEventEmitter.log(chalk.red('No local trainer installed for CLI, run', chalk.magenta('[mabl tests trainer install]')));
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
exports.getTrainerVersion = getTrainerVersion;
|
|
94
|
-
async function downloadTrainer(version) {
|
|
95
|
-
fs.ensureDirSync(getTrainerPath());
|
|
96
|
-
const client = axios_1.default.create(await (0, httpUtil_1.currentProxyConfig)());
|
|
97
|
-
const url = `${env_1.BASE_API_URL}/trainer/distribution?${buildQueryStringsForDistro(version)}`;
|
|
98
|
-
const finalPath = getTrainerZipFile();
|
|
99
|
-
const writer = fs.createWriteStream(finalPath);
|
|
100
|
-
const response = await client.get(url, {
|
|
101
|
-
responseType: 'stream',
|
|
102
|
-
});
|
|
103
|
-
response.data.pipe(writer);
|
|
104
|
-
await new Promise((resolve, reject) => {
|
|
105
|
-
writer.on('finish', resolve);
|
|
106
|
-
writer.on('error', reject);
|
|
107
|
-
});
|
|
108
|
-
return new Promise((resolve, reject) => {
|
|
109
|
-
const unzipper = new DecompressZip(finalPath);
|
|
110
|
-
unzipper.on('error', (_err) => {
|
|
111
|
-
const errorMessage = 'There was an issue unzipping the local mabl Trainer';
|
|
112
|
-
messaging_1.mablEventEmitter.log(errorMessage);
|
|
113
|
-
reject(new Error(errorMessage));
|
|
114
|
-
});
|
|
115
|
-
unzipper.on('extract', (_log) => {
|
|
116
|
-
setTrainerManifestId();
|
|
117
|
-
resolve();
|
|
118
|
-
});
|
|
119
|
-
unzipper.extract({
|
|
120
|
-
path: getTrainerUnzippedPath(),
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
async function checkForTrainerUpdate() {
|
|
125
|
-
if (trainerExists()) {
|
|
126
|
-
const currentTrainerCheckSum = crypto
|
|
127
|
-
.createHash('md5')
|
|
128
|
-
.update(fs.readFileSync(getTrainerZipFile()))
|
|
129
|
-
.digest('base64');
|
|
130
|
-
await getCurrentVersionChecksum()
|
|
131
|
-
.then((checkSum) => {
|
|
132
|
-
const checkSumLatest = checkSum.match('md5=([^}]+)');
|
|
133
|
-
if (checkSumLatest && checkSumLatest[1] !== currentTrainerCheckSum) {
|
|
134
|
-
const table = new cli_table3_1.default({
|
|
135
|
-
head: [chalk.yellow('Trainer Update Available')],
|
|
136
|
-
wordWrap: true,
|
|
137
|
-
});
|
|
138
|
-
table.push([
|
|
139
|
-
{
|
|
140
|
-
rowSpan: 1,
|
|
141
|
-
content: `There is a newer version of the trainer available! Run ${chalk.magenta('mabl tests trainer update')} to update`,
|
|
142
|
-
vAlign: 'center',
|
|
143
|
-
},
|
|
144
|
-
]);
|
|
145
|
-
messaging_1.mablEventEmitter.log(table.toString());
|
|
146
|
-
}
|
|
147
|
-
})
|
|
148
|
-
.catch((error) => {
|
|
149
|
-
messaging_1.mablEventEmitter.log(error.message);
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
exports.checkForTrainerUpdate = checkForTrainerUpdate;
|
|
154
|
-
async function getCurrentVersionChecksum() {
|
|
155
|
-
const url = `${env_1.BASE_API_URL}/trainer/distribution?${buildQueryStringsForDistro()}`;
|
|
156
|
-
return axios_1.default
|
|
157
|
-
.head(url, await (0, httpUtil_1.currentProxyConfig)())
|
|
158
|
-
.then((response) => response.headers['x-goog-hash'])
|
|
159
|
-
.catch((error) => {
|
|
160
|
-
loggingProvider_1.logger.error(chalk.red.bold(`There was an issue checking the current mabl trainer. ${error.message}`));
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
function buildQueryStringsForDistro(version) {
|
|
164
|
-
const queryStringArgs = {
|
|
165
|
-
version,
|
|
166
|
-
release: env_1.ENV,
|
|
167
|
-
};
|
|
168
|
-
return queryString.stringify(queryStringArgs);
|
|
169
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateTrainer = void 0;
|
|
4
|
-
const trainerUtil_1 = require("./trainerUtil");
|
|
5
|
-
const constants_1 = require("../../../constants");
|
|
6
|
-
const loggingProvider_1 = require("../../../../providers/logging/loggingProvider");
|
|
7
|
-
const chalk = require('chalk');
|
|
8
|
-
exports.command = 'update';
|
|
9
|
-
exports.describe = 'Update the mabl Trainer version for the mabl CLI';
|
|
10
|
-
exports.builder = (yargs) => {
|
|
11
|
-
yargs.option(constants_1.CommandArgTrainerVersion, {
|
|
12
|
-
describe: 'the version to update to',
|
|
13
|
-
nargs: 1,
|
|
14
|
-
type: 'string',
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
exports.handler = updateTrainer;
|
|
18
|
-
async function updateTrainer(parsed) {
|
|
19
|
-
const version = parsed['trainer-version'];
|
|
20
|
-
const printedVersion = chalk.magenta(`${version !== null && version !== void 0 ? version : 'latest'}`);
|
|
21
|
-
loggingProvider_1.logger.info(`Updating the local version of the mabl Trainer to: ${printedVersion}`);
|
|
22
|
-
const updatedVersion = await (0, trainerUtil_1.updateMablTrainer)(version);
|
|
23
|
-
const newVersion = updatedVersion !== null && updatedVersion !== void 0 ? updatedVersion : 'unknown';
|
|
24
|
-
loggingProvider_1.logger.info(`Update complete, version: ${chalk.magenta(newVersion)}, is ready`);
|
|
25
|
-
return newVersion;
|
|
26
|
-
}
|
|
27
|
-
exports.updateTrainer = updateTrainer;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const trainerUtil_1 = require("./trainerUtil");
|
|
4
|
-
const loggingProvider_1 = require("../../../../providers/logging/loggingProvider");
|
|
5
|
-
const chalk = require('chalk');
|
|
6
|
-
exports.command = 'version';
|
|
7
|
-
exports.describe = 'Get the version of the local mabl Trainer';
|
|
8
|
-
exports.builder = {};
|
|
9
|
-
exports.handler = getVersion;
|
|
10
|
-
async function getVersion() {
|
|
11
|
-
try {
|
|
12
|
-
await (0, trainerUtil_1.checkForTrainerUpdate)();
|
|
13
|
-
const trainerVersion = (0, trainerUtil_1.getTrainerVersion)() || '';
|
|
14
|
-
if (trainerVersion) {
|
|
15
|
-
loggingProvider_1.logger.info(`Current CLI mabl Trainer version is: ${chalk.magenta(trainerVersion)}`);
|
|
16
|
-
}
|
|
17
|
-
return trainerVersion || 'unknown';
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
throw new Error(`Error getting trainer version: ${error}`);
|
|
21
|
-
}
|
|
22
|
-
}
|