Skip to content

Commit 3955b5a

Browse files
Merge pull request #59 from Shahnawaz-Sk/master
removing node-rest-client deps
2 parents 27726ba + 932cfd8 commit 3955b5a

File tree

8 files changed

+9170
-3360
lines changed

8 files changed

+9170
-3360
lines changed

package-lock.json

Lines changed: 9090 additions & 3330 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wdio-lambdatest-service",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"description": "A WebdriverIO service that manages tunnel and job metadata for LambdaTest.",
55
"author": "LambdaTest <[email protected]>",
66
"contributors": [
@@ -46,10 +46,10 @@
4646
"url": "https://github.com/LambdaTest/wdio-lambdatest-service/issues"
4747
},
4848
"dependencies": {
49-
"@lambdatest/node-rest-client": "^1.0.5",
5049
"@lambdatest/node-tunnel": "^4.0.1",
5150
"@wdio/logger": "^7.0.0",
5251
"colors": "^1.4.0",
52+
"form-data": "^4.0.0",
5353
"source-map-support": "^0.5.21"
5454
},
5555
"peerDependencies": {

src/constants.d.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1-
export declare const TUNNEL_STOP_FAILED: string;
2-
export declare const TUNNEL_START_FAILED: string;
3-
export declare const TUNNEL_STOP_TIMEOUT: number;
1+
declare module 'constants' {
2+
export const version: {
3+
latestVersion: string;
4+
supportedVersions: string[];
5+
};
6+
7+
export const appVersion: {
8+
latestVersion: string;
9+
supportedVersions: string[];
10+
};
11+
12+
export const baseUrl: string;
13+
14+
export const baseUrlApp: string;
15+
16+
export const TUNNEL_STOP_FAILED: string;
17+
export const TUNNEL_START_FAILED: string;
18+
}
19+

src/constants.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
export const TUNNEL_STOP_FAILED = 'LambdaTest Tunnel failed to stop within 60 seconds!'
2-
export const TUNNEL_START_FAILED = 'LambdaTest Tunnel failed to start within 60 seconds!'
3-
export const TUNNEL_STOP_TIMEOUT = 60000
1+
module.exports = {
2+
version: { latestVersion: "v1", supportedVersions: ["v1"] },
3+
appVersion: { latestVersion: "v1", supportedVersions: ["v1"] },
4+
baseUrl: "https://api.lambdatest.com/automation/api/",
5+
baseUrlApp: "https://mobile-api.lambdatest.com/mobile-automation/api/",
6+
TUNNEL_STOP_FAILED: "LambdaTest Tunnel failed to stop within 60 seconds!",
7+
TUNNEL_START_FAILED :"LambdaTest Tunnel failed to start within 60 seconds!",
8+
TUNNEL_STOP_TIMEOUT:60000
9+
};

src/service.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import LambdaRestClient from '@lambdatest/node-rest-client'
21
import logger from '@wdio/logger'
32

4-
import { getParentSuiteName } from './util.js'
3+
import { getParentSuiteName, updateSessionById } from './util.js'
54

65
const log = logger('@wdio/lambdatest-service')
76

@@ -29,6 +28,7 @@ export default class LambdaRestService {
2928
_testTitle;
3029
_error;
3130
_ltErrorRemark;
31+
_lambdaCredentials;
3232

3333
constructor(options = {}, capabilities = {}, config = {}) {
3434
this._options = { ...DEFAULT_OPTIONS, ...options };
@@ -71,12 +71,8 @@ export default class LambdaRestService {
7171
}
7272

7373
this._isServiceEnabled = lambdaCredentials.username && lambdaCredentials.accessKey;
74-
75-
try {
76-
this._api = LambdaRestClient.AutomationClient(lambdaCredentials);
77-
} catch (_) {
78-
this._isServiceEnabled = false;
79-
}
74+
this._lambdaCredentials=lambdaCredentials;
75+
8076
}
8177

8278
async beforeScenario(world, context) {
@@ -273,18 +269,7 @@ export default class LambdaRestService {
273269
{
274270
await this._setSessionRemarks(this._error);
275271
}
276-
277-
await new Promise((resolve, reject) => {
278-
if (!this._api) {
279-
return reject(new Error('LambdaTest service is not enabled'));
280-
}
281-
this._api.updateSessionById(sessionId, body, (err, result) => {
282-
if (err) {
283-
return reject(err);
284-
}
285-
return resolve(result);
286-
});
287-
});
272+
await updateSessionById(sessionId, body, this._lambdaCredentials);
288273
} catch (ex) {
289274
console.log(ex);
290275
}

src/util.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@
55
* @returns
66
*/
77
export declare function getParentSuiteName(fullTitle: string, testSuiteTitle: string): string;
8+
9+
/**
10+
* Updates the session using sessionId
11+
* @param {string} sessionId
12+
* @param {any} data
13+
* @param {any} lambdaCredentials
14+
* @returns
15+
*/
16+
export declare function updateSessionById(sessionId: string, data: any, lambdaCredentials: any, callback: any): Promise<void>;

src/util.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
const axios = require('axios');
2+
const { version, appVersion, baseUrl, baseUrlApp } = require("./constants.js");
3+
14
/**
25
* [Jasmine only] Get the parent suite name of a test
36
* @param {string} fullTitle
@@ -15,3 +18,34 @@ export function getParentSuiteName(fullTitle, testSuiteTitle) {
1518
}
1619
return parentSuiteName.trim();
1720
}
21+
22+
/**
23+
* Updates the session using sessionId
24+
* @param {string} sessionId
25+
* @param {any} data
26+
* @param {any} lambdaCredentials
27+
* @returns
28+
*/
29+
export async function updateSessionById(sessionId, data, lambdaCredentials){
30+
const sessionUrl = lambdaCredentials.isApp ? `${baseUrlApp}${appVersion.latestVersion}/sessions/${sessionId}` : `${baseUrl}${version.latestVersion}/sessions/${sessionId}`;
31+
let config = {
32+
method: 'patch',
33+
maxBodyLength: Infinity,
34+
url: sessionUrl,
35+
headers: {
36+
'accept': 'application/json',
37+
'Authorization': `Basic ${Buffer.from(lambdaCredentials.username + ':' + lambdaCredentials.accessKey).toString('base64')}`,
38+
'Content-Type': 'application/json'
39+
},
40+
data: data
41+
};
42+
try {
43+
let response = await axios.request(config);
44+
if (process.env.LT_CLIENT_LOG === "true"){
45+
console.log(response);
46+
}
47+
} catch (error) {
48+
console.error(error);
49+
}
50+
}
51+

tests/service.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import path from 'path'
2-
import request from 'request'
2+
33
import { describe, expect, it, test, vi } from 'vitest'
44
import LambdaTestService from '../src/service.js'
55

66
process.env.LT_USERNAME = process.env.LT_USERNAME ?? 'foo'
77
process.env.LT_ACCESS_KEY = process.env.LT_ACCESS_KEY ?? 'bar'
88

9-
vi.mock('request')
9+
1010
vi.mock('@wdio/logger', () => import(path.join(process.cwd(), '__mocks__', '@wdio/logger')))
1111

1212
const browser = {

0 commit comments

Comments
 (0)