gemini-gui
Advanced tools
Comparing version 5.0.0-alpha.6 to 5.0.0-alpha.7
@@ -54,2 +54,14 @@ 'use strict'; | ||
return this._recreateTmpDirs() | ||
.then(() => { | ||
const reusePath = this._options.reuse; | ||
if (!reusePath) { | ||
return; | ||
} | ||
try { | ||
this._reuseData = require(path.resolve(reusePath)); | ||
} catch (e) { | ||
throw new Error(`Nothing to reuse in ${reusePath}`); | ||
} | ||
}) | ||
.then(this._readTests.bind(this)); | ||
@@ -70,2 +82,6 @@ } | ||
getTestsStatus() { | ||
return Promise.resolve(this._tests.status); | ||
} | ||
_readTests() { | ||
@@ -93,3 +109,5 @@ const opts = this._options; | ||
.then(() => { | ||
this._tests = new Tests(this, this._collection); | ||
const suites = (this._reuseData || {}).suites; | ||
this._tests = new Tests(this); | ||
return this._tests.initialize(this._collection, suites); | ||
}); | ||
@@ -153,3 +171,7 @@ } | ||
.then(() => { | ||
this._runner.emit('updateResult', result); | ||
// if haven't run tests before updating screenshot then no runner present | ||
// this happens when we reuse result | ||
if (this._runner) { | ||
this._runner.emit('updateResult', result); | ||
} | ||
return this.refPathToURL(test.referencePath, test.browserId); | ||
@@ -171,2 +193,10 @@ }); | ||
createCurrentPathFor() { | ||
return temp.path({dir: this.currentDir, suffix: '.png'}); | ||
} | ||
createDiffPathFor() { | ||
return temp.path({dir: this.diffDir, suffix: '.png'}); | ||
} | ||
refPathToURL(fullPath, browserId) { | ||
@@ -198,2 +228,7 @@ return this._appendTimestampToURL( | ||
copyImage(srcRelPath, dstPath) { | ||
const srcPath = path.resolve(path.dirname(this._options.reuse), srcRelPath); | ||
return fs.copyAsync(srcPath, dstPath); | ||
} | ||
static get refPrefix() { | ||
@@ -200,0 +235,0 @@ return '/ref'; |
@@ -24,2 +24,3 @@ 'use strict'; | ||
.option('-O, --no-open', 'not to open a browser window after starting the server') | ||
.option('-r, --reuse <filepath>', 'Filepath to gemini tests results to reuse') | ||
.parse(process.argv); | ||
@@ -26,0 +27,0 @@ |
@@ -20,3 +20,4 @@ 'use strict'; | ||
'fail', | ||
'skip' | ||
'skipped', | ||
'error' | ||
]; | ||
@@ -65,2 +66,24 @@ | ||
}); | ||
// for state: change suite controls state according to state initial status | ||
if (this.browserId) { | ||
var retry = this.retry.bind(this); | ||
this._suiteControls = new SuiteControls(this._bodyNode); | ||
switch (this._status) { | ||
case 'success': { | ||
this._suiteControls.setAsSuccess(retry); | ||
break; | ||
} | ||
case 'fail': { | ||
this._suiteControls.setAsFailure(retry, this.updateReference.bind(this)); | ||
break; | ||
} | ||
case 'error': { | ||
this.status = 'fail'; | ||
this._suiteControls.setAsError(retry); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
@@ -67,0 +90,0 @@ |
@@ -37,3 +37,3 @@ 'use strict'; | ||
_enableIfNotRunning: function(button) { | ||
var isRunning = window.controller.state === 'running'; | ||
var isRunning = window.controller && window.controller.state === 'running'; | ||
@@ -40,0 +40,0 @@ this._setButtonEnabled(button, !isRunning); |
@@ -19,3 +19,22 @@ 'use strict'; | ||
}, | ||
partialsDir: path.join(__dirname, 'views', 'partials') | ||
partialsDir: path.join(__dirname, 'views', 'partials'), | ||
helpers: { | ||
ifCond: function(a, op, b, options) { | ||
switch (op) { | ||
case '===': return (a === b) ? options.fn(this) : options.inverse(this); | ||
case '!==': return (a !== b) ? options.fn(this) : options.inverse(this); | ||
default: return options.inverse(this); | ||
} | ||
}, | ||
ifShouldCollapse: function(status, options) { | ||
switch (status) { | ||
case 'fail': | ||
case 'error': return options.inverse(this); | ||
default: return options.fn(this); | ||
} | ||
}, | ||
sectionStatus: function() { | ||
return this.status === 'error' ? 'fail' : this.status; | ||
} | ||
} | ||
})); | ||
@@ -35,6 +54,7 @@ | ||
server.get('/', function(req, res) { | ||
app.getTests() | ||
.then(function(suites) { | ||
Promise.all([app.getTests(), app.getTestsStatus()]) | ||
.spread(function(suites, status) { | ||
res.render('main', { | ||
suites: suites, | ||
suites, | ||
status, | ||
autoRun: options.autoRun | ||
@@ -41,0 +61,0 @@ }); |
'use strict'; | ||
var Index = require('./common/tests-index'), | ||
utils = require('./utils'); | ||
// | ||
//TODO: | ||
function Tests(app, suiteCollection) { | ||
const _ = require('lodash'); | ||
const Promise = require('bluebird'); | ||
const Index = require('./common/tests-index'); | ||
const utils = require('./utils'); | ||
const getStatus = (skipped, reuse) => { | ||
if (skipped) { | ||
return 'skipped'; | ||
} | ||
return _.findKey(_.get(reuse, 'result'), (value) => value === true) || 'idle'; | ||
}; | ||
const suiteOrStateStatus = (items) => { | ||
const groups = _.groupBy(items, 'status'); | ||
if (!_.isEmpty(groups.error)) { | ||
return 'error'; | ||
} | ||
if (!_.isEmpty(groups.fail)) { | ||
return 'fail'; | ||
} | ||
if (!_.isEmpty(groups.idle)) { | ||
return 'idle'; | ||
} | ||
if (!_.isEmpty(groups.success)) { | ||
return 'success'; | ||
} | ||
return 'skipped'; | ||
}; | ||
function Tests(app) { | ||
this._app = app; | ||
this._index = new Index(); | ||
this._data = this._mapSuites(suiteCollection.topLevelSuites()); | ||
} | ||
@@ -15,2 +45,3 @@ | ||
constructor: Tests, | ||
get data() { | ||
@@ -20,46 +51,106 @@ return this._data; | ||
_mapSuites: function(suites) { | ||
return suites.map(function(suite) { | ||
var data = { | ||
suite: suite, | ||
children: this._mapSuites(suite.children), | ||
status: 'idle', | ||
states: this._mapStates(suite) | ||
}; | ||
data.suite.skipComment && (data.suite.skipComment = utils.wrapLinkByTag(data.suite.skipComment)); | ||
this._index.add(data); | ||
return data; | ||
}, this); | ||
get status() { | ||
return this._status; | ||
}, | ||
_mapStates: function(suite) { | ||
return suite.states.map(function(state) { | ||
var data = { | ||
suite: suite, | ||
state: state, | ||
browsers: this._getBrowsersData(suite, state) | ||
}; | ||
this._index.add(data); | ||
return data; | ||
}, this); | ||
initialize(suiteCollection, rawReuseSuites) { | ||
const reuseSuites = rawReuseSuites || []; | ||
return this._mapSuites(suiteCollection.topLevelSuites(), reuseSuites) | ||
.then((data) => { | ||
this._data = data; | ||
this._status = suiteOrStateStatus(this._data); | ||
}); | ||
}, | ||
_getBrowsersData: function(suite, state) { | ||
return suite.browsers.map(function(browserId) { | ||
var fullPath = this._app.getScreenshotPath(suite, state.name, browserId), | ||
data = { | ||
suite: suite, | ||
state: state, | ||
browserId: browserId, | ||
metaInfo: state && state.metaInfo ? JSON.stringify(state.metaInfo, null, 4) : 'Meta info is not available', | ||
skipped: state.shouldSkip(browserId), | ||
referenceURL: this._app.refPathToURL(fullPath, browserId), | ||
rootUrl: this._app.getRootUrlforBrowser(browserId) | ||
}; | ||
_mapSuites: function(suites, reuseSuites) { | ||
return Promise.all(suites.map((suite) => { | ||
const reuse = _.find(reuseSuites, {name: suite.name, suitePath: suite.path}); | ||
const reuseChildren = _.get(reuse, 'children') || []; | ||
this._index.add(data); | ||
return data; | ||
}, this); | ||
return Promise.all([ | ||
this._mapSuites(suite.children, reuseChildren), | ||
this._mapStates(suite, reuseChildren) | ||
]).spread((children, states) => { | ||
const status = suiteOrStateStatus(children.concat(states)); | ||
const data = {suite, children, states, status}; | ||
data.suite.skipComment && (data.suite.skipComment = utils.wrapLinkByTag(data.suite.skipComment)); | ||
this._index.add(data); | ||
return data; | ||
}); | ||
})); | ||
}, | ||
_mapStates: function(suite, reuseStates) { | ||
return Promise.all(suite.states.map((state) => { | ||
const reuse = _.find(reuseStates, {name: state.name, suitePath: suite.path.concat(state.name)}); | ||
return this._getBrowsersData(suite, state, _.get(reuse, 'browsers')) | ||
.then((browsers) => { | ||
const status = suiteOrStateStatus(browsers); | ||
const data = {suite, state, browsers, status}; | ||
this._index.add(data); | ||
return data; | ||
}); | ||
})); | ||
}, | ||
_getBrowsersData: function(suite, state, reuseBrowsers) { | ||
return Promise.all(suite.browsers.map((browserId) => { | ||
const reuse = _.find(reuseBrowsers, {name: browserId}); | ||
const metaInfoObj = Object.assign( | ||
{}, | ||
state.metaInfo, | ||
reuse && reuse.result.metaInfo && JSON.parse(reuse.result.metaInfo) | ||
); | ||
const metaInfo = !_.isEmpty(metaInfoObj) | ||
? JSON.stringify(metaInfoObj, null, 4) | ||
: 'Meta info is not available'; | ||
const referencePath = this._app.getScreenshotPath(suite, state.name, browserId); | ||
const status = getStatus(state.shouldSkip(browserId), reuse); | ||
// if status is 'success' then actualPath is present, but there is no image | ||
const currentPath = reuse && reuse.result.actualPath && status !== 'success' | ||
&& this._app.createCurrentPathFor(); | ||
const diffPath = reuse && reuse.result.diffPath && this._app.createDiffPathFor(); | ||
const copyImagePromises = [ | ||
currentPath ? this._app.copyImage(reuse.result.actualPath, currentPath) : Promise.resolve(), | ||
diffPath ? this._app.copyImage(reuse.result.diffPath, diffPath) : Promise.resolve() | ||
]; | ||
return Promise.all(copyImagePromises) | ||
.then(() => { | ||
if (status === 'skipped') { | ||
suite.skipComment = _.get(reuse, 'result.reason'); | ||
} | ||
const data = { | ||
suite, | ||
state, | ||
browserId, | ||
metaInfo, | ||
referenceURL: this._app.refPathToURL(referencePath, browserId), | ||
currentURL: currentPath && this._app.currentPathToURL(currentPath), | ||
diffURL: diffPath && this._app.diffPathToURL(diffPath), | ||
rootUrl: this._app.getRootUrlforBrowser(browserId), | ||
status, | ||
stack: status === 'error' && _.get(reuse, 'result.reason') | ||
}; | ||
if (data.status === 'fail') { | ||
this._app.addFailedTest({suite, state, browserId, referencePath, currentPath}); | ||
} | ||
this._index.add(data); | ||
return data; | ||
}); | ||
})); | ||
}, | ||
find: function(query) { | ||
@@ -66,0 +157,0 @@ return this._index.find(query); |
{ | ||
"name": "gemini-gui", | ||
"version": "5.0.0-alpha.6", | ||
"version": "5.0.0-alpha.7", | ||
"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
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
1108646
63
2519
7
1