Socket
Socket
Sign inDemoInstall

chigai-api

Package Overview
Dependencies
109
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.2 to 1.3.2

9

app/main.js

@@ -32,3 +32,3 @@ /**

* @param {String} uri the location to test
* @param {Object} options the options, taken from chigai-core. currently "vw", "vh", "threshold"
* @param {Object} options the options, taken from chigai-core. currently "vw", "vh", "threshold", "wait"
* @return {Boolean} false if the regression failes

@@ -38,3 +38,2 @@ */

let result;
try {

@@ -49,2 +48,3 @@ result = await chigaiCore.regression(uri, options);

}
// if (Array.isArray(result) && result.length === 1 && result[0].match === false) {

@@ -62,9 +62,8 @@ return false;

* @param {String} uri the location to test
* @param {Object} options the options, taken from chigai-core. currently "vw", "vh", "threshold"
* @param {Object} options the options, taken from chigai-core. currently "vw", "vh", "threshold", "wait"
* @return {Boolean} false if the regression failes
*/
module.exports = async(uri, options = {}) => {
module.exports = async (uri, options = {}) => {
let result = await _assert(uri, options);
return result;
};
{
"name": "chigai-api",
"version": "1.0.2",
"version": "1.3.2",
"description": "Chigai: modern visual regression testing. API module.",

@@ -40,11 +40,14 @@ "main": "./app/main.js",

"dependencies": {
"chigai-core": "^1.0.0"
"chigai-core": "^1.5.0"
},
"devDependencies": {
"chai": "4.1.1",
"chigai-mock-server": "^1.0.0",
"chai": "4.1.1",
"eslint": "4.4.1",
"mocha": "3.5.0",
"nyc": "^11.2.1"
"eslint": "4.18.2",
"mocha": "5.0.3",
"nyc": "^13.2.0",
"proxyquire": "^2.0.1",
"sinon": "^5.0.10",
"sinon-chai": "^3.1.0"
}
}

@@ -14,3 +14,3 @@ # chigai-api [![Build Status](https://travis-ci.org/martinkr/chigai-api.svg?branch=master)](https://travis-ci.org/martinkr/chigai-api)

# How to use this?
Chigai-api provides a clean facade for chiga-core. The regression testing of a given url and creating a fresh reference item beforehand.
Chigai-api provides a clean facade for chigai-core. The regression testing of a given url and creating a fresh reference item beforehand.
Chigai-api is designed to be used with your favourite testrunner.

@@ -21,6 +21,6 @@

# Installation
## Installation
```$ yarn add chigai-api chigai-cli```
# Example
## Example
```JavaScript

@@ -33,3 +33,4 @@ // with mocha

let result;
result = await regression("http://example.com", {"vw": 1200, "vh": 800, "threshold": 0.01});
// set the viewport to 1200x800 and wait for 250ms between onload and screenshotting. expect the delta to be lower than 1%
result = await regression("http://example.com", {"vw": 1200, "vh": 800, "threshold": 0.01, "wait": 250});
result.should.be.ok;

@@ -40,7 +41,46 @@ }));

# Create a fresh reference on the CLI
### Configuration options
Options can either be passed as arguments per call or globally via .chigairs.json file. The options-object takes precedence.
#### ```vw```
Default: ```1024```. The with of the viewport you cant to screenshot. This will be part of the unique identifier.
#### ```vh```
Default: ```786```. The height of the viewport you cant to screenshot. This will be part of the unique identifier.
#### ```threshold```
Default: ```0.01```. The threshold to use for the comparison. This will not be part of the unique identifier.
#### ```path```
Default: ```./screenshots``` There's the possiblitly to pass a custom path to chigai. It's relative to your working directory.
Use this to share your reference items (e.g. via source control, rsync ...).
#### ```wait```
Default: ```0```. Wait this amount of miliseconds after the page's ```load-event``` before making the screenshot. This will not be part of the unique identifier.
#### .chigai.json
You can store project wide setttings in this file. It takes the same key-value-pairs as the options-object. Plus an additional ```path``` property.
```JavaScript
{
"path" : "./myscreenshots",
"threshold": 0.5,
"vw": 1200,
"vh" : 800,
"wait": 5000
}
```
## Create a fresh reference on the CLI
If you need a new reference item, e.g. because you changed the page - use chigai-cli:
```$ chigai reference http://example.com -w 1200 -h 800 -t 0.01```
```$ ./node-modules/.bin/chigai reference http://example.com -w 1200 -h 800 -t 0.01```
# Tech Stack
## Tech Stack
- ECMAScript 2018 on ```nodejs v8.5.0```

@@ -50,3 +90,3 @@ - ```blink-diff v^1.0.1```

- ```puppeteer v0.11.0```
- 100% code coverage using ```mocha v3.5.2```, ```chai v4.1.2``` and```nyc v11.2.1``,
- 100% code coverage using ```mocha v3.5.2```, ```chai v4.1.2``` and ```nyc v11.2.1```,

@@ -53,0 +93,0 @@ ## Resources

@@ -26,2 +26,3 @@ /**

const fs = require("fs-extra-plus");
const proxyquire = require("proxyquire");

@@ -79,3 +80,5 @@ const thisModulePath = "main";

let result;
result = await thisModule(uriStatic, {"threshold": 0.01});
result = await thisModule(uriStatic, {
"threshold": 0.01
});
result.should.be.ok;

@@ -86,3 +89,5 @@ }));

let result;
result = await thisModule(uriStatic, {"threshold": 0.01});
result = await thisModule(uriStatic, {
"threshold": 0.01
});
result.should.be.ok;

@@ -93,4 +98,8 @@ }));

let result;
result = await thisModule(uriStatic);
result = await thisModule(uriStatic);
result = await thisModule(uriStatic, {
"path": "../myscreenshots"
});
result = await thisModule(uriStatic, {
"path": "../myscreenshots"
});
result.should.be.ok;

@@ -103,3 +112,5 @@ }));

// lower threshold for random mock
result = await thisModule(uriDynamic, {"threshold": 0.01});
result = await thisModule(uriDynamic, {
"threshold": 0.01
});
result.should.not.be.ok;

@@ -111,2 +122,94 @@ }));

describe("should call the \"core\"-package ", () => {
let thisModuleProxied;
// create stubs for spying on them
let stubModule = {
"regression": (uri, options) => new Promise((resolve, reject) => {
resolve(true);
}),
"reference": (uri, options) => new Promise((resolve, reject) => {
resolve(true);
})
};
let spyCoreRegression = sinon.spy(stubModule, "regression");
let spyCoreReference = sinon.spy(stubModule, "reference");
before(() => {
// mock dependencies
thisModuleProxied = proxyquire("./../../app/" + thisModulePath, {
"chigai-core": {
"regression": spyCoreRegression,
"reference": spyCoreReference
}
});
});
beforeEach(() => {
spyCoreRegression.resetHistory();
spyCoreReference.resetHistory();
});
it("should pass the URI as the first parameters", (async () => {
let result;
result = await thisModuleProxied(uriDynamic);
spyCoreRegression.should.have.been.calledWith("http://localhost:3000/random", {})
}));
it("should pass the URI as the first, and the \"vw\" as \"vw\"-property in the object as the second parameter", (async () => {
let result;
result = await thisModuleProxied(uriDynamic, {
"vw": 500
});
spyCoreRegression.should.have.been.calledWith("http://localhost:3000/random", {
"vw": 500
})
}));
it("should pass the URI as the first, and the \"vh\" as \"vh\"-property in the object as the second parameter", (async () => {
let result;
result = await thisModuleProxied(uriDynamic, {
"vh": 500
});
spyCoreRegression.should.have.been.calledWith("http://localhost:3000/random", {
"vh": 500
})
}));
it("should pass the URI as the first, and the \"wait\" as \"wait\"-property in the object as the second parameter", (async () => {
let result;
result = await thisModuleProxied(uriDynamic, {
"wait": 500
});
spyCoreRegression.should.have.been.calledWith("http://localhost:3000/random", {
"wait": 500
})
}));
it("should pass the URI as the first, and the \"wait\" as \"wait\"-property in the object as the second parameter", (async () => {
let result;
result = await thisModuleProxied(uriDynamic, {
"wait": 500
});
spyCoreRegression.should.have.been.calledWith("http://localhost:3000/random", {
"wait": 500
})
}));
it("should pass the URI as the first, and the \"threshold\" as \"threshold\"-property in the object as the second parameter", (async () => {
let result;
result = await thisModuleProxied(uriDynamic, {
"threshold": 500
});
spyCoreRegression.should.have.been.calledWith("http://localhost:3000/random", {
"threshold": 500
})
}));
});
});

@@ -8,3 +8,6 @@ "use strict";

global.sinon = require("sinon");
global.sinonChai = require("sinon-chai");
global.chai.use(global.sinonChai);
global.ENV = "MOCHA";

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc