Dialog differ
npm install dialog-differ__WORK IN PROGRESS__
An application for diffing two dialogs against each other.
Uses Google Chrome's Puppeteer to take screenshots and ImageDiff to compare screenshots.
A collaboration with Starak.
- Node 6+
npm install dialog-differ
``
const DialogDiffer = require( 'dialog-differ' );
const suite = { // see 'Suite' structure
options: {
sizes: [
{ width: 460, height: 350 },
{ width: 320, height: 150 }
],
originalVersion: '1.0.1',
currentVersion: '1.0.2'
},
original: [
{
id: 'first',
version: '1.0.1',
url: 'http://example.com/1.0.1/dialog-first.html'
},
{
id: 'second',
version: '1.0.1',
url: 'http://example.com/1.0.1/dialog-second.html'
}
],
current: [
{
id: 'first',
version: '1.0.2',
url: 'http://example.com/1.0.2/dialog-first.html'
},
{
id: 'second',
version: '1.0.2',
url: 'http://example.com/1.0.2/dialog-second.html'
}
]
};
// create dialog differ
const dialogDiffer = new DialogDiffer();
// init dialog differ
await dialogDiffer.initDialogDiffer( { databaseArgs: ${__dirname}/database.json } ); // store database in database.json
// diff suite
const suiteResult = await dialogDiffer.diff( suite ); // see 'SuiteResult' structure
`
| Property | Type | Description |
| --- | --- | --- |
| \[databaseLayer] | AbstractDatabaseLayer | Database layer. Default LowDbDatabaseLayer. |
| \[logLevel] | String | Log level. Default error. |
``
const dialogDiffer = new DialogDiffer( {
databaseLayer = null,
logLevel = null,
} )
Returns Promise
Method to initialize dialog differ. Used to send arguments to database layer.
| Property | Type | Description |
| --- | --- | --- |
| \[databaseArgs] | any | Database arguments. See AbstractDatabaseLayer~initDB. |
`${__dirname}/database.json
// store database in database.json when using LowDbDatabaseLayer
await dialogDiffer.initDialogDiffer( { databaseArgs: } );`
Returns Promise
Diffs original dialogs with current dialogs.
| Property | Type | Description |
| --- | --- | --- |
| suite | DialogDiffer.Suite | Suite. See AbstractDatabaseLayer~initDB. |
``
const suiteResult = await dialogDiffer.diff( suite );
Returns Promise
Get running or finished DialogDiffer.SuiteResult from database.
| Property | Type | Description |
| --- | --- | --- |
| suiteId | String | Suite id |
``
const suiteResult = await dialogDiffer.getSuiteResult( suiteId );
Returns Promise
Get list of latest running or finished DialogDiffer.SuiteResult from database.
``
const suiteResults = await dialogDiffer.getLastSuiteResults();
Returns Promise
Delete all DialogDiffer.DialogScreenshots for Dialogs matching dialogId from database.
| Property | Type | Description |
| --- | --- | --- |
| dialogId | String | Dialog id |
``
await dialogDiffer.deleteDialogs( dialogId );
Returns Promise
Delete DialogDiffer.SuiteResult for suiteId from database.
| Property | Type | Description |
| --- | --- | --- |
| suiteId | String | Suite id |
``
await dialogDiffer.deleteSuiteResult( suiteId );
#### Suite
| Property | Type | Description |
| --- | --- | --- |
| options | DialogDiffer.Options | Suite options |
| original | Array
| current | Array
#### Suite Options
| Property | Type | Description | Example |
| --- | --- | --- | --- |
| sizes | Array<{ width: Number, height: Number }> | Sizes | [ { width: 460, height: 350 } ] | String
| originalVersion | | Original version | 1.0.1 |String
| currentVersion | | Current version | 1.0.2|Boolean
| \[isForceSnap] | | Force snap | false| Boolean
| \[isForceDiff] | | Force diff | false|
#### Suite Dialog
| Property | Type | Description | Example |
| --- | --- | --- | --- |
| version | String | Dialog version | 1.0.1 |String
| id | | Dialog id | first |String
| url | | Dialog URL | http://example.com/1.0.1/dialog-first.html |String
| \[hash] | | URL hash | #hash |String
| \[waitForSelector] | | Wait for selector | body.active |Number
| \[timeout] | | Timeout before taking snap (ms) | 250 |String
| \[crop] | | Selector to use for cropping screenshot | #container |Function(defaultWidth, defaultHeight): { width: Number, height: Number }
| \[resize] | | Function evaluated by Puppeteer which returns the new size to use for screenshot | function() { var container = document.querySelector('#container'); return { width: container.scrollWidth, height: container.scrollHeight }; } |
#### Suite Result
| Property | Type | Description | Example |
| --- | --- | --- | --- |
| options | DialogDiffer.Options | Suite options |
| results | Array |
#### Suite Dialogs Result
| Property | Type | Description | Example |
| --- | --- | --- | --- |
| dialogId | String | Dialog id | first |DialogDiffer.DialogResult
| original | | Original dialog | { id: 'first', version: '1.0.1', url: ..., screenshots: [ ... ] } |DialogDiffer.DialogResult
| current | | Current dialog | { id: 'first', version: '1.0.2', url: ..., screenshots: [ ... ] } |String
| originalVersion | | Original version | 1.0.1 |String
| currentVersion | | Current version | 1.0.2 |DifferConstant
| result | | Diff result | changed |Array
| differ | | Dialogs diffs | [ { index: 0, result: 'changed', base64: 'data:image/png;base64,...' } ] |
#### Suite Dialog Result
Extends Suite Dialog
| Property | Type | Description | Example |
| --- | --- | --- | --- |
| screenshots | Array | Dialog screenshots | [ { base64: 'data:image/png;base64,...', width: 460, height: 350 } ] |{ code: String, message: String }
| \[error] | | Error when creating screenshot | { code: 'snap-dialog-from-browser-error', message: 'Could not snap dialog url \'http://example.com/1.0.1/dialog-first.html\'' } |
#### Suite Dialog Result Diff
| Property | Type | Description | Example |
| --- | --- | --- | --- |
| index | Number | Index | 0 |DifferConstant
| result | | Diff result | identical |String
| base64 | | Diff image | data:image/png;base64,... |
#### Suite Error
Extends JS Error
| Property | Type | Description | Example |
| --- | --- | --- | --- |
| message | String | Error message | Unexpected error |ErrorConstants
| code | | Error code | unexpected-error |Object
| args | | Error arguments | { dialogId: 'one' } |
#### Error Constants
See ErrorConstants
| Property | Type | Description |
| --- | --- | --- |
| unexpected-error | String | Unexpected error |
TODO More errors
#### Differ Constants
| Property | Type | Description |
| --- | --- | --- |
| identical | String | Identical dialog/screenshot |changed
| | String | Changed dialog/screenshot |new
| | String | New dialog/screenshot |deleted
| | String | Deleted dialog/screenshot |
#### Logger Constants
| Property | Type | Description |
| --- | --- | --- |
| none | String | No logging |debug
| | String | Log, info and error logging |info
| | String | Info and error logging |error
| | String | Error logging |
- npm installnpm test
-
- npm run dist`
- Examples