gemini-gui
Advanced tools
Comparing version 4.2.1 to 4.3.0
# Changelog | ||
## 4.3.0 - 2016-08-23 | ||
* Emit updateResult event during update for optimize reference image in plugin | ||
## 4.2.1 - 2016-08-23 | ||
@@ -4,0 +8,0 @@ |
319
lib/app.js
'use strict'; | ||
var path = require('path'), | ||
q = require('q'), | ||
fs = require('q-io/fs'), | ||
temp = require('temp'), | ||
_ = require('lodash'), | ||
findGemini = require('./find-gemini'), | ||
reporter = require('./reporter'), | ||
chalk = require('chalk'), | ||
util = require('util'), | ||
const path = require('path'); | ||
const q = require('q'); | ||
const fs = require('q-io/fs'); | ||
const temp = require('temp'); | ||
const _ = require('lodash'); | ||
const chalk = require('chalk'); | ||
Tests = require('./tests-model'), | ||
Index = require('./common/tests-index'), | ||
EventSource = require('./event-source'), | ||
Runner = require('./runner'); | ||
const findGemini = require('./find-gemini'); | ||
const reporter = require('./reporter'); | ||
const Tests = require('./tests-model'); | ||
const Index = require('./common/tests-index'); | ||
const EventSource = require('./event-source'); | ||
const Runner = require('./runner'); | ||
function removeTreeIfExists(path) { | ||
const removeTreeIfExists = (path) => { | ||
return fs.exists(path) | ||
.then(function(exists) { | ||
if (exists) { | ||
return fs.removeTree(path); | ||
} | ||
}); | ||
} | ||
.then((exists) => exists && fs.removeTree(path)); | ||
}; | ||
function filterBrowsers(browsersFromConfig, browsersFromCli) { | ||
return _.intersection(browsersFromConfig, browsersFromCli); | ||
} | ||
const filterBrowsers = _.intersection; | ||
function checkUnknownBrowsers(browsersFromConfig, browsersFromCli) { | ||
var unknownBrowsers = _.difference(browsersFromCli, browsersFromConfig); | ||
const checkUnknownBrowsers = (browsersFromConfig, browsersFromCli) => { | ||
const unknownBrowsers = _.difference(browsersFromCli, browsersFromConfig); | ||
if (!_.isEmpty(unknownBrowsers)) { | ||
console.warn(util.format( | ||
'%s Unknown browser ids: %s. Use one of the browser ids specified in the config file: %s', | ||
chalk.yellow('WARNING:'), unknownBrowsers.join(', '), browsersFromConfig.join(', ') | ||
)); | ||
console.warn('%s Unknown browser ids: %s. Use one of the browser ids specified in the config file: %s', | ||
chalk.yellow('WARNING:'), unknownBrowsers.join(', '), browsersFromConfig.join(', ')); | ||
} | ||
} | ||
}; | ||
function App(options) { | ||
this._options = options; | ||
this.diffDir = temp.path('gemini-gui-diff'); | ||
this.currentDir = temp.path('gemini-gui-curr'); | ||
this._failedTests = new Index(); | ||
module.exports = class App { | ||
constructor(options) { | ||
this._options = options; | ||
this.diffDir = temp.path('gemini-gui-diff'); | ||
this.currentDir = temp.path('gemini-gui-curr'); | ||
this._failedTests = new Index(); | ||
this._eventSource = new EventSource(); | ||
this._eventSource = new EventSource(); | ||
var Gemini = findGemini(); | ||
this._gemini = new Gemini(this._options.config, {cli: true, env: true}); | ||
_.set(this._gemini.config, 'system.tempDir', this.currentDir); | ||
const Gemini = findGemini(); | ||
this._gemini = new Gemini(this._options.config, {cli: true, env: true}); | ||
_.set(this._gemini.config, 'system.tempDir', this.currentDir); | ||
var browserIds = this._gemini.browserIds; | ||
checkUnknownBrowsers(browserIds, this._options.browser); | ||
this._gemini.on('startRunner', (runner) => this._runner = runner); | ||
this.referenceDirs = _.zipObject( | ||
browserIds, | ||
browserIds.map(function(browserId) { | ||
return this._gemini.config.forBrowser(browserId).screenshotsDir; | ||
}.bind(this)) | ||
); | ||
} | ||
const browserIds = this._gemini.browserIds; | ||
checkUnknownBrowsers(browserIds, this._options.browser); | ||
App.prototype.initialize = function() { | ||
return this._recreateTmpDirs() | ||
.then(this._readTests.bind(this)); | ||
}; | ||
this.referenceDirs = _.zipObject( | ||
browserIds, | ||
browserIds.map((id) => this._gemini.config.forBrowser(id).screenshotsDir) | ||
); | ||
} | ||
App.prototype.addClient = function(connection) { | ||
this._eventSource.addConnection(connection); | ||
}; | ||
initialize() { | ||
return this._recreateTmpDirs() | ||
.then(this._readTests.bind(this)); | ||
} | ||
App.prototype.sendClientEvent = function(event, data) { | ||
this._eventSource.emit(event, data); | ||
}; | ||
addClient(connection) { | ||
this._eventSource.addConnection(connection); | ||
} | ||
App.prototype.getTests = function() { | ||
return q.resolve(this._tests.data); | ||
}; | ||
sendClientEvent(event, data) { | ||
this._eventSource.emit(event, data); | ||
} | ||
App.prototype._readTests = function() { | ||
var _this = this; | ||
getTests() { | ||
return q(this._tests.data); | ||
} | ||
return this._gemini.readTests(this._options.testFiles, this._options.grep) | ||
.then(function(collection) { | ||
_this._collection = collection; | ||
return collection.topLevelSuites(); | ||
}) | ||
.then(function(suites) { | ||
if (!_this._options.browser) { | ||
return; | ||
} | ||
_readTests() { | ||
return this._gemini.readTests(this._options.testFiles, this._options.grep) | ||
.then((collection) => { | ||
this._collection = collection; | ||
return collection.topLevelSuites(); | ||
}) | ||
.then((suites) => { | ||
if (!this._options.browser) { | ||
return; | ||
} | ||
suites.map(function(suite) { | ||
suite.browsers = filterBrowsers(suite.browsers, _this._options.browser); | ||
suites.map((suite) => { | ||
suite.browsers = filterBrowsers(suite.browsers, this._options.browser); | ||
}); | ||
}) | ||
.then(() => { | ||
this._tests = new Tests(this, this._collection); | ||
}); | ||
}) | ||
.then(function() { | ||
_this._tests = new Tests(_this, _this._collection); | ||
}); | ||
}; | ||
} | ||
App.prototype.run = function(specificTests) { | ||
var _this = this; | ||
return Runner.create(this._collection, specificTests) | ||
.run(function(collection) { | ||
return _this._gemini.test(collection, { | ||
reporters: [reporter(_this), 'flat'] | ||
}); | ||
}); | ||
}; | ||
run(specificTests) { | ||
return Runner.create(this._collection, specificTests) | ||
.run((collection) => this._gemini.test(collection, { | ||
reporters: [reporter(this), 'flat'] | ||
})); | ||
} | ||
App.prototype._recreateTmpDirs = function() { | ||
var _this = this; | ||
return q.all([removeTreeIfExists(this.currentDir), removeTreeIfExists(this.diffDir)]) | ||
.then(function() { | ||
return q.all([ | ||
fs.makeDirectory(_this.currentDir), | ||
fs.makeDirectory(_this.diffDir) | ||
]); | ||
}); | ||
}; | ||
_recreateTmpDirs() { | ||
return q.all([removeTreeIfExists(this.currentDir), removeTreeIfExists(this.diffDir)]) | ||
.then(() => q.all([ | ||
fs.makeDirectory(this.currentDir), | ||
fs.makeDirectory(this.diffDir) | ||
])); | ||
} | ||
App.prototype.buildDiff = function(failureReport) { | ||
var _this = this; | ||
return this._buildDiffFile(failureReport) | ||
.then(function(diffPath) { | ||
return _this.diffPathToURL(diffPath); | ||
}); | ||
}; | ||
buildDiff(failureReport) { | ||
return this._buildDiffFile(failureReport) | ||
.then((diffPath) => this.diffPathToURL(diffPath)); | ||
} | ||
App.prototype._buildDiffFile = function(failureReport) { | ||
var diffPath = temp.path({dir: this.diffDir, suffix: '.png'}); | ||
return failureReport.saveDiffTo(diffPath).thenResolve(diffPath); | ||
}; | ||
_buildDiffFile(failureReport) { | ||
const diffPath = temp.path({dir: this.diffDir, suffix: '.png'}); | ||
return failureReport.saveDiffTo(diffPath).thenResolve(diffPath); | ||
} | ||
App.prototype.addNoReferenceTest = function(test) { | ||
//adding ref path here because gemini requires real suite to calc ref path | ||
//and on client we have just stringified path | ||
test.referencePath = this.getScreenshotPath(test.suite, test.state.name, test.browserId); | ||
this.addFailedTest(test); | ||
}; | ||
addNoReferenceTest(test) { | ||
//adding ref path here because gemini requires real suite to calc ref path | ||
//and on client we have just stringified path | ||
test.referencePath = this.getScreenshotPath(test.suite, test.state.name, test.browserId); | ||
this.addFailedTest(test); | ||
} | ||
App.prototype.addFailedTest = function(test) { | ||
this._failedTests.add(test); | ||
}; | ||
addFailedTest(test) { | ||
this._failedTests.add(test); | ||
} | ||
App.prototype.updateReferenceImage = function(testData) { | ||
var _this = this, | ||
test = this._failedTests.find(testData); | ||
updateReferenceImage(testData) { | ||
const test = this._failedTests.find(testData); | ||
if (!test) { | ||
return q.reject(new Error('No such test failed')); | ||
if (!test) { | ||
return q.reject(new Error('No such test failed')); | ||
} | ||
const result = { | ||
imagePath: test.referencePath, | ||
updated: true, | ||
suite: test.state.suite, | ||
state: test.state, | ||
browserId: test.browserId | ||
}; | ||
return fs.makeTree(path.dirname(test.referencePath)) | ||
.then(() => fs.copy(test.currentPath, test.referencePath)) | ||
.then(() => { | ||
this._runner.emit('updateResult', result); | ||
return this.refPathToURL(test.referencePath, test.browserId); | ||
}); | ||
} | ||
return fs.makeTree(path.dirname(test.referencePath)) | ||
.then(function() { | ||
return fs.copy(test.currentPath, test.referencePath); | ||
}) | ||
.then(function() { | ||
console.log('Reference image %s has been updated.', test.referencePath); | ||
return _this.refPathToURL(test.referencePath, test.browserId); | ||
}); | ||
}; | ||
getScreenshotPath(suite, stateName, browserId) { | ||
return this._gemini.getScreenshotPath(suite, stateName, browserId); | ||
} | ||
App.prototype.getScreenshotPath = function(suite, stateName, browserId) { | ||
return this._gemini.getScreenshotPath(suite, stateName, browserId); | ||
}; | ||
getBrowserCapabilites(browserId) { | ||
return this._gemini.getBrowserCapabilites(browserId); | ||
} | ||
App.prototype.getBrowserCapabilites = function(browserId) { | ||
return this._gemini.getBrowserCapabilites(browserId); | ||
}; | ||
refPathToURL(fullPath, browserId) { | ||
return this._appendTimestampToURL( | ||
this._pathToURL(this.referenceDirs[browserId], fullPath, App.refPrefix + '/' + browserId) | ||
); | ||
} | ||
App.prototype.refPathToURL = function(fullPath, browserId) { | ||
return this._appendTimestampToURL( | ||
this._pathToURL(this.referenceDirs[browserId], fullPath, App.refPrefix + '/' + browserId) | ||
); | ||
}; | ||
currentPathToURL(fullPath) { | ||
return this._appendTimestampToURL( | ||
this._pathToURL(this.currentDir, fullPath, App.currentPrefix) | ||
); | ||
} | ||
App.prototype.currentPathToURL = function(fullPath) { | ||
return this._appendTimestampToURL( | ||
this._pathToURL(this.currentDir, fullPath, App.currentPrefix) | ||
); | ||
}; | ||
// add query string timestamp to avoid caching on client | ||
_appendTimestampToURL(URL) { | ||
return URL + '?t=' + new Date().valueOf(); | ||
} | ||
// add query string timestamp to avoid caching on client | ||
App.prototype._appendTimestampToURL = function(URL) { | ||
return URL + '?t=' + new Date().valueOf(); | ||
}; | ||
diffPathToURL(fullPath) { | ||
return this._pathToURL(this.diffDir, fullPath, App.diffPrefix); | ||
} | ||
App.prototype.diffPathToURL = function(fullPath) { | ||
return this._pathToURL(this.diffDir, fullPath, App.diffPrefix); | ||
}; | ||
_pathToURL(rootDir, fullPath, prefix) { | ||
const relPath = path.relative(rootDir, fullPath); | ||
return prefix + '/' + encodeURI(relPath); | ||
} | ||
App.prototype._pathToURL = function(rootDir, fullPath, prefix) { | ||
var relPath = path.relative(rootDir, fullPath); | ||
return prefix + '/' + encodeURI(relPath); | ||
}; | ||
static get refPrefix() { | ||
return '/ref'; | ||
} | ||
App.refPrefix = '/ref'; | ||
App.currentPrefix = '/curr'; | ||
App.diffPrefix = '/diff'; | ||
static get currentPrefix() { | ||
return '/curr'; | ||
} | ||
module.exports = App; | ||
static get diffPrefix() { | ||
return '/diff'; | ||
} | ||
}; |
'use strict'; | ||
var path = require('path'), | ||
opener = require('opener'), | ||
chalk = require('chalk'), | ||
pkg = require('../package.json'), | ||
server = require('./server'), | ||
program = require('commander'); | ||
const path = require('path'); | ||
const opener = require('opener'); | ||
const chalk = require('chalk'); | ||
const program = require('commander'); | ||
exports.run = function() { | ||
const pkg = require('../package.json'); | ||
const server = require('./server'); | ||
const collect = (newValue, array) => (array || []).concat(newValue); | ||
exports.run = () => { | ||
program | ||
@@ -21,3 +24,3 @@ .version(pkg.version) | ||
program.on('--help', function() { | ||
program.on('--help', () => { | ||
console.log('Also you can override gemini config options.'); | ||
@@ -28,10 +31,6 @@ console.log('See all possible options in gemini documentation.'); | ||
program.testFiles = [].concat(program.args); | ||
server.start(program).then(function(result) { | ||
console.log('GUI is running at %s', chalk.cyan(result.url)); | ||
server.start(program).then((result) => { | ||
console.log(`GUI is running at ${chalk.cyan(result.url)}`); | ||
opener(result.url); | ||
}).done(); | ||
}; | ||
function collect(newValue, array) { | ||
return (array || []).concat(newValue); | ||
} |
{ | ||
"name": "gemini-gui", | ||
"version": "4.2.1", | ||
"version": "4.3.0", | ||
"description": "GUI for gemini testing utility", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is too big to display
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
879462
59
2030
1