@testim/testim-cli 3.238.0 → 3.241.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.
@@ -40,14 +40,21 @@ async function prepareTunnel() {
40
40
  }
41
41
 
42
42
  const connectTunnel = async (options) => {
43
+ const tunnelBaseUrl = options.baseUrl || `http://localhost:${options.tunnelPort || 80}`;
44
+ const tunnelRoutes = options.tunnelRoutes || [tunnelBaseUrl];
43
45
  const [result] = await Promise.all([
44
- servicesApi.getCloudflareTunnel(options.company.companyId, options.tunnelRoutes),
46
+ servicesApi.getCloudflareTunnel(options.company.companyId, tunnelRoutes),
45
47
  module.exports.prepareTunnel(),
46
48
  ]);
47
49
  tunnelId = result._id;
48
50
  tunnelProcess = childProcess.spawn(TUNNEL_BINARY_LOCATION, ['tunnel', '--no-autoupdate', 'run', '--force', '--token', result.token], { stdio: 'inherit' });
49
51
  await servicesApi.forceUpdateCloudflareTunnelRoutes(options.company.companyId, tunnelId);
50
- await fse.writeFileSync(options.tunnelRoutesOutput, JSON.stringify(result.routesMapping, null, 2));
52
+
53
+ if (options.tunnelRoutesOutput) {
54
+ await fse.writeFileSync(options.tunnelRoutesOutput, JSON.stringify(result.routesMapping, null, 2));
55
+ }
56
+
57
+ options.baseUrl = `${options.tunnelUseHttpAddress ? 'http' : 'https'}://${result.routesMapping[tunnelBaseUrl]}`;
51
58
  };
52
59
 
53
60
  const disconnectTunnel = async (options) => {
@@ -43,7 +43,7 @@ describe('testimCloudflare', () => {
43
43
  killStub = sandbox.stub(processMock, 'kill').callThrough();
44
44
  sandbox.stub(childProcess, 'spawn').returns(processMock);
45
45
  sandbox.stub(testimCloudflare, 'prepareTunnel');
46
- sandbox.stub(servicesApi, 'getCloudflareTunnel').resolves({ _id: utils.guid() });
46
+ sandbox.stub(servicesApi, 'getCloudflareTunnel').resolves({ _id: utils.guid(), routesMapping: {} });
47
47
  sandbox.stub(servicesApi, 'forceUpdateCloudflareTunnelRoutes');
48
48
  sandbox.stub(fse, 'writeFileSync');
49
49
  });
@@ -127,7 +127,7 @@ describe('testimCloudflare', () => {
127
127
  let tunnelData;
128
128
 
129
129
  beforeEach(() => {
130
- tunnelData = { _id: utils.guid(), token: utils.guid() };
130
+ tunnelData = { _id: utils.guid(), token: utils.guid(), routesMapping: {} };
131
131
  prepareTunnelStub = sandbox.stub(testimCloudflare, 'prepareTunnel');
132
132
  getCloudflareTunnelStub = sandbox.stub(servicesApi, 'getCloudflareTunnel').resolves(tunnelData);
133
133
  forceUpdateCloudflareTunnelRoutesStub = sandbox.stub(servicesApi, 'forceUpdateCloudflareTunnelRoutes');
@@ -154,9 +154,32 @@ describe('testimCloudflare', () => {
154
154
 
155
155
  it('should write the tunnel data to a file', async () => {
156
156
  tunnelData.routesMapping = utils.guid();
157
- await testimCloudflare.connectTunnel({ company: {} });
157
+ await testimCloudflare.connectTunnel({ company: {}, tunnelRoutesOutput: 'test.json' });
158
158
  sinon.assert.calledOnce(writeFileSyncStub);
159
+ expect(writeFileSyncStub.args[0][0]).to.eql('test.json');
159
160
  expect(writeFileSyncStub.args[0][1]).to.eql(JSON.stringify(tunnelData.routesMapping));
160
161
  });
162
+
163
+ it('should set the baseUrl to the tunneled url', async () => {
164
+ tunnelData.routesMapping = { 'http://localhost:80': utils.guid() };
165
+ const opts = { company: {} };
166
+ await testimCloudflare.connectTunnel(opts);
167
+ expect(opts.baseUrl).to.eql(`https://${tunnelData.routesMapping['http://localhost:80']}`);
168
+ });
169
+
170
+ it('should set the baseUrl to the tunneled url, overriding an existing baseURL', async () => {
171
+ const baseUrl = utils.guid();
172
+ tunnelData.routesMapping = { [baseUrl]: utils.guid() };
173
+ const opts = { company: {}, baseUrl };
174
+ await testimCloudflare.connectTunnel(opts);
175
+ expect(opts.baseUrl).to.eql(`https://${tunnelData.routesMapping[baseUrl]}`);
176
+ });
177
+
178
+ it('should set the baseUrl considering tunnelUseHttpAddress', async () => {
179
+ tunnelData.routesMapping = { 'http://localhost:80': utils.guid() };
180
+ const opts = { company: {}, tunnelUseHttpAddress: true };
181
+ await testimCloudflare.connectTunnel(opts);
182
+ expect(opts.baseUrl).to.eql(`http://${tunnelData.routesMapping['http://localhost:80']}`);
183
+ });
161
184
  });
162
185
  });
@@ -185,6 +185,7 @@ function _buildChromiumOptions(opts, browserOptions, testRunConfig, customExtens
185
185
  'profile.content_settings.exceptions.clipboard': {
186
186
  '[*.],*': { last_modified: Date.now(), setting: 1 },
187
187
  },
188
+ 'download.allow_office_viewer_for_download': false,
188
189
  },
189
190
  w3c: isW3CMode(),
190
191
  };
@@ -20,7 +20,7 @@ function getTokenHeader() {
20
20
  return testimCustomToken.getCustomTokenV3()
21
21
  .then(brearToken => {
22
22
  if (!brearToken) {
23
- return Promise.reject(new Error('Failed to get token from server'));
23
+ throw new Error('Failed to get token from server');
24
24
  }
25
25
  return { Authorization: `Bearer ${brearToken}` };
26
26
  });
@@ -386,6 +386,19 @@ function uploadArtifact(projectId, testId, testResultId, content, subType, mimeT
386
386
  })).then(() => storagePath);
387
387
  }
388
388
 
389
+ const removeHiddenParamsInTestData = (testData, projectDefaults) => {
390
+ const testDataValueClone = _.clone(testData);
391
+ if (projectDefaults && projectDefaults.hiddenParams) {
392
+ const { hiddenParams } = projectDefaults;
393
+ (hiddenParams || []).forEach((param) => {
394
+ if (testDataValueClone[param]) {
395
+ testDataValueClone[param] = constants.test.HIDDEN_PARAM;
396
+ }
397
+ });
398
+ }
399
+ return testDataValueClone;
400
+ };
401
+
389
402
  const uploadRunDataArtifact = _.memoize(async (projectId, testId, testResultId, runData) => {
390
403
  if (_.isEmpty(runData)) {
391
404
  return undefined;
@@ -397,20 +410,8 @@ const updateTestDataArtifact = _.memoize(async (projectId, testId, testResultId,
397
410
  if (_.isEmpty(testData)) {
398
411
  return undefined;
399
412
  }
400
- const removeHiddenParamsInTestData = () => {
401
- const testDataValueClone = _.clone(testData);
402
- if (projectDefaults && projectDefaults.hiddenParams) {
403
- const { hiddenParams } = projectDefaults;
404
- (hiddenParams || []).forEach((param) => {
405
- if (testDataValueClone[param]) {
406
- testDataValueClone[param] = constants.test.HIDDEN_PARAM;
407
- }
408
- });
409
- }
410
- return testDataValueClone;
411
- };
412
413
 
413
- return await uploadArtifact(projectId, testId, testResultId, JSON.stringify(removeHiddenParamsInTestData(testData)), 'test-test-data', 'application/json');
414
+ return await uploadArtifact(projectId, testId, testResultId, JSON.stringify(removeHiddenParamsInTestData(testData, projectDefaults)), 'test-test-data', 'application/json');
414
415
  }, (projectId, testId, testResultId, testData) => `${hash(testData)}:${testId}:${testResultId}`);
415
416
 
416
417
  function addTestRetry({
@@ -510,4 +511,5 @@ module.exports = {
510
511
  getCloudflareTunnel,
511
512
  forceUpdateCloudflareTunnelRoutes,
512
513
  deleteCloudflareTunnel,
514
+ removeHiddenParamsInTestData,
513
515
  };
@@ -10,7 +10,8 @@ const testimNgrok = require('./testimNgrok');
10
10
  const testimCloudflare = require('./testimCloudflare');
11
11
  const logger = require('./logger').getLogger('tunnel');
12
12
 
13
- const shouldUseLambdatestTunnel = options => [gridTypes.LAMBDATEST, gridTypes.HYBRID].includes(options.gridData && options.gridData.type) && options.gridData.tunnel !== 'ngrok';
13
+ const shouldUseLambdatestTunnel = options => [gridTypes.LAMBDATEST, gridTypes.HYBRID].includes(options.gridData && options.gridData.type) && options.gridData.tunnel === 'lambdatest';
14
+ const shouldUseCloudflareTunnel = options => options.tunnelRoutes || (options.gridData && options.gridData.type === gridTypes.HYBRID && options.gridData.tunnel === 'cloudflare');
14
15
 
15
16
  const connect = async (options) => {
16
17
  if (!options.tunnel) {
@@ -23,7 +24,7 @@ const connect = async (options) => {
23
24
  if (shouldUseLambdatestTunnel(options)) {
24
25
  spinner = ora('Starting testim lambdatest tunnel...').start();
25
26
  await LambdatestService.connectTunnel(options);
26
- } else if (options.tunnelRoutes) {
27
+ } else if (shouldUseCloudflareTunnel(options)) {
27
28
  spinner = ora('Starting testim cloudflare tunnel...').start();
28
29
  await testimCloudflare.connectTunnel(options);
29
30
  } else {
@@ -44,14 +44,14 @@ describe('testimTunnel', () => {
44
44
  });
45
45
 
46
46
  it('should choose lambdatest if passed grid is a lambdatest grid', async () => {
47
- await testimTunnel.connect({ tunnel: true, gridData: { type: 'testimLambdaTest' } });
47
+ await testimTunnel.connect({ tunnel: true, gridData: { type: 'testimLambdaTest', tunnel: 'lambdatest' } });
48
48
  sinon.assert.calledOnce(ltConnectStub);
49
49
  sinon.assert.notCalled(ngrokConnectStub);
50
50
  sinon.assert.notCalled(cloudflareConnectStub);
51
51
  });
52
52
 
53
53
  it('should choose lambdatest if passed grid is a hybrid grid', async () => {
54
- await testimTunnel.connect({ tunnel: true, gridData: { type: 'testimHybrid' } });
54
+ await testimTunnel.connect({ tunnel: true, gridData: { type: 'testimHybrid', tunnel: 'lambdatest' } });
55
55
  sinon.assert.calledOnce(ltConnectStub);
56
56
  sinon.assert.notCalled(ngrokConnectStub);
57
57
  sinon.assert.notCalled(cloudflareConnectStub);
@@ -66,7 +66,7 @@ describe('testimTunnel', () => {
66
66
 
67
67
  it('should handle connect errors', async () => {
68
68
  ltConnectStub.rejects('error');
69
- await expect(testimTunnel.connect({ tunnel: true, gridData: { type: 'testimLambdaTest' } })).to.be.rejectedWith('Failed to start tunnel. Please contact support@testim.io');
69
+ await expect(testimTunnel.connect({ tunnel: true, gridData: { type: 'testimLambdaTest', tunnel: 'lambdatest' } })).to.be.rejectedWith('Failed to start tunnel. Please contact support@testim.io');
70
70
  });
71
71
  });
72
72
 
@@ -108,14 +108,14 @@ describe('testimTunnel', () => {
108
108
  });
109
109
 
110
110
  it('should choose lambdatest if passed grid is a lambdatest grid', async () => {
111
- await testimTunnel.disconnect({ tunnel: true, gridData: { type: 'testimLambdaTest' } });
111
+ await testimTunnel.disconnect({ tunnel: true, gridData: { type: 'testimLambdaTest', tunnel: 'lambdatest' } });
112
112
  sinon.assert.calledOnce(ltDisconnectStub);
113
113
  sinon.assert.notCalled(ngrokDisconnectStub);
114
114
  sinon.assert.notCalled(cloudflareDisconnectStub);
115
115
  });
116
116
 
117
117
  it('should choose lambdatest if passed grid is a hybrid grid', async () => {
118
- await testimTunnel.disconnect({ tunnel: true, gridData: { type: 'testimHybrid' } });
118
+ await testimTunnel.disconnect({ tunnel: true, gridData: { type: 'testimHybrid', tunnel: 'lambdatest' } });
119
119
  sinon.assert.calledOnce(ltDisconnectStub);
120
120
  sinon.assert.notCalled(ngrokDisconnectStub);
121
121
  sinon.assert.notCalled(cloudflareDisconnectStub);
@@ -130,7 +130,7 @@ describe('testimTunnel', () => {
130
130
 
131
131
  it('should handle connect errors', async () => {
132
132
  ltDisconnectStub.rejects('error');
133
- await expect(testimTunnel.disconnect({ tunnel: true, gridData: { type: 'testimLambdaTest' } })).to.be.rejectedWith('catch error - failed to close tunnel');
133
+ await expect(testimTunnel.disconnect({ tunnel: true, gridData: { type: 'testimLambdaTest', tunnel: 'lambdatest' } })).to.be.rejectedWith('catch error - failed to close tunnel');
134
134
  });
135
135
  });
136
136