forked from gemini-testing/gemini
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgemini.js
More file actions
121 lines (102 loc) · 3.47 KB
/
Copy pathgemini.js
File metadata and controls
121 lines (102 loc) · 3.47 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
'use strict';
var path = require('path'),
ScreenShooter = require('./screen-shooter'),
Tester = require('./tester'),
Config = require('./config'),
Suite = require('./suite'),
pathUtils = require('./path-utils'),
publicApi = require('./public-api'),
exposeTestsApi = require('./tests-api'),
Image = require('./image');
var DEFAULT_CFG_NAME = '.gemini.yml',
DEFAULT_SPECS_DIR = 'gemini';
function requireWithNoCache(moduleName) {
var result = require(moduleName);
delete require.cache[moduleName];
return result;
}
function Gemini(config, overrides) {
config = config || DEFAULT_CFG_NAME;
this.config = new Config(config, overrides);
var _this = this;
function getDefaultSpecsDir() {
return path.join(_this.config.projectRoot, DEFAULT_SPECS_DIR);
}
function executeRunner(runnerInstance, paths, options) {
if (!options) {
//if there are only two arguments, they are
//(runnerInstance, options) and paths are
//the default.
options = paths;
paths = [getDefaultSpecsDir()];
}
options = options || {};
options.reporters = options.reporters || [];
if (options.grep) {
runnerInstance.setGrepPattern(options.grep);
}
return _this.readTests(paths)
.then(function(rootSuite) {
options.reporters.forEach(applyReporter.bind(null, runnerInstance));
return runnerInstance.run(rootSuite);
});
}
this.readTests = function(paths) {
paths = paths || [getDefaultSpecsDir()];
return pathUtils.expandPaths(paths)
.then(function(expanded) {
var rootSuite = Suite.create('');
exposeTestsApi(publicApi, rootSuite);
expanded.forEach(requireWithNoCache);
return rootSuite;
});
};
this.gather = function(paths, options) {
return executeRunner(new ScreenShooter(this.config), paths, options);
};
this.test = function(paths, options) {
return executeRunner(
new Tester(this.config, {tempDir: options.tempDir}),
paths,
options
);
};
this.getScreenshotPath = function(suite, stateName, browserId) {
return this.config.getScreenshotPath(suite, stateName, browserId);
};
this.buildDiff = function(referencePath, currentPath, diffPath) {
return Image.buildDiff({
reference: referencePath,
current: currentPath,
diff: diffPath,
diffColor: this.config.diffColor,
strictComparison: this.config.strictComparison
});
};
this.getBrowserCapabilites = function(browserId) {
return this.config.browsers[browserId];
};
Object.defineProperty(this, 'browserIds', {
enumerable: true,
get: function() {
return Object.keys(this.config.browsers);
}
});
}
function applyReporter(runner, reporter) {
if (typeof reporter === 'string') {
try {
reporter = require('./reporters/' + reporter);
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND') {
throw new Error('No such reporter: ' + reporter);
}
throw e;
}
}
if (typeof reporter !== 'function') {
throw new TypeError('Reporter must be a string or a function');
}
reporter(runner);
}
module.exports = Gemini;