@testim/testim-cli 3.253.0 → 3.254.0

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.
Files changed (79) hide show
  1. package/OverrideTestDataBuilder.js +1 -1
  2. package/agent/routers/cliJsCode/index.js +4 -4
  3. package/agent/routers/cliJsCode/router.js +46 -42
  4. package/agent/routers/cliJsCode/service.js +18 -13
  5. package/agent/routers/codim/router.js +14 -17
  6. package/agent/routers/codim/router.test.js +15 -14
  7. package/agent/routers/codim/service.js +1 -1
  8. package/agent/routers/general/index.js +4 -8
  9. package/agent/routers/hybrid/registerRoutes.js +18 -18
  10. package/agent/routers/index.js +7 -7
  11. package/agent/routers/playground/router.js +11 -10
  12. package/agent/routers/playground/service.js +19 -18
  13. package/agent/routers/standalone-browser/registerRoutes.js +10 -10
  14. package/cdpTestRunner.js +4 -3
  15. package/chromiumInstaller.js +4 -5
  16. package/cli/onExit.js +2 -2
  17. package/cli.js +7 -6
  18. package/cliAgentMode.js +4 -5
  19. package/codim/codim-cli.js +11 -10
  20. package/codim/hybrid-utils.js +1 -1
  21. package/codim/measure-perf.js +9 -6
  22. package/codim/template.js/tests/examples/01-simple-text-validation.test.js +6 -6
  23. package/codim/template.js/tests/examples/02-using-locators.test.js +13 -15
  24. package/codim/template.js/tests/examples/03-using-hooks.test.js +17 -19
  25. package/codim/template.js/tests/examples/04-skip-and-only.test.js +16 -17
  26. package/codim/template.js/tests/examples/05-multiple-windows.test.js +16 -17
  27. package/codim/template.js/webpack.config.js +1 -1
  28. package/codim/template.ts/webpack.config.js +3 -3
  29. package/commons/AbortError.js +4 -4
  30. package/commons/detectDebugger.js +4 -2
  31. package/commons/lazyRequire.js +10 -9
  32. package/commons/logger.js +4 -4
  33. package/commons/performance-logger.js +14 -8
  34. package/commons/prepareRunnerAndTestimStartUtils.js +6 -7
  35. package/commons/socket/baseSocketServiceSocketIO.js +32 -34
  36. package/commons/socket/realDataService.js +6 -5
  37. package/commons/socket/realDataServiceSocketIO.js +4 -4
  38. package/commons/socket/remoteStepService.js +4 -3
  39. package/commons/socket/remoteStepServiceSocketIO.js +11 -12
  40. package/commons/socket/socketService.js +50 -52
  41. package/commons/socket/testResultServiceSocketIO.js +11 -11
  42. package/commons/testimDesiredCapabilitiesBuilder.js +3 -2
  43. package/commons/testimNgrok.js +2 -2
  44. package/commons/testimNgrok.test.js +1 -1
  45. package/commons/testimServicesApi.js +27 -20
  46. package/commons/xhr2.js +97 -100
  47. package/errors.js +5 -0
  48. package/fixLocalBuild.js +2 -0
  49. package/npm-shrinkwrap.json +2515 -1256
  50. package/package.json +6 -6
  51. package/player/appiumTestPlayer.js +1 -1
  52. package/player/chromeLauncherTestPlayer.js +0 -1
  53. package/player/services/tabServiceMock.js +166 -0
  54. package/player/stepActions/navigationStepAction.js +11 -10
  55. package/player/stepActions/sleepStepAction.js +4 -5
  56. package/player/stepActions/textStepAction.js +4 -11
  57. package/player/utils/windowUtils.js +4 -3
  58. package/player/webdriver.js +1 -1
  59. package/processHandler.js +3 -3
  60. package/processHandler.test.js +1 -1
  61. package/reports/consoleReporter.js +3 -2
  62. package/reports/junitReporter.js +1 -2
  63. package/runOptions.js +6 -6
  64. package/runner.js +13 -0
  65. package/runners/TestPlanRunner.js +142 -74
  66. package/runners/buildCodeTests.js +38 -37
  67. package/runners/runnerUtils.js +3 -3
  68. package/services/lambdatestService.js +3 -5
  69. package/stepPlayers/cliJsStepPlayback.js +22 -17
  70. package/testRunHandler.js +8 -0
  71. package/testRunStatus.js +1 -1
  72. package/{utils.js → utils/index.js} +25 -117
  73. package/utils/promiseUtils.js +78 -0
  74. package/utils/stringUtils.js +96 -0
  75. package/{utils.test.js → utils/utils.test.js} +2 -2
  76. package/workers/BaseWorker.js +16 -14
  77. package/workers/WorkerAppium.js +1 -1
  78. package/workers/WorkerExtensionSingleBrowser.js +4 -4
  79. package/workers/WorkerSelenium.js +5 -2
@@ -2,7 +2,7 @@
2
2
 
3
3
  'use strict';
4
4
 
5
- const utils = require('./utils.js');
5
+ const utils = require('./utils');
6
6
  const _ = require('lodash');
7
7
  const logger = require('./commons/logger').getLogger('override-test-data-builder');
8
8
 
@@ -1,13 +1,13 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
3
  const router = require('./router');
4
4
  const service = require('./service');
5
- const logger = require('../../../commons/logger').getLogger("cli-service");
5
+ const logger = require('../../../commons/logger').getLogger('cli-service');
6
6
 
7
7
  // clean local
8
8
  service.cleanLocalPackageInstallFolder()
9
- .catch(err => logger.warn("failed to clean local package folder", {err}));
9
+ .catch(err => logger.warn('failed to clean local package folder', { err }));
10
10
 
11
11
  module.exports = {
12
- router: router
12
+ router,
13
13
  };
@@ -1,60 +1,64 @@
1
- "use strict";
1
+ /* eslint-disable no-console */
2
2
 
3
- const Promise = require('bluebird');
3
+ 'use strict';
4
+
5
+ const { TimeoutError } = require('bluebird');
4
6
  const express = require('express');
5
7
  const service = require('./service');
6
- const {NpmPackageError} = require('../../../errors');
7
- const logger = require('../../../commons/logger').getLogger("cli-router");
8
+ const { NpmPackageError } = require('../../../errors');
9
+ const logger = require('../../../commons/logger').getLogger('cli-router');
8
10
  const chalk = require('chalk');
9
11
 
10
12
  const router = express.Router();
11
13
 
12
- router.post('/run', (req, res) => {
13
- const {code, stepId, incomingParams, context, testResultId, retryIndex, stepResultId, timeout, fileDataUrl} = req.body;
14
+ router.post('/run', async (req, res) => {
15
+ const { code, stepId, incomingParams, context, testResultId, retryIndex, stepResultId, timeout, fileDataUrl } = req.body;
14
16
 
15
- if (typeof code !== "string" || !stepId || !incomingParams || !context || !testResultId || typeof retryIndex !== "number" || !stepResultId || typeof timeout !== "number") {
16
- return res.status(400).json({success: false, code: "invalid-params"});
17
+ if (typeof code !== 'string' || !stepId || !incomingParams || !context || !testResultId || typeof retryIndex !== 'number' || !stepResultId || typeof timeout !== 'number') {
18
+ res.status(400).json({ success: false, code: 'invalid-params' });
19
+ return;
17
20
  }
18
21
 
19
- return service.runCodeWithPackages(code, stepId, incomingParams, context, testResultId, retryIndex, stepResultId, timeout, fileDataUrl)
20
- .then(data => {
21
- if(!data.success) {
22
- console.log(chalk.red(data.result.resultValue));
23
- logger.error('CLI Action Failure', {message: data.result.resultValue });
24
- }
25
- res.status(200).json({success: true, data});
26
- })
27
- .catch(err => {
28
- logger.error("failed to run cli code", {err});
29
- console.log(chalk.red("failed to run cli code", err));
30
- res.status(500).json({success: false, code: "internal-error"});
31
- });
22
+ try {
23
+ const data = await service.runCodeWithPackages(code, stepId, incomingParams, context, testResultId, retryIndex, stepResultId, timeout, fileDataUrl);
24
+ if (!data.success) {
25
+ console.log(chalk.red(data.result.resultValue));
26
+ logger.error('CLI Action Failure', { message: data.result.resultValue });
27
+ }
28
+ res.status(200).json({ success: true, data });
29
+ } catch (err) {
30
+ logger.error('failed to run cli code', { err });
31
+ console.log(chalk.red('failed to run cli code', err));
32
+ res.status(500).json({ success: false, code: 'internal-error' });
33
+ }
32
34
  });
33
35
 
34
- router.post('/install', (req, res) => {
35
- const {stepId, testResultId, retryIndex, packageData, stepResultId, timeout} = req.body;
36
+ router.post('/install', async (req, res) => {
37
+ const { stepId, testResultId, retryIndex, packageData, stepResultId, timeout } = req.body;
36
38
 
37
- if (!stepId || typeof packageData !== "object" || !testResultId || typeof retryIndex !== "number" || !stepResultId || typeof timeout !== "number") {
38
- return res.status(400).json({success: false, code: "invalid-params"});
39
+ if (!stepId || typeof packageData !== 'object' || !testResultId || typeof retryIndex !== 'number' || !stepResultId || typeof timeout !== 'number') {
40
+ res.status(400).json({ success: false, code: 'invalid-params' });
41
+ return;
39
42
  }
40
43
 
41
- return service.installPackage(stepId, testResultId, retryIndex, packageData, stepResultId, timeout)
42
- .then(data => {
43
- logger.info("installed packages successfully");
44
- res.status(200).json({success: true, data});
45
- })
46
- .catch(NpmPackageError, err => {
47
- logger.error("failed to install node packages", {err});
48
- res.status(200).json({success: false, code: "invalid-node-package", message: err.message});
49
- })
50
- .catch(Promise.TimeoutError, () => {
51
- logger.error("timeout installing node package");
52
- return res.status(200).json({success: false, code: "timeout"});
53
- })
54
- .catch(err => {
55
- logger.error("failed to install node packages", {err});
56
- res.status(500).json({success: false, code: "internal-error"});
57
- });
44
+ try {
45
+ const data = await service.installPackage(stepId, testResultId, retryIndex, packageData, stepResultId, timeout);
46
+ logger.info('installed packages successfully');
47
+ res.status(200).json({ success: true, data });
48
+ } catch (err) {
49
+ if (err instanceof NpmPackageError) {
50
+ logger.error('failed to install node packages', { err });
51
+ res.status(200).json({ success: false, code: 'invalid-node-package', message: err.message });
52
+ return;
53
+ }
54
+ if (err instanceof TimeoutError) {
55
+ logger.error('timeout installing node package');
56
+ res.status(200).json({ success: false, code: 'timeout' });
57
+ return;
58
+ }
59
+ logger.error('failed to install node packages', { err });
60
+ res.status(500).json({ success: false, code: 'internal-error' });
61
+ }
58
62
  });
59
63
 
60
64
  module.exports = router;
@@ -11,6 +11,7 @@ const logger = require('../../../commons/logger').getLogger('cli-service');
11
11
  const { getS3Artifact } = require('../../../commons/testimServicesApi');
12
12
  const npmWrapper = require('../../../commons/npmWrapper');
13
13
  const featureFlags = require('../../../commons/featureFlags');
14
+ const { TimeoutError } = require('../../../errors');
14
15
 
15
16
  let workerThreads;
16
17
 
@@ -587,22 +588,22 @@ function runCodeWithPackages(code, stepId, incomingParams, context, testResultId
587
588
  }).then(res => Object.assign({}, res, { nodeVersion: process.version }));
588
589
  }
589
590
 
590
- function runNpmInstall(transactionId, packageData, timeout) {
591
+ async function runNpmInstall(transactionId, packageData, timeout) {
591
592
  const packages = packageData.map(data => `${data.packageName}@${data.packageVersion}`);
592
593
  const localPackageInstallFolder = getLocalPackageInstallFolder();
593
594
  const installFolder = path.join(localPackageInstallFolder, `/${transactionId}`);
594
595
  const proxyUri = global.proxyUri;
595
596
 
596
- // while correct, everything is in a try/catch so it should be fine.
597
- // eslint-disable-next-line no-async-promise-executor
598
- return new Promise(async (resolve, reject) => {
597
+
598
+ async function npmInstallation() {
599
599
  let output = '';
600
600
  try {
601
601
  output = await npmWrapper.installPackages(installFolder, packages, proxyUri, timeout);
602
602
  logger.info('npm package install finished', { transactionId, output, timeout });
603
603
  if (Number(output.trim().split(' ')[1]) < packages.length) {
604
- reject('npm package install failed, couldn\'t install all packages');
605
- return;
604
+ // TODO: I am not sure changing this to an error would be safe.
605
+ // eslint-disable-next-line no-throw-literal
606
+ throw 'npm package install failed, couldn\'t install all packages';
606
607
  }
607
608
  const packageDataWithVersions = packageData.map(pData => {
608
609
  const version = npmWrapper.getLocallyInstalledPackageVersion(installFolder, pData.packageName);
@@ -614,17 +615,21 @@ function runNpmInstall(transactionId, packageData, timeout) {
614
615
  });
615
616
  });
616
617
 
617
- resolve({ data: packageDataWithVersions, installFolder });
618
+ return { data: packageDataWithVersions, installFolder };
618
619
  } catch (err) {
619
620
  logger.warn('npm package install failed', { transactionId, err });
620
- reject(err);
621
+ throw err;
621
622
  }
622
- })
623
- .timeout(timeout)
624
- .catch(Promise.TimeoutError, err => {
623
+ }
624
+
625
+ try {
626
+ return await utils.promiseTimeout(npmInstallation(), timeout);
627
+ } catch (err) {
628
+ if (err instanceof TimeoutError) {
625
629
  logger.warn('timeout to install package', { packages, transactionId, err, timeout });
626
- throw err;
627
- });
630
+ }
631
+ throw err;
632
+ }
628
633
  }
629
634
 
630
635
  function getLocalPackageInstallFolder() {
@@ -1,8 +1,9 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
3
  const express = require('express');
4
+
4
5
  const router = express.Router();
5
- const logger = require('../../../commons/logger').getLogger("codim-router");
6
+ const logger = require('../../../commons/logger').getLogger('codim-router');
6
7
 
7
8
  const {
8
9
  findTests,
@@ -10,40 +11,39 @@ const {
10
11
  getLocalLocatorContents,
11
12
  saveTest,
12
13
  saveLocators,
13
- compileFunctionsLibrary
14
+ compileFunctionsLibrary,
14
15
  } = require('./service');
15
16
 
16
17
 
17
18
  router.get('/tests', async (req, res) => {
18
19
  const tests = await findTests();
19
- res.json({tests, success: true });
20
+ res.json({ tests, success: true });
20
21
  });
21
22
  router.get('/locators', async (req, res) => {
22
23
  const locators = await getLocalLocators();
23
24
  const contents = await getLocalLocatorContents(locators, req.query.full);
24
- res.json({locators, contents, success: true });
25
+ res.json({ locators, contents, success: true });
25
26
  });
26
27
  router.post('/locators', async (req, res) => {
27
-
28
28
  if (!req.body) {
29
- res.status(400).send({success: false, reason: 'missing body' });
29
+ res.status(400).send({ success: false, reason: 'missing body' });
30
30
  return;
31
31
  }
32
32
  if (!req.body.locators) {
33
- res.status(400).send({success: false, reason: 'missing locators' });
33
+ res.status(400).send({ success: false, reason: 'missing locators' });
34
34
  return;
35
35
  }
36
36
 
37
37
  const { locators, mergeIntoExisting } = req.body;
38
38
 
39
39
  await saveLocators(locators, { mergeIntoExisting: mergeIntoExisting || false });
40
- res.status(200).send({ success: true })
40
+ res.status(200).send({ success: true });
41
41
  });
42
42
 
43
43
  router.get('/compile', async (req, res) => {
44
44
  try {
45
45
  const code = await compileFunctionsLibrary(req.body.name);
46
- res.send({ success: true, code })
46
+ res.send({ success: true, code });
47
47
  } catch (e) {
48
48
  logger.error(e);
49
49
  res.json({ success: false, reason: e.message });
@@ -51,20 +51,17 @@ router.get('/compile', async (req, res) => {
51
51
  });
52
52
 
53
53
  router.post('/saveTest', async (req, res) => {
54
-
55
54
  if (!req.body) {
56
- res.status(400).send({success: false, reason: 'missing body' });
55
+ res.status(400).send({ success: false, reason: 'missing body' });
57
56
  return;
58
57
  }
59
58
  try {
60
- await saveTest(req.body);
61
- res.send({ success: true });
59
+ await saveTest(req.body);
60
+ res.send({ success: true });
62
61
  } catch (e) {
63
- res.json({success: false, reason: e.message });
62
+ res.json({ success: false, reason: e.message });
64
63
  logger.error(e);
65
- return;
66
64
  }
67
-
68
65
  });
69
66
 
70
67
 
@@ -1,4 +1,4 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
3
  const router = require('./router');
4
4
 
@@ -6,17 +6,19 @@ const path = require('path');
6
6
  const os = require('os');
7
7
  const compression = require('compression');
8
8
  const express = require('express');
9
+
9
10
  const app = express();
10
11
  const bodyParser = require('body-parser');
11
12
  const Promise = require('bluebird');
13
+ const { promiseFromCallback } = require('../../../utils');
12
14
  const superagent = require('superagent');
13
- const { expect } = require('chai');
15
+ const { expect } = require('chai'); // eslint-disable-line import/no-extraneous-dependencies
14
16
 
15
17
  const fs = Promise.promisifyAll(require('fs'));
16
18
 
17
- app.use(bodyParser.urlencoded({extended: false, limit: '50mb'}));
19
+ app.use(bodyParser.urlencoded({ extended: false, limit: '50mb' }));
18
20
  app.use(compression());
19
- app.use(bodyParser.json({limit: '50mb'}));
21
+ app.use(bodyParser.json({ limit: '50mb' }));
20
22
 
21
23
  app.use('/files', router.router);
22
24
 
@@ -24,13 +26,13 @@ describe('codim router', () => {
24
26
  let listener;
25
27
  async function saveLocators(locatorsObject) {
26
28
  const request = superagent.post(`http://localhost:${listener.address().port}/files/locators`)
27
- .send(locatorsObject);
28
- await Promise.fromCallback((callback) => request.end(callback));
29
+ .send(locatorsObject);
30
+ await promiseFromCallback((callback) => request.end(callback));
29
31
  }
30
32
 
31
33
  async function loadLocators() {
32
34
  const request = superagent.get(`http://localhost:${listener.address().port}/files/locators`);
33
- return await Promise.fromCallback((callback) => request.end(callback)).then(x => x.text).then(JSON.parse);
35
+ return await promiseFromCallback((callback) => request.end(callback)).then(x => x.text).then(JSON.parse);
34
36
  }
35
37
 
36
38
  let tmpDir;
@@ -46,17 +48,16 @@ describe('codim router', () => {
46
48
 
47
49
  it('saves locators', async () => {
48
50
  await saveLocators({
49
- locators: [{ id: 'foo', name: 'foo', body: {internal: 'bar' }}],
50
- mergeIntoExisting: false
51
+ locators: [{ id: 'foo', name: 'foo', body: { internal: 'bar' } }],
52
+ mergeIntoExisting: false,
51
53
  });
52
54
  const locators = await loadLocators();
53
55
  expect(locators).to.deep.eq({
54
- "contents": {},
55
- "locators": {
56
- "foo": "foo"
56
+ contents: {},
57
+ locators: {
58
+ foo: 'foo',
57
59
  },
58
- "success": true
60
+ success: true,
59
61
  });
60
62
  });
61
-
62
63
  });
@@ -12,7 +12,7 @@ const findTestFolder = _.memoize(async (fromFolder) => {
12
12
  const files = await fs.readdirAsync(fromFolder);
13
13
  // this is either invoked by running the Testim CLI from inside the tests folder or from inside the `init` folder
14
14
  // so deal with the case we're inside tests.
15
- const isInProjectFolder = files.some(x => x === 'tests') && (await fs.statAsync(path.join(fromFolder, 'tests'))).isDirectory();
15
+ const isInProjectFolder = files.includes('tests') && (await fs.statAsync(path.join(fromFolder, 'tests'))).isDirectory();
16
16
  if (isInProjectFolder) {
17
17
  return path.join(fromFolder, 'tests');
18
18
  }
@@ -1,4 +1,4 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
3
  const { getPackageVersion } = require('../../../testimNpmDriver');
4
4
  const { doLogin } = require('../../../credentialsManager');
@@ -9,11 +9,9 @@ module.exports = (app) => {
9
9
  * root endpoint
10
10
  */
11
11
  app.get('/', (req, res) => {
12
-
13
12
  const isStartMode = getStartedWithStart();
14
13
 
15
- return res.status(200).json({success: true, isTestimAgent: true, startMode: isStartMode});
16
-
14
+ return res.status(200).json({ success: true, isTestimAgent: true, startMode: isStartMode });
17
15
  });
18
16
 
19
17
  /**
@@ -22,19 +20,17 @@ module.exports = (app) => {
22
20
  app.get('/version', (req, res) => {
23
21
  res.status(200).json({
24
22
  node: process.version,
25
- app: getPackageVersion()
23
+ app: getPackageVersion(),
26
24
  });
27
25
  });
28
26
 
29
27
  app.get('/loginInfo', (req, res) => {
30
28
  try {
31
29
  const projects = JSON.parse(Buffer.from(req.query.info, 'base64').toString());
32
- doLogin({overwriteExisting: false, projects });
30
+ doLogin({ overwriteExisting: false, projects });
33
31
  res.status(200).end();
34
32
  } catch (err) {
35
33
  res.status(400).end();
36
34
  }
37
35
  });
38
-
39
-
40
36
  };
@@ -3,7 +3,7 @@
3
3
  const service = require('../../../stepPlayers/hybridStepPlayback');
4
4
  const express = require('express');
5
5
  const lazyRequire = require('../../../commons/lazyRequire');
6
- const logger = require('../../../commons/logger').getLogger("hybrid-router");
6
+ const logger = require('../../../commons/logger').getLogger('hybrid-router');
7
7
 
8
8
  /**
9
9
  * @param {{
@@ -16,7 +16,7 @@ module.exports.hybridRoutes = function hybridRoutes(testimStandaloneBrowser) {
16
16
  router.post('/run', (req, res) => {
17
17
  if (!req.body || !req.body.step) {
18
18
  res.status(400).send({
19
- error: "Missing step"
19
+ error: 'Missing step',
20
20
  });
21
21
  return;
22
22
  }
@@ -24,15 +24,15 @@ module.exports.hybridRoutes = function hybridRoutes(testimStandaloneBrowser) {
24
24
  const {
25
25
  step,
26
26
  context,
27
- loginData // is this safe to pass here?
27
+ loginData, // is this safe to pass here?
28
28
  } = req.body;
29
29
  if (!testimStandaloneBrowser.webdriverApi) {
30
- res.status(503).send({success: false, reason: 'Testim Agent was not started with Testim Start.' });
30
+ res.status(503).send({ success: false, reason: 'Testim Agent was not started with Testim Start.' });
31
31
  }
32
32
 
33
33
  // The step run might take very long time, and it will still be valid
34
34
  // so we set here unlimited timeout
35
- req.setTimeout(0)
35
+ req.setTimeout(0);
36
36
 
37
37
  service.execute(
38
38
  step,
@@ -41,18 +41,18 @@ module.exports.hybridRoutes = function hybridRoutes(testimStandaloneBrowser) {
41
41
  loginData,
42
42
  undefined, // don't pass frameManager,
43
43
  'agent'
44
- ).then((result) => {
45
- res.status(200).send(result);
46
- }).catch(e => {
47
- logger.error("failed to run hybrid code", { e });
48
- res.status(500).send(Object.assign({success: false, error: e }));
49
- });
44
+ ).then((result) => {
45
+ res.status(200).send(result);
46
+ }).catch(e => {
47
+ logger.error('failed to run hybrid code', { e });
48
+ res.status(500).send(Object.assign({ success: false, error: e }));
49
+ });
50
50
  });
51
51
 
52
52
  router.post('/abort', (req, res) => {
53
53
  if (!req.body || !req.body.stepResultId) {
54
54
  res.status(400).send({
55
- error: `missing stepResultId`
55
+ error: 'missing stepResultId',
56
56
  });
57
57
 
58
58
  return;
@@ -62,20 +62,20 @@ module.exports.hybridRoutes = function hybridRoutes(testimStandaloneBrowser) {
62
62
  service.abort(req.body.stepResultId);
63
63
  res.status(204).end();
64
64
  } catch (e) {
65
- if (e && e.message === "No such stepResultId") {
65
+ if (e && e.message === 'No such stepResultId') {
66
66
  res.status(400).send({
67
- error: `No such stepResultId`
67
+ error: 'No such stepResultId',
68
68
  });
69
69
  return;
70
70
  }
71
71
 
72
- logger.error("hybrid code abort unexpected error", { e });
72
+ logger.error('hybrid code abort unexpected error', { e });
73
73
  res.status(500).send({
74
- error: "unexpected error",
75
- info: `${e ? e.message : "N/A"}`
74
+ error: 'unexpected error',
75
+ info: `${e ? e.message : 'N/A'}`,
76
76
  });
77
77
  }
78
78
  });
79
79
 
80
80
  return router;
81
- }
81
+ };
@@ -1,4 +1,4 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
3
  const compression = require('compression');
4
4
  const express = require('express');
@@ -7,14 +7,14 @@ const cors = require('cors');
7
7
  const { IS_ON_PREM, DISABLE_AGENT_ORIGIN_CHECK } = require('../../commons/config');
8
8
 
9
9
 
10
- module.exports = function(beforeMiddleware, standaloneBrowserInfo) {
10
+ module.exports = function (beforeMiddleware, standaloneBrowserInfo) {
11
11
  const app = express();
12
12
  beforeMiddleware(app);
13
13
 
14
14
  // view engine setup
15
- app.use(bodyParser.urlencoded({extended: false, limit: '50mb'}));
15
+ app.use(bodyParser.urlencoded({ extended: false, limit: '50mb' }));
16
16
  app.use(compression());
17
- app.use(bodyParser.json({limit: '50mb'}));
17
+ app.use(bodyParser.json({ limit: '50mb' }));
18
18
 
19
19
  /**
20
20
  * set cors options
@@ -27,8 +27,8 @@ module.exports = function(beforeMiddleware, standaloneBrowserInfo) {
27
27
  allowedHeaders: ['Content-Type', 'Authorization'],
28
28
  credentials: true,
29
29
  maxAge: 86400,
30
- origin: (IS_ON_PREM || DISABLE_AGENT_ORIGIN_CHECK) ? '*' : whitelist
31
- }
30
+ origin: (IS_ON_PREM || DISABLE_AGENT_ORIGIN_CHECK) ? '*' : whitelist,
31
+ };
32
32
  app.use('*', cors(corsOptions));
33
33
 
34
34
  // Routes
@@ -42,7 +42,7 @@ module.exports = function(beforeMiddleware, standaloneBrowserInfo) {
42
42
  app.use('/cliJs', cliJsCode.router);
43
43
 
44
44
  app.use('/standalone-browser',
45
- require("./standalone-browser/registerRoutes").standaloneBrowserRoutes(standaloneBrowserInfo)
45
+ require('./standalone-browser/registerRoutes').standaloneBrowserRoutes(standaloneBrowserInfo)
46
46
  );
47
47
 
48
48
  app.use('/hybrid', require('./hybrid/registerRoutes').hybridRoutes(standaloneBrowserInfo));
@@ -1,16 +1,17 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
3
  const express = require('express');
4
+
4
5
  const router = express.Router();
5
6
  const logger = require('../../../commons/logger').getLogger('playground-router');
6
- const {ClientError, PlaygroundCodeError} = require('../../../errors');
7
- const {runPlaygroundTest, stopPlaygroundTest, CODE_TYPES} = require('./service');
8
- const {DISABLE_AGENT_ORIGIN_CHECK} = require('../../../commons/config');
7
+ const { ClientError, PlaygroundCodeError } = require('../../../errors');
8
+ const { runPlaygroundTest, stopPlaygroundTest, CODE_TYPES } = require('./service');
9
+ const { DISABLE_AGENT_ORIGIN_CHECK } = require('../../../commons/config');
9
10
 
10
11
  const VALID_HOSTS = ['localhost', 'app.testim.io', 'playground.testim.io', 'staging.testim.io', 'app.staging.testim.cc', 'tta-crm.tricentis.com'];
11
12
 
12
13
  const parseUrl = (url) => {
13
- if(!url) {
14
+ if (!url) {
14
15
  return {};
15
16
  }
16
17
  try {
@@ -21,17 +22,17 @@ const parseUrl = (url) => {
21
22
  };
22
23
 
23
24
  const checkReferer = (req, res, next) => {
24
- if(DISABLE_AGENT_ORIGIN_CHECK) {
25
+ if (DISABLE_AGENT_ORIGIN_CHECK) {
25
26
  return next();
26
27
  }
27
28
  const referer = req.headers.referer;
28
29
  const origin = req.headers.origin;
29
- if(!referer && !origin) {
30
+ if (!referer && !origin) {
30
31
  return res.status(400).send();
31
32
  }
32
33
  const refererUrl = parseUrl(referer);
33
34
  const originUrl = parseUrl(origin);
34
- if(!VALID_HOSTS.includes(refererUrl.hostname) && !VALID_HOSTS.includes(originUrl.hostname)) {
35
+ if (!VALID_HOSTS.includes(refererUrl.hostname) && !VALID_HOSTS.includes(originUrl.hostname)) {
35
36
  return res.status(400).send();
36
37
  }
37
38
  return next();
@@ -50,11 +51,11 @@ router.post('/run', [checkReferer], async (req, res) => {
50
51
  await runPlaygroundTest(body);
51
52
  res.send({ success: true });
52
53
  } catch (e) {
53
- if(e instanceof ClientError) {
54
+ if (e instanceof ClientError) {
54
55
  res.status(404).send({ success: false });
55
56
  return undefined;
56
57
  }
57
- if(e instanceof PlaygroundCodeError) {
58
+ if (e instanceof PlaygroundCodeError) {
58
59
  res.json({ success: false, type: 'playground-error', stack: e.innerStack });
59
60
  return undefined;
60
61
  }