0.0.7 • Published 2 months ago

comparizen-client v0.0.7

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
2 months ago

Node client for Comparizen

Quick start

Install the dependency using npm install comparizen-client --save-dev

Example test script:

import { ComparizenClient } from "comparizen-client";

const client = new ComparizenClient({
    apiKey: 'some-api-key', // preferably set this from an environment variable
});

/*
Create a test run. This groups all your uploaded images into one 'run', making it easier to link the test run to a build or test.  
You can find your project ID and api key in your Comparizen project's settings. */
const testRunId = await client.createTestRun('your-project-id', 'my testrun name')

const imageBuffer = fs.readFileSync(`${__dirname}/front-page-screenshot.png`); // or get an image from some other api, like a screenshot creator
await client.uploadImage(imageBuffer, testRunId, { name: 'Front page of my site'});

// .. upload more screenshots

/* 
Marks the test run as 'finished'. This lets Comparizen know that it should not expect any new screenshots in the test run,
allowing it to determine the test run's status immediately after all screenshots have been processed. */ 
await client.finalizeTestRun(testRunId);

/*
Here we wait until all uploaded images have been processed and return the results. */
const testRunResult = await client.pollForTestRunProcessingComplete(testRunId);

if (testRunResult.status !== 'ALL_OK') {
    throw new Error(`test failed, see results: at ${testRunResult.url}`)
}

Config options

new ComparizenClient({
    /* 
    Preferably set this from an environment variable */
    apiKey: 'some-api-key',

    /* 
    Set to `true` to receive a comparison result after each image upload.
    This allows you to fail your test immediately after one image is deemed different than the baseline.
        
    If set to false, calls to `uploadImage` will return immediately after the image has been uploaded and its result
    won't include any comparison results. You can then use either `pollForComparisonProcessingComplete` or `pollForTestRunProcessingComplete`
    to return the results of the comparison or the entire test run respectively. */
    waitForCompareResult: false,

    /* 
    Maximum number of seconds to wait for the result of a single image comparison. 
    Defaults to `60` but is typically done well within 5 seconds depending on the image's size. */
    waitForCompareResultTimeout: 60,

    /* 
    Maximum number of seconds to wait for the result of a single image comparison. Defaults to `60` but is typically done a lot faster,
    depending on the amount of images and their sizes. */
    waitForCompareResultTimeout: 60,
});
0.0.7

2 months ago

0.0.6

3 months ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

4 years ago