This repository was archived by the owner on Sep 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathapp.js
More file actions
133 lines (112 loc) · 3.86 KB
/
Copy pathapp.js
File metadata and controls
133 lines (112 loc) · 3.86 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
'use strict';
var path = require('path'),
q = require('q'),
fs = require('q-io/fs'),
temp = require('temp'),
findGemini = require('./find-gemini'),
Tests = require('./tests-model'),
Index = require('./common/tests-index'),
EventSource = require('./event-source'),
reporter = require('./reporter');
function removeTreeIfExists(path) {
return fs.exists(path)
.then(function(exists) {
if (exists) {
return fs.removeTree(path);
}
});
}
function App(options) {
this.diffDir = temp.path('gemini-gui-diff');
this.currentDir = temp.path('gemini-gui-curr');
this._eventSource = new EventSource();
var Gemini = findGemini();
this._gemini = new Gemini(options.configFile, options);
this.referenceDir = this._gemini.config.screenshotsDir;
this.browserIds = this._gemini.browserIds;
}
App.prototype.addClient = function(connection) {
this._eventSource.addConnection(connection);
};
App.prototype.sendClientEvent = function(event, data) {
this._eventSource.emit(event, data);
};
App.prototype.readTests = function(paths) {
var _this = this;
if (!this._tests) {
return this._gemini.readTests(paths)
.then(function(rootSuite) {
_this._rootSuite = rootSuite;
_this._tests = new Tests(_this, rootSuite);
return _this._tests.data;
});
}
return q.resolve(this._tests.data);
};
App.prototype.run = function(paths) {
var _this = this;
this._failedTests = new Index();
return this._recreateTmpDirs()
.then(function() {
return _this._gemini.test(paths, {
reporters: [reporter(_this)],
tempDir: _this.currentDir
});
});
};
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)
]);
});
};
App.prototype.buildDiff = function(referencePath, currentPath) {
var _this = this,
diffPath = temp.path({dir: this.diffDir, suffix: '.png'});
return this._gemini.buildDiff(referencePath, currentPath, diffPath)
.then(function() {
return _this.diffPathToURL(diffPath);
});
};
App.prototype.addFailedTest = function(test) {
this._failedTests.add(test);
};
App.prototype.updateReferenceImage = function(testData) {
var _this = this,
test = this._failedTests.find(testData);
if (!test) {
return q.reject(new Error('No such test failed'));
}
return fs.copy(test.currentPath, test.referencePath)
.then(function() {
// add query string timestamp to avoid caching on client
return _this.refPathToURL(test.referencePath) + '?t=' + new Date().valueOf();
});
};
App.prototype.getScreenshotPath = function(suite, stateName, browserId) {
return this._gemini.getScreenshotPath(suite, stateName, browserId);
};
App.prototype.getBrowserCapabilites = function(browserId) {
return this._gemini.getBrowserCapabilites(browserId);
};
App.prototype.refPathToURL = function(fullPath) {
return this._pathToURL(this.referenceDir, fullPath, App.refPrefix);
};
App.prototype.currentPathToURL = function(fullPath) {
return this._pathToURL(this.currentDir, fullPath, App.currentPrefix);
};
App.prototype.diffPathToURL = function(fullPath) {
return this._pathToURL(this.diffDir, fullPath, App.diffPrefix);
};
App.prototype._pathToURL = function(rootDir, fullPath, prefix) {
var relPath = path.relative(rootDir, fullPath);
return prefix + '/' + encodeURI(relPath);
};
App.refPrefix = '/ref';
App.currentPrefix = '/curr';
App.diffPrefix = '/diff';
module.exports = App;