-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpretest.js
54 lines (45 loc) · 1.38 KB
/
pretest.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
const console = require('console')
const fs = require('fs')
const process = require('process')
const testConfigPath = './config/mongodb.test.json'
const testConfigSamplePath = './config/mongodb.test.json.sample'
const testConfigSample = fs.readFileSync(testConfigSamplePath, {
encoding: 'utf-8',
})
function loadConfig(done) {
try {
const testConfig = fs.readFileSync(testConfigPath, {encoding: 'utf-8'})
return done(JSON.parse(testConfig))
} catch (err) {
if (err.code === 'ENOENT') {
fs.writeFileSync(testConfigPath, testConfigSample)
console.log()
console.log("Created file at '" + testConfigPath + "'")
loadConfig(function (config) {
testDatabaseSetting(config)
})
}
}
}
function stop() {
process.exit(1)
}
function testDatabaseSetting(config) {
const database = config.database.database
const authDatabase = config.auth.database.database
if (database !== 'test' || authDatabase !== 'test') {
const message =
'\nWARNING: The test suite requires the use of a `test` database. The databases for authentication and data can be configured in the file ' +
testConfigPath +
'.'
console.log(message.bold.red)
console.log('')
console.log(
'Tests will not be run with the current configuration.\n'.bold.red,
)
stop()
}
}
loadConfig(function (config) {
testDatabaseSetting(config)
})