Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gemini-faildump

Package Overview
Dependencies
Maintainers
5
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gemini-faildump - npm Package Compare versions

Comparing version 2.0.1 to 3.0.0

AUTHORS

7

CHANGELOG.md
# Changelog
## 3.0.0
* Don't save image when option "light" is enabled
* Improved comparing diffs
* major: Do not support node lower than 4.0
## 2.0.0

@@ -4,0 +11,0 @@

40

lib/errors/base-error.js
'use strict';
var _ = require('lodash'),
URI = require('urijs');
const _ = require('lodash');
const URI = require('urijs');
function BaseError(data, config) {
var browserConfig = config.forBrowser(data.browserId);
this._browserCapabilities = browserConfig.desiredCapabilities;
this._quota = new URI(browserConfig.gridUrl).username();
this._timestamp = new Date();
module.exports = class BaseError {
constructor(data, config) {
const browserConfig = config.forBrowser(data.browserId);
this._browserCapabilities = browserConfig.desiredCapabilities;
this._quota = new URI(browserConfig.gridUrl).username();
this._timestamp = new Date();
this.message = data.message || 'Image diff found'; // diff Error don't have "message" key;
this.browserId = data.browserId;
this.sessionId = data.sessionId;
this.name = _.compact([
data.suite.fullName,
data.state && data.state.name,
data.browserId
]).join('.');
}
this.message = data.message || 'Image diff found'; // diff Error don't have "message" key;
this.browserId = data.browserId;
this.sessionId = data.sessionId;
this.name = _.compact([
data.suite.fullName,
data.state && data.state.name,
data.browserId
]).join('.');
}
BaseError.prototype.getData = function() {
return {
getData() {
return {
timestamp: this._timestamp,

@@ -30,4 +31,3 @@ message: this.message,

};
}
};
module.exports = BaseError;
'use strict';
var q = require('q'),
tempFS = require('../temp-fs'),
const BaseError = require('./base-error');
const ImageError = require('./image-error');
BaseError = require('./base-error'),
ImageError = require('./image-error'),
imageProcessor = require('../image-processor');
exports.buildError = function (data, geminiConfig, options) {
if (!data.imagePath && !data.saveDiffTo) {
return q(new BaseError(data, geminiConfig));
}
var imagePath = data.imagePath || tempFS.resolveImagePath(),
saveImg = data.imagePath ? q : data.saveDiffTo.bind(data);
return saveImg(imagePath)
.then(function() {
if (!options.light) {
return imageProcessor.pngToBase64(imagePath);
}
})
.then(function(base64) {
return new ImageError(data, geminiConfig, {
path: imagePath,
base64: base64
});
});
exports.buildError = (data, config, options) => {
return (data.imagePath || data.saveDiffTo)
? new ImageError(data, config, options)
: new BaseError(data, config);
};
'use strict';
var _ = require('lodash'),
inherit = require('inherit'),
const _ = require('lodash');
const q = require('q');
const fs = require('q-io/fs');
BaseError = require('./base-error');
const tempFS = require('../temp-fs');
const BaseError = require('./base-error');
const imageProcessor = require('../image-processor');
var ImageError = inherit(BaseError, {
__constructor: function(data, config, img) {
this.__base(data, config);
this.imagePath = img.path;
this.base64 = img.base64;
this.isDiff = data.equal !== undefined;
},
module.exports = class ImageError extends BaseError {
constructor(data, config, options) {
super(data, config);
getData: function() {
return _.defaults(this.__base(), {
base64: this.base64
});
this.imagePath = data.imagePath || tempFS.resolveImagePath();
this.saveImg = data.imagePath ? q : data.saveDiffTo.bind(data);
this.light = options.light;
this.isDiff = !_.isUndefined(data.equal);
}
});
module.exports = ImageError;
getData() {
const baseErrData = super.getData();
return this.light ? baseErrData : this._addBase64(baseErrData);
}
save() {
return this.saveImg(this.imagePath)
.catch((error) => console.error(`Error occurred while saving image: ${error.stack || error}`));
}
_addBase64(baseErrData) {
return fs.exists(this.imagePath)
.then((isImgExists) => isImgExists || this.save())
.then(() => imageProcessor.pngToBase64(this.imagePath))
.then((base64) => _.extend(baseErrData, {base64}))
.catch((error) => console.error(error.stack || error));
}
};
'use strict';
var _ = require('lodash'),
inherit = require('inherit'),
fs = require('q-io/fs'),
q = require('q'),
const _ = require('lodash');
const fs = require('q-io/fs');
const q = require('q');
errorFactory = require('./errors/error-factory'),
imageProcessor = require('./image-processor');
const errorFactory = require('./errors/error-factory');
const imageProcessor = require('./image-processor');
module.exports = inherit({
__constructor: function (config, opts) {
module.exports = class FailCollector {
constructor(config, opts) {
this._config = config;
this._options = opts || {};
this.fails = [];
},
}
addFail: function (fail) {
this.fails.push(errorFactory.buildError(fail, this._config, this._options));
},
addFail(fail) {
this.fails.push(q.resolve(errorFactory.buildError(fail, this._config, this._options)));
}
collect: function() {
collect() {
return q.all(this.fails)
.then(function(fails) {
return _.groupBy(fails, 'name');
})
.then(this._filterDiffs.bind(this))
.then(this._getFailsData.bind(this))
.then(this._saveToFile.bind(this))
.catch(function (error) {
console.error('Some error while collecting fails: ', error.stack);
});
},
.then((fails) => _.groupBy(fails, 'name'))
.then((fails) => this._filterDiffs(fails))
.then((fails) => this._getFailsData(fails))
.then((fails) => this._saveToFile(fails))
.catch((error) => console.error(`Error occurred while collecting fails: ${error.stack}`));
}
_filterDiffs: function(fails) {
_filterDiffs(fails) {
return this._getRealFailedTests(fails)
.then(function(realFails) {
return _.omit(fails, realFails);
});
},
.then((realFails) => _.omit(fails, realFails));
}
_getRealFailedTests: function(errors) {
_getRealFailedTests(errors) {
return _(errors)
.map(function(fails) {
.map((fails) => {
return fails.length === this._maxRuns(fails[0].browserId)
&& _.every(fails, {isDiff: true})
&& getRealFailedTestName_(fails);
}.bind(this))
})
.thru(q.all).value()

@@ -54,31 +47,38 @@ .then(_.compact);

return _(fails)
// remove the comparison of the first diff with yourself
.slice(1)
.map(compareWith_(fails[0]))
.thru(q.all).value()
.then(function(compares) {
return _.every(compares) && fails[0].name;
});
.then((compares) => _.every(compares) && fails[0].name);
}
function compareWith_(reference) {
return function(fail) {
return imageProcessor.compare(reference.imagePath, fail.imagePath);
};
const promise = reference.save();
return (fail) => promise
.then(fail.save())
.then(() => imageProcessor.compare(reference.imagePath, fail.imagePath));
}
},
}
_maxRuns: function(browserId) {
_maxRuns(browserId) {
return this._config.forBrowser(browserId).retry + 1;
},
}
_getFailsData: function (fails) {
return _.mapValues(fails, function (failList) {
return failList.map(function (fail) {
return fail.getData();
});
});
},
_getFailsData(fails) {
const keys = _.keys(fails);
_saveToFile: function (errors) {
return _(fails)
.map((failList) => _(failList)
.map((fail) => fail.getData())
.thru(q.all)
.value())
.thru(q.all)
.value()
.then((res) => _.zipObject(keys, res));
}
_saveToFile(errors) {
return fs.write('faildump.json', JSON.stringify(errors));
}
});
};
'use strict';
var FailCollector = require('./fail-collector');
const FailCollector = require('./fail-collector');
module.exports = function (gemini, opts) {
module.exports = (gemini, opts) => {
const fails = new FailCollector(gemini.config, opts);
gemini.on('startRunner', function(runner) {
var fails = new FailCollector(gemini.config, opts);
gemini.on(gemini.events.ERROR, (data) => fails.addFail(data));
runner.on('err', fails.addFail.bind(fails));
gemini.on(gemini.events.RETRY, (data) => fails.addFail(data));
runner.on('retry', fails.addFail.bind(fails));
gemini.on(gemini.events.TEST_RESULT, (data) => data.equal || fails.addFail(data));
runner.on('endTest', function (data) {
data.equal || fails.addFail(data);
});
runner.on('end', fails.collect.bind(fails));
});
gemini.on(gemini.events.END_RUNNER, () => fails.collect());
};
{
"name": "gemini-faildump",
"version": "2.0.1",
"version": "3.0.0",
"description": "Fail information plugin",

@@ -37,5 +37,4 @@ "keywords": [

"dependencies": {
"inherit": "~2.2.1",
"lodash": "^3.10.1",
"looks-same": "2.2.2",
"looks-same": "^3.2.0",
"q": "^1.1.2",

@@ -42,0 +41,0 @@ "q-io": "^1.13.2",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc