forked from approvals/Approvals.NodeJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
138 lines (112 loc) · 4.65 KB
/
config.js
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
134
135
136
137
138
'use strict';
var userHome = require('user-home');
var fs = require('fs');
var path = require('path');
var _ = require("lodash");
var yaml = require('js-yaml');
var reportingLaunchingCircuitBreaker = require('./Reporting/ReportLaunchingCircuitBreaker');
// begin-snippet: default_config
var defaultConfig = {
// The strategy for determining which reporter to use will likely
// change at some point. For now, you can configure priority here.
// What I'd prefer is if each project has a configuration file
// and each user could setup a ~/.approvalConfig file
// which would contain their preferred merge/diff tools
reporters: [
"opendiff",
"p4merge",
"tortoisemerge",
"nodediff",
"gitdiff",
/* OR a custom reporter object. See the above example of how to create a custom reporter. */
],
// If you need to normalize text file line-endings
// you can set this to something like "\n" or "\r\n"
//
// default value here of false or undefined will not apply any
// line-ending replacement before writing the approval received file
normalizeLineEndingsTo: false, // default
// If approvals determines things are different, it will replacement
// line endings CRLF with just LF and re-compare. If they are the same
// approvals will log a warning that the files are the same except for
// line endings. Flip this to `true` to fail tests if line-endings
// are different
failOnLineEndingDifferences: false,
// Some diff tools automatically append an EOL to a merge file
// Setting this to true helps with those cases... (Also see EOL below
// for what is appended)
appendEOL: true,
// When appendEOL above is true, this value defines what will be appended at the end of the file.
// It's really a bad name as it's not End-of-Line... but -end-of-file err end-of-line-at-end-of-file :P
EOL: require('os').EOL,
// This helps keep the project clean of files
// that became stale due to removal of tests
// or after a rename
errorOnStaleApprovedFiles: true,
// This is a function called when the proc is exiting and we're
// validating any stale *.approved.txt files. You can override
// this function to ignore validation of some files or not
shouldIgnoreStaleApprovedFile: function(/*fileName*/) { return false; },
// On some files or projects a Byte Order
// Mark can be inserted and cause issues,
// this allows you to force it to be stripped
stripBOM: false,
//DANGER: this can be used to force-approve a file during a test run.
// Can be used for first time-run or if lots of tests are failing because
// of a change you know is correct. AGAIN DANGER - don't ever check code
// in that configures this to be on...)
forceApproveAll: false,
// Default to `false` - launching each diff tool in the background, failing the test and
// moving on to the next test. If `true` will launch the diff tool and block/wait (if diff tool supports this) until
// the user exits the diff tool before continuing on with the rest of the tests.
blockUntilReporterExits: false,
// The number of reporters (diff tools) launched before before approval tests stops launching new reporters.
// This is to avoid overloading a system with too many processes.
// NOTE: This value is only used if `blockUntilReporterExits` is `false`.
maxLaunches: 10
};
// end-snippet
var getHomeApprovalConfig = function () {
var homeConfigPath = path.join(userHome, '.approvalsConfig');
if (fs.existsSync(homeConfigPath)) {
// Get document, or throw exception on error
var configFileData = fs.readFileSync(homeConfigPath).toString();
try {
return yaml.load(configFileData);
} catch (ex) {
throw new Error("Error parsing " + homeConfigPath + ". " + ex);
}
}
return null;
};
var currentConfigObj;
var getConfig = function (configOverrides) {
var homeConfig = getHomeApprovalConfig() || {};
var resultConfig = _.defaults(configOverrides || {}, currentConfigObj || {}, homeConfig, defaultConfig);
return resultConfig;
};
var configure = function (overrideOptions) {
currentConfigObj = getConfig(overrideOptions);
processConfig(currentConfigObj);
return currentConfigObj;
};
var currentConfig = function () {
return currentConfigObj;
};
var reset = function () {
currentConfigObj = _.defaults({}, getHomeApprovalConfig(), defaultConfig)
};
currentConfigObj = getConfig();
function processConfig(config) {
if (config.maxLaunches) {
reportingLaunchingCircuitBreaker.setMaxLaunch(config.maxLaunches);
}
}
module.exports = {
getConfig: getConfig,
getHomeApprovalConfig: getHomeApprovalConfig,
defaultConfig: defaultConfig,
configure: configure,
currentConfig: currentConfig,
reset: reset
};