Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/sdk-utils/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isSmartUIRunning, fetchDOMSerializer, postSnapshot } from './src/smartui.js'
import logger from './src/lib/logger.js'
const { isSmartUIRunning, fetchDOMSerializer, postSnapshot } = require('./src/smartui');
const logger = require('./src/lib/logger');

export default {
module.exports = {
logger,
fetchDOMSerializer,
postSnapshot,
Expand Down
3 changes: 1 addition & 2 deletions packages/sdk-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"url": "git+https://github.com/LambdaTest/lambdatest-js-sdk",
"directory": "packages/sdk-utils"
},
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand All @@ -19,7 +18,7 @@
"license": "MIT",
"dependencies": {
"axios": "^1.6.2",
"chalk": "^5.3.0",
"chalk": "4",
"winston": "^3.11.0"
}
}
10 changes: 4 additions & 6 deletions packages/sdk-utils/src/lib/httpClient.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios'
import utils from './utils.js'
const axios = require('axios');
const utils = require('./utils');

class httpClient {
module.exports = new class httpClient {
async request(config) {
return axios.request(config)
.then(resp => {
Expand Down Expand Up @@ -47,6 +47,4 @@ class httpClient {
}
})
}
}

export default new httpClient();
};
6 changes: 3 additions & 3 deletions packages/sdk-utils/src/lib/logger.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createLogger, transports, format, config } from 'winston'
import chalk from 'chalk'
const { createLogger, transports, format } = require('winston');
const chalk = require('chalk');

const logLevel = () => {
let debug = (process.env.LT_SDK_DEBUG === 'true') ? 'debug' : undefined;
return debug || process.env.LT_SDK_LOG_LEVEL || 'info'
}

export default (logContext) => {
module.exports = function logger(logContext) {
return createLogger({
level: logLevel(),
format: format.combine(
Expand Down
14 changes: 4 additions & 10 deletions packages/sdk-utils/src/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import fs from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';

export function getSmartUIServerAddress() {
function getSmartUIServerAddress() {
return process.env.SMARTUI_SERVER_ADDRESS || 'http://localhost:8080'
}

export function getPackageName() {
return JSON.parse(fs.readFileSync(join(dirname(fileURLToPath(import.meta.url)), '../../package.json'), 'utf-8')).name
}

export * as default from './utils.js';
module.exports = {
getSmartUIServerAddress
};
20 changes: 13 additions & 7 deletions packages/sdk-utils/src/smartui.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import client from './lib/httpClient.js'
import logger from './lib/logger.js'
import utils from './lib/utils.js'
const log = logger(utils.getPackageName())
const client = require('./lib/httpClient');
const logger = require('./lib/logger');
const utils = require('./lib/utils');
const log = logger(require('../package.json').name);

export async function isSmartUIRunning() {
async function isSmartUIRunning() {
try {
await client.isSmartUIRunning();
return true;
Expand All @@ -13,7 +13,7 @@ export async function isSmartUIRunning() {
}
}

export async function fetchDOMSerializer() {
async function fetchDOMSerializer() {
try {
return await client.fetchDOMSerializer();
} catch (error) {
Expand All @@ -22,7 +22,7 @@ export async function fetchDOMSerializer() {
}
}

export async function postSnapshot(snapshotDOM, snapshotName, testType) {
async function postSnapshot(snapshotDOM, snapshotName, testType) {
const data = JSON.stringify({
snapshot: {
dom: snapshotDOM,
Expand All @@ -38,3 +38,9 @@ export async function postSnapshot(snapshotDOM, snapshotName, testType) {
throw new Error(`post snapshot failed`);
}
}

module.exports = {
isSmartUIRunning,
fetchDOMSerializer,
postSnapshot
}
6 changes: 3 additions & 3 deletions packages/selenium-driver/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { smartuiSnapshot } from './src/smartui.js';
const { smartuiSnapshot } = require('./src/smartui');

export {
module.exports = {
smartuiSnapshot
};
}
1 change: 0 additions & 1 deletion packages/selenium-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"type": "module",
"keywords": [
"lambdatest",
"selenium"
Expand Down
11 changes: 7 additions & 4 deletions packages/selenium-driver/src/smartui.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import utils from '@lambdatest/sdk-utils'
import { getPackageName } from './utils.js';
const pkgName = getPackageName()
const utils = require('@lambdatest/sdk-utils');
const pkgName = require('../package.json').name;

export async function smartuiSnapshot(driver, snapshotName) {
async function smartuiSnapshot(driver, snapshotName) {
// TODO: check if driver is selenium webdriver object
if (!driver) throw new Error('An instance of the selenium driver object is required.');
if (!snapshotName) throw new Error('The `snapshotName` argument is required.');
Expand All @@ -23,3 +22,7 @@ export async function smartuiSnapshot(driver, snapshotName) {
throw new Error(error);
}
}

module.exports = {
smartuiSnapshot
}
7 changes: 0 additions & 7 deletions packages/selenium-driver/src/utils.js

This file was deleted.

39 changes: 34 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.