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
91 lines (79 loc) · 2.94 KB
/
Copy pathtester.js
File metadata and controls
91 lines (79 loc) · 2.94 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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
'use strict';
var q = require('q'),
inherit = require('inherit'),
fs = require('q-io/fs'),
temp = require('temp'),
Runner = require('./runner'),
Image = require('./image'),
NoRefImageError = require('./errors/no-ref-image-error'),
RunnerEvents = require('./constants/runner-events');
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 browserConfig = capture.browser.config,
refPath = browserConfig.getScreenshotPath(
capture.suite,
capture.state.name
),
tmpPath = this._tempPath(),
tolerance = capture.state.tolerance,
_this = this;
if (!tolerance && tolerance !== 0) {
tolerance = browserConfig.tolerance;
}
return capture.image.save(tmpPath)
.then(function() {
return fs.exists(refPath);
})
.then(function(refExists) {
if (!refExists) {
return q.reject(new NoRefImageError(refPath,
{
suite: capture.suite,
state: capture.state,
currentPath: tmpPath,
browserId: capture.browser.id
}));
}
})
.then(function() {
return [tmpPath, Image.compare(tmpPath, refPath, {
strictComparison: browserConfig.strictComparison,
canHaveCaret: capture.canHaveCaret,
tolerance: tolerance
})];
})
.spread(function(currentPath, isEqual) {
_this.emit(RunnerEvents.END_TEST, {
suite: capture.suite,
state: capture.state,
referencePath: refPath,
currentPath: currentPath,
browserId: capture.browser.id,
sessionId: capture.browser.sessionId,
equal: isEqual,
saveDiffTo: function(diffPath) {
return Image.buildDiff({
reference: refPath,
current: currentPath,
diff: diffPath,
diffColor: _this.config.system.diffColor,
tolerance: tolerance,
strictComparison: browserConfig.strictComparison
});
}
});
});
},
_tempPath: function() {
return temp.path({dir: this._tempDir, suffix: '.png'});
}
});