-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from LambdaTest/stage
Release JS packages
- Loading branch information
Showing
14 changed files
with
542 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Publish JS packages | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
build-and-publish: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '16' | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Install pnpm | ||
run: npm install -g pnpm | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Publish packages | ||
run: pnpm publish --recursive --access public --no-git-checks | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { isSmartUIRunning, fetchDOMSerializer, postSnapshot } from './src/smartui.js' | ||
import logger from './src/lib/logger.js' | ||
|
||
export default { | ||
logger, | ||
fetchDOMSerializer, | ||
postSnapshot, | ||
isSmartUIRunning | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "@lambdatest/sdk-utils", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/LambdaTest/lambdatet-sdk", | ||
"directory": "js/packages/sdk-utils" | ||
}, | ||
"type": "module", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"lambdatest" | ||
], | ||
"author": "LambdaTest <keys@lambdatest.com>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"axios": "^1.6.2", | ||
"chalk": "^5.3.0", | ||
"winston": "^3.11.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import axios from 'axios' | ||
import utils from './utils.js' | ||
|
||
class httpClient { | ||
async request(config) { | ||
return axios.request(config) | ||
.then(resp => { | ||
return { | ||
status: resp.status, | ||
statusMessage: resp.statusMessage, | ||
headers: resp.headers, | ||
body: resp.data | ||
}; | ||
}) | ||
.catch(error => { | ||
if (error.response) { | ||
throw new Error(JSON.stringify(error.response.data)); | ||
} | ||
if (error.request) { | ||
throw new Error(error.toJSON().message); | ||
} | ||
throw error; | ||
}); | ||
} | ||
|
||
isSmartUIRunning() { | ||
return this.request({ | ||
url: `${utils.getSmartUIServerAddress()}/healthcheck`, | ||
method: 'GET', | ||
}) | ||
} | ||
|
||
fetchDOMSerializer() { | ||
return this.request({ | ||
url: `${utils.getSmartUIServerAddress()}/domserializer`, | ||
method: 'GET' | ||
}) | ||
} | ||
|
||
postSnapshot(data) { | ||
return this.request({ | ||
url: `${utils.getSmartUIServerAddress()}/snapshot`, | ||
method: 'POST', | ||
data: data, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
} | ||
}) | ||
} | ||
} | ||
|
||
export default new httpClient(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { createLogger, transports, format, config } from 'winston' | ||
import chalk from '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) => { | ||
return createLogger({ | ||
level: logLevel(), | ||
format: format.combine( | ||
format.timestamp(), | ||
format.printf(({ message, level }) => { | ||
if (typeof message === 'object') { | ||
message = JSON.stringify(message); | ||
} | ||
switch (level) { | ||
case 'debug': | ||
message = chalk.blue(message); | ||
break; | ||
case 'warn': | ||
message = chalk.yellow(message); | ||
break; | ||
case 'error': | ||
message = chalk.red(message); | ||
break; | ||
} | ||
return `[${logContext}] ${message}`; | ||
}) | ||
), | ||
transports: [new transports.Console()] | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import fs from 'fs'; | ||
import { fileURLToPath } from 'url'; | ||
import { dirname, join } from 'path'; | ||
|
||
export 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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import client from './lib/httpClient.js' | ||
import logger from './lib/logger.js' | ||
import utils from './lib/utils.js' | ||
const log = logger(utils.getPackageName()) | ||
|
||
export async function isSmartUIRunning() { | ||
try { | ||
await client.isSmartUIRunning(); | ||
return true; | ||
} catch (error) { | ||
log.debug(error); | ||
return false; | ||
} | ||
} | ||
|
||
export async function fetchDOMSerializer() { | ||
try { | ||
return await client.fetchDOMSerializer(); | ||
} catch (error) { | ||
log.debug(error); | ||
throw new Error(`fetch DOMSerializer failed`); | ||
} | ||
} | ||
|
||
export async function postSnapshot(snapshotDOM, snapshotName, testType) { | ||
const data = JSON.stringify({ | ||
snapshot: { | ||
dom: snapshotDOM, | ||
name: snapshotName | ||
}, | ||
testType | ||
}); | ||
|
||
try { | ||
return await client.postSnapshot(data); | ||
} catch (error) { | ||
log.debug(error); | ||
throw new Error(`post snapshot failed`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { smartuiSnapshot } from './src/smartui.js'; | ||
|
||
export { | ||
smartuiSnapshot | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "@lambdatest/selenium-driver", | ||
"version": "1.0.0", | ||
"description": "Selenium driver for all Lambdatest functionalities", | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/LambdaTest/lambdatet-sdk", | ||
"directory": "js/packages/selenium-driver" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"type": "module", | ||
"keywords": [ | ||
"lambdatest", | ||
"selenium" | ||
], | ||
"author": "LambdaTest <keys@lambdatest.com>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@lambdatest/sdk-utils": "workspace:^" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import utils from '@lambdatest/sdk-utils' | ||
import { getPackageName } from './utils.js'; | ||
const pkgName = getPackageName() | ||
|
||
export 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.'); | ||
if (!(await utils.isSmartUIRunning())) throw new Error('SmartUI server is not running.'); | ||
let log = utils.logger(pkgName); | ||
|
||
try { | ||
let resp = await utils.fetchDOMSerializer(); | ||
await driver.executeScript(resp.body.data.dom); | ||
|
||
let { dom } = await driver.executeScript(options => ({ | ||
dom: SmartUIDOM.serialize(options) | ||
}), {}); | ||
|
||
await utils.postSnapshot(dom.html, snapshotName, pkgName); | ||
log.info(`Snapshot captured: ${snapshotName}`); | ||
} catch (error) { | ||
throw new Error(error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import fs from 'fs'; | ||
import { fileURLToPath } from 'url'; | ||
import { dirname, join } from 'path'; | ||
|
||
export function getPackageName() { | ||
return JSON.parse(fs.readFileSync(join(dirname(fileURLToPath(import.meta.url)), '../package.json'), 'utf-8')).name | ||
} |
Oops, something went wrong.