This repository was archived by the owner on Sep 21, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathtester.js
More file actions
70 lines (60 loc) · 2.14 KB
/
Copy pathtester.js
File metadata and controls
70 lines (60 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
851E
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'use strict';
var q = require('q'),
inherit = require('inherit'),
fs = require('q-io/fs'),
temp = require('temp'),
Runner = require('./runner'),
Image = require('./image'),
StateError = require('./errors/state-error');
temp.track();
module.exports = inherit(Runner, {
__constructor: function(config, options) {
this.__base(config);
options = options || {};
this._tempDir = options.tempDir || temp.path('gemini');
},
_prepare: function() {
return fs.makeTree(this._tempDir);
},
_processCapture: function(capture) {
var refPath = this.config.getScreenshotPath(
capture.suite,
capture.state.name,
capture.browser.id),
tmpPath = this._tempPath(),
_this = this;
return fs.exists(refPath)
.then(function(refExists) {
if (!refExists) {
return q.reject(new StateError(
'Can not find reference image at ' + refPath + '\n' +
'Run `gemini gather` command to capture all reference images.'
));
}
})
.then(function() {
return capture.image.save(tmpPath);
})
.then(function() {
return [tmpPath, Image.compare(tmpPath, refPath, {
strictComparison: _this.config.strictComparison,
canHaveCaret: capture.canHaveCaret
})];
})
.spread(function(currentPath, isEqual) {
_this._stats.add(isEqual? 'passed' : 'failed');
_this.emit('endTest', {
suiteName: capture.suite.name,
suiteId: capture.suite.id,
stateName: capture.state.name,
equal: isEqual,
referencePath: refPath,
currentPath: currentPath,
browserId: capture.browser.id
});
});
},
_tempPath: function() {
return temp.path({dir: this._tempDir, suffix: '.png'});
}
});