npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@percy/sdk-utils

v1.30.3

Published

Common JavaScript SDK utils

Downloads

2,258,209

Readme

@percy/sdk-utils

Common JavaScript SDK utils

Usage

logger([debug])

This function is a direct export of @percy/logger.

percy

This object contains information about the local Percy environment and is updated when isPercyEnabled is called for the first time.

import { percy } from '@percy/sdk-utils'

// reflects/updates process.env.PERCY_SERVER_ADDRESS
percy.address === 'http://localhost:5338'

// 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

// updated after fetchPercyDOM() is called
percy.domScript === fs.readFile(require.resolve('@percy/dom'))

isPercyEnabled()

Returns true or false if the Percy CLI API server is running. Calls the server's /healthcheck endpoint and populates information for the 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.

import { isPercyEnabled } from '@percy/sdk-utils'

// CLI API not running
await isPercyEnabled() === false
// [percy] Percy is not running, disabling snapshots

// CLI API is running
await isPercyEnabled() === true

fetchPercyDOM()

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 to the global scope. Subsequent calls return the first cached result.

import { fetchPercyDOM } from '@percy/sdk-utils'

let script = await fetchPercyDOM()

// selenium-webdriver
driver.executeScript(script)
// webdriverio
browser.execute(script)
// puppeteer
page.evaluate(script)
// protractor
browser.executeScript(script)
// etc...

postSnapshot(options)

Posts snapshot options to the local Percy API server.

import { postSnapshot } from '@percy/sdk-utils'

await postSnapshot({
  // required
  name: 'Snapshot Name',
  url: 'http://localhost:8000/',
  domSnapshot: 'result from PercyDOM.serialize()'
  // optional
  environmentInfo: ['<lib>/<version>', '<lang>/<version>'],
  clientInfo: '<sdk>/<version>',
  widths: [475, 1280],
  minHeight: 1024,
  enableJavaScript: false,
  requestHeaders: {}
})

request(url[, options])

Sends a request to the local Percy API server. Used internally by the other SDK utils.

import { request } from '@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

import { request } from '@percy/sdk-utils'

// Cypress SDK example
request.fetch = async function fetch(url, options) {
  options = { url, retryOnNetworkFailure: false, ...options }
  return Cypress.backend('http:request', options)
}