Skip to content

Commit c29eba3

Browse files
authored
Merge pull request #12 from pinanks/convert-to-commonjs
Convert to commonjs
2 parents d27c9e4 + c7557da commit c29eba3

File tree

11 files changed

+72
-51
lines changed

11 files changed

+72
-51
lines changed

packages/sdk-utils/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { isSmartUIRunning, fetchDOMSerializer, postSnapshot } from './src/smartui.js'
2-
import logger from './src/lib/logger.js'
1+
const { isSmartUIRunning, fetchDOMSerializer, postSnapshot } = require('./src/smartui');
2+
const logger = require('./src/lib/logger');
33

4-
export default {
4+
module.exports = {
55
logger,
66
fetchDOMSerializer,
77
postSnapshot,

packages/sdk-utils/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"url": "git+https://github.com/LambdaTest/lambdatest-js-sdk",
99
"directory": "packages/sdk-utils"
1010
},
11-
"type": "module",
1211
"scripts": {
1312
"test": "echo \"Error: no test specified\" && exit 1"
1413
},
@@ -19,7 +18,7 @@
1918
"license": "MIT",
2019
"dependencies": {
2120
"axios": "^1.6.2",
22-
"chalk": "^5.3.0",
21+
"chalk": "4",
2322
"winston": "^3.11.0"
2423
}
2524
}

packages/sdk-utils/src/lib/httpClient.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import axios from 'axios'
2-
import utils from './utils.js'
1+
const axios = require('axios');
2+
const utils = require('./utils');
33

4-
class httpClient {
4+
module.exports = new class httpClient {
55
async request(config) {
66
return axios.request(config)
77
.then(resp => {
@@ -47,6 +47,4 @@ class httpClient {
4747
}
4848
})
4949
}
50-
}
51-
52-
export default new httpClient();
50+
};

packages/sdk-utils/src/lib/logger.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { createLogger, transports, format, config } from 'winston'
2-
import chalk from 'chalk'
1+
const { createLogger, transports, format } = require('winston');
2+
const chalk = require('chalk');
33

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

9-
export default (logContext) => {
9+
module.exports = function logger(logContext) {
1010
return createLogger({
1111
level: logLevel(),
1212
format: format.combine(

packages/sdk-utils/src/lib/utils.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
import fs from 'fs';
2-
import { fileURLToPath } from 'url';
3-
import { dirname, join } from 'path';
4-
5-
export function getSmartUIServerAddress() {
1+
function getSmartUIServerAddress() {
62
return process.env.SMARTUI_SERVER_ADDRESS || 'http://localhost:8080'
73
}
84

9-
export function getPackageName() {
10-
return JSON.parse(fs.readFileSync(join(dirname(fileURLToPath(import.meta.url)), '../../package.json'), 'utf-8')).name
11-
}
12-
13-
export * as default from './utils.js';
5+
module.exports = {
6+
getSmartUIServerAddress
7+
};

packages/sdk-utils/src/smartui.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import client from './lib/httpClient.js'
2-
import logger from './lib/logger.js'
3-
import utils from './lib/utils.js'
4-
const log = logger(utils.getPackageName())
1+
const client = require('./lib/httpClient');
2+
const logger = require('./lib/logger');
3+
const utils = require('./lib/utils');
4+
const log = logger(require('../package.json').name);
55

6-
export async function isSmartUIRunning() {
6+
async function isSmartUIRunning() {
77
try {
88
await client.isSmartUIRunning();
99
return true;
@@ -13,7 +13,7 @@ export async function isSmartUIRunning() {
1313
}
1414
}
1515

16-
export async function fetchDOMSerializer() {
16+
async function fetchDOMSerializer() {
1717
try {
1818
return await client.fetchDOMSerializer();
1919
} catch (error) {
@@ -22,7 +22,7 @@ export async function fetchDOMSerializer() {
2222
}
2323
}
2424

25-
export async function postSnapshot(snapshotDOM, snapshotName, testType) {
25+
async function postSnapshot(snapshotDOM, snapshotName, testType) {
2626
const data = JSON.stringify({
2727
snapshot: {
2828
dom: snapshotDOM,
@@ -38,3 +38,9 @@ export async function postSnapshot(snapshotDOM, snapshotName, testType) {
3838
throw new Error(`post snapshot failed`);
3939
}
4040
}
41+
42+
module.exports = {
43+
isSmartUIRunning,
44+
fetchDOMSerializer,
45+
postSnapshot
46+
}

packages/selenium-driver/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { smartuiSnapshot } from './src/smartui.js';
1+
const { smartuiSnapshot } = require('./src/smartui');
22

3-
export {
3+
module.exports = {
44
smartuiSnapshot
5-
};
5+
}

packages/selenium-driver/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"scripts": {
1212
"test": "echo \"Error: no test specified\" && exit 1"
1313
},
14-
"type": "module",
1514
"keywords": [
1615
"lambdatest",
1716
"selenium"

packages/selenium-driver/src/smartui.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import utils from '@lambdatest/sdk-utils'
2-
import { getPackageName } from './utils.js';
3-
const pkgName = getPackageName()
1+
const utils = require('@lambdatest/sdk-utils');
2+
const pkgName = require('../package.json').name;
43

5-
export async function smartuiSnapshot(driver, snapshotName) {
4+
async function smartuiSnapshot(driver, snapshotName) {
65
// TODO: check if driver is selenium webdriver object
76
if (!driver) throw new Error('An instance of the selenium driver object is required.');
87
if (!snapshotName) throw new Error('The `snapshotName` argument is required.');
@@ -23,3 +22,7 @@ export async function smartuiSnapshot(driver, snapshotName) {
2322
throw new Error(error);
2423
}
2524
}
25+
26+
module.exports = {
27+
smartuiSnapshot
28+
}

packages/selenium-driver/src/utils.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)