Socket
Socket
Sign inDemoInstall

@percy/sdk-utils

Package Overview
Dependencies
Maintainers
6
Versions
215
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@percy/sdk-utils - npm Package Compare versions

Comparing version 1.0.0-beta.42 to 1.0.0-beta.43

dist/bundle.js

39

package.json
{
"name": "@percy/sdk-utils",
"version": "1.0.0-beta.42",
"version": "1.0.0-beta.43",
"license": "MIT",
"main": "index.js",
"main": "dist/index.js",
"browser": "dist/bundle.js",
"files": [
"index.js",
"test/helper.js"
"dist",
"test/helpers.js",
"test/server.js",
"test/client.js"
],

@@ -14,2 +17,3 @@ "engines": {

"scripts": {
"build": "node ../../scripts/build",
"lint": "eslint --ignore-path ../../.gitignore .",

@@ -22,6 +26,29 @@ "test": "node ../../scripts/test",

},
"karma": {
"run_start": "node test/server start &",
"run_complete": "node test/server stop"
},
"rollup": {
"external": [
"ws"
],
"output": {
"name": "PercySDKUtils"
},
"test": {
"external": [
"@percy/logger",
"test/server"
],
"output": {
"globals": {
"@percy/logger": "PercySDKUtils.logger"
}
}
}
},
"dependencies": {
"@percy/logger": "^1.0.0-beta.42"
"@percy/logger": "^1.0.0-beta.43"
},
"gitHead": "1feffb5149eff71114ea583e10c098f75f497544"
"gitHead": "4eb85cf34665859cfd6dd2d3d09b1089e5f70144"
}

95

README.md
# @percy/sdk-utils
Common Node SDK utils
Common JavaScript SDK utils
- [Usage](#usage)
- [`logger()`](#loggerdebug)
- [`getInfo()`](#getinfo)
- [`percy`](#percy)
- [`isPercyEnabled()`](#ispercyenabled)
- [`postSnapshot()`](#postsnapshot)
- [`request`](#requesturl-options)

@@ -17,33 +18,35 @@ ## Usage

### `getInfo()`
### `percy`
Returns information about any running Percy CLI server. Some information is only available after
[`isPercyEnabled`](#ispercyenabled) has been called.
This object contains information about the local Percy environment and is updated when
[`isPercyEnabled`](#ispercyenabled) is called for the first time.
``` js
const { getInfo } = require('@percy/sdk-utils');
const { percy } = require('@percy/sdk-utils')
const { cliApi, loglevel, version, config } = getInfo();
```
// reflects/updates process.env.PERCY_SERVER_ADDRESS
percy.address === 'http://localhost:5338'
#### Returned properties
// updated after isPercyEnabled() is called
percy.enabled === true|false
percy.version.major === 1
percy.version.minor === 2
percy.version.patch === 3
percy.version.toString() === '1.2.3'
percy.config === {} // .percy.yml config
- `cliApi` — CLI API address (`process.env.PERCY_CLI_API || 'http://localhost:5338'`)
- `loglevel` — CLI log level (`process.env.PERCY_LOGLEVEL || 'info'`)
// updated after fetchPercyDOM() is called
percy.domScript === fs.readFile(require.resolve('@percy/dom'))
```
The following properties are only populated after [`isPercyEnabled`](#ispercyenabled) has been
called.
- `version` — CLI version parts (e.g. `['1', '0', '0']`)
- `config` — CLI config options
### `isPercyEnabled()`
Returns `true` or `false` if the Percy CLI API server is running. Calls the server's `/healthcheck`
endpoint and populates information for [`getInfo`](#getInfo). The result of this function is cached
and subsequent calls will return the first cached result. If the healthcheck fails, will log a
message unless the CLI loglevel is `quiet` or `silent`.
endpoint and populates information for the [`percy`](#percy) property. The result of this function
is cached and subsequent calls will return the first cached result. If the healthcheck fails, will
log a message unless the CLI loglevel is `quiet` or `silent`. Upon a successful health check, a
remote logging connection is also established.
``` js
const { isPercyEnabled } = require('@percy/sdk-utils');
const { isPercyEnabled } = require('@percy/sdk-utils')

@@ -60,3 +63,3 @@ // CLI API not running

Fetches and returns the `@percy/dom` serialization script hosted by the CLI API server. The
Fetches and returns the `@percy/dom` serialization script hosted by the local Percy API server. The
resulting string can be evaulated within a browser context to add the `PercyDOM.serialize` function

@@ -66,14 +69,14 @@ to the global scope. Subsequent calls return the first cached result.

``` js
const { fetchPercyDOM } = require('@percy/sdk-utils');
const { fetchPercyDOM } = require('@percy/sdk-utils')
let script = await fetchPercyDOM();
let script = await fetchPercyDOM()
// selenium-webdriver
driver.executeScript(script);
driver.executeScript(script)
// webdriverio
browser.execute(script);
browser.execute(script)
// puppeteer
page.evaluate(script);
page.evaluate(script)
// protractor
browser.executeScript(script);
browser.executeScript(script)
// etc...

@@ -84,6 +87,6 @@ ```

Posts snapshot options to the CLI API server.
Posts snapshot options to the local Percy API server.
``` js
const { postSnapshot } = require('@percy/sdk-utils');
const { postSnapshot } = require('@percy/sdk-utils')

@@ -102,3 +105,33 @@ await postSnapshot({

requestHeaders: {}
});
})
```
### `request(url[, options])`
Sends a request to the local Percy API server. Used internally by the other SDK utils.
``` js
const { request } = require('@percy/sdk-utils')
await request('/percy/idle')
await request('/percy/stop')
```
#### `request.fetch(url, options)`
The underlying implementation of the `request()` util. For Node environments, `http.request` is
used; for browser environments, `window.fetch` is used. Can be overridden by the SDK's framework to
work around CORS/CSP issues.
The returned object must contain the following normalized properties from the request response:
`status`, `statusText`, `headers`, `body`
``` js
const { request } = require('@percy/sdk-utils')
// Cypress SDK example
request.fetch = async function fetch(url, options) {
options = { url, retryOnNetworkFailure: false, ...options }
return Cypress.backend('http:request', options)
}
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc