@percy/client
Advanced tools
Comparing version 1.0.0-beta.39 to 1.0.0-beta.40
@@ -200,3 +200,3 @@ "use strict"; | ||
progress, | ||
timeout = 600000, | ||
timeout = 10 * 60 * 1000, | ||
interval = 1000 | ||
@@ -203,0 +203,0 @@ }) { |
{ | ||
"name": "@percy/client", | ||
"version": "1.0.0-beta.39", | ||
"version": "1.0.0-beta.40", | ||
"license": "MIT", | ||
@@ -14,6 +14,6 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"build": "cross-env NODE_ENV=production babel src --out-dir dist --root-mode upward", | ||
"build": "node ../../scripts/build", | ||
"lint": "eslint --ignore-path ../../.gitignore .", | ||
"test": "cross-env NODE_ENV=test mocha", | ||
"test:coverage": "nyc yarn test" | ||
"test": "node ../../scripts/test", | ||
"test:coverage": "yarn test --coverage" | ||
}, | ||
@@ -23,5 +23,2 @@ "publishConfig": { | ||
}, | ||
"mocha": { | ||
"require": "../../scripts/babel-register" | ||
}, | ||
"devDependencies": { | ||
@@ -31,5 +28,5 @@ "mock-require": "^3.0.3" | ||
"dependencies": { | ||
"@percy/env": "^1.0.0-beta.39" | ||
"@percy/env": "^1.0.0-beta.40" | ||
}, | ||
"gitHead": "bd5cea12ca0d21ca167ce9100df2ead274428b7e" | ||
"gitHead": "1607ab0f5dbe5ab8ef3c9f7b6c2a89f66533348c" | ||
} |
113
README.md
# @percy/client | ||
Communicate with Percy's API to create builds and snapshots, upload resources, and finalize builds | ||
and snapshots. Uses `@percy/env` to send environment information with new builds. Can also be used | ||
to query for a project's builds using a read access token. | ||
and snapshots. Uses [`@percy/env`](.packages/env) to send environment information with new | ||
builds. Can also be used to query for a project's builds using a read access token. | ||
- [Usage](#usage) | ||
- [Create a build](#create-a-build) | ||
- [Create, upload, and finalize snapshots](#create-upload-and-finalize-snapshots) | ||
- [Finalize a build](#finalize-a-build) | ||
- [Query for a build*](#query-for-a-build) | ||
- [Query for a project's builds*](#query-for-a-projects-builds) | ||
- [Wait for a build to be finished*](#wait-for-a-build-to-be-finished) | ||
## Usage | ||
### `new PercyClient([options])` | ||
``` js | ||
import PercyClient from '@percy/client'; | ||
import PercyClient from '@percy/client' | ||
// provide a read or write token, defaults to PERCY_TOKEN environment variable | ||
const client = new PercyClient({ token: 'abcdef123456' }) | ||
const client = new PercyClient(options) | ||
``` | ||
### Create a build | ||
#### Options | ||
- `token` — Your project's `PERCY_TOKEN` (**default** `process.env.PERCY_TOKEN`) | ||
- `clientInfo` — Client info sent to Percy via a user-agent string | ||
- `environmentInfo` — Environment info also sent with the user-agent string | ||
## Create a build | ||
Creates a percy build. Only one build can be created at a time per instance. During this step, | ||
various environment information is collected via [`@percy/env`](./packages/env#readme) and | ||
associated with the new build. If `PERCY_PARALLEL_TOTAL` and `PERCY_PARALLEL_NONCE` are present, a | ||
build shard is created as part of a parallelized Percy build. | ||
``` js | ||
@@ -24,20 +40,33 @@ await client.createBuild() | ||
### Create, upload, and finalize snapshots | ||
## Create, upload, and finalize snapshots | ||
This method combines the work of creating a snapshot, uploading any missing resources, and finally | ||
finalizng the snapshot. | ||
``` js | ||
await client.sendSnapshot({ | ||
name, | ||
widths, | ||
minHeight, | ||
enableJavaScript, | ||
clientInfo, | ||
environmentInfo, | ||
// `sha` falls back to `content` sha | ||
resources: [{ url, sha, content, mimetype, root }] | ||
}) | ||
await client.sendSnapshot(snapshotOptions) | ||
``` | ||
### Finalize a build | ||
#### Options | ||
- `name` — Snapshot name (**required**) | ||
- `widths` — Widths to take screenshots at | ||
- `minHeight` — Miniumum screenshot height | ||
- `enableJavaScript` — Enable JavaScript for screenshots | ||
- `clientInfo` — Additional client info | ||
- `environmentInfo` — Additional environment info | ||
- `resources` — Array of snapshot resources | ||
- `url` — Resource URL (**required**) | ||
- `mimetype` — Resource mimetype (**required**) | ||
- `content` — Resource content (**required** when missing `sha`) | ||
- `sha` — Resource content sha (**required** when missing `content`) | ||
- `root` — Boolean indicating a root resource | ||
## Finalize a build | ||
Finalizes the active build. When `all` is true, `all-shards=true` is added as a query param so the | ||
API finalizes all other parallel build shards associated with the build. | ||
``` js | ||
// finalize the active build | ||
await client.finalizeBuild() | ||
@@ -49,4 +78,6 @@ | ||
### Query for a build | ||
## Query for a build | ||
Retrieves build data by id. | ||
**Requires a read access token** | ||
@@ -58,17 +89,47 @@ | ||
### Query for a project's builds | ||
## Query for a project's builds | ||
Retrieves project builds, optionally filtered. The project slug can be found as part of the | ||
project's URL. For example, the project slug for `https://percy.io/percy/example` is | ||
`"percy/example"`. | ||
**Requires a read access token** | ||
``` js | ||
await client.getBuilds(projectSlug/*, filters*/) | ||
// get all builds for a project | ||
await client.getBuilds(projectSlug) | ||
// get all builds for a project's "master" branch | ||
await client.getBuilds(projectSlug, { branch: 'master' }) | ||
``` | ||
### Wait for a build to be finished | ||
#### Filters | ||
- `sha` — A single commit sha | ||
- `shas` — An array of commit shas | ||
- `branch` — The name of a branch | ||
- `state` — The build state (`"pending"`, `"finished"`, etc.) | ||
## Wait for a build to be finished | ||
This method resolves when the build has finished and is no longer pending or processing. By default, | ||
it will time out if there is no update after 10 minutes. | ||
**Requires a read access token** | ||
``` js | ||
await client.waitForBuild({ build: 'build-id' }) | ||
await client.waitForBuild({ project: 'project-slug', commit: '40-char-sha' }) | ||
// wait for a specific project build by commit sha | ||
await client.waitForBuild({ | ||
project: 'percy/example', | ||
commit: '40-char-sha' | ||
}) | ||
``` | ||
#### Options | ||
- `build` — Build ID (**required** when missing `commit`) | ||
- `commit` — Commit SHA (**required** when missing `build`) | ||
- `project` — Project slug (**required** when using `commit`) | ||
- `timeout` — Timeout in milliseconds to wait with no updates (**default** `10 * 60 * 1000`) | ||
- `interval` — Interval in miliseconds to check for updates (**default** `1000`) | ||
- `progress` — Function to call on each update with build data |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24677
133
Updated@percy/env@^1.0.0-beta.40