-
Notifications
You must be signed in to change notification settings - Fork 3
/
pretest.js
33 lines (28 loc) · 1.08 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
'use strict';
function init() {
if (!process.env.CI) {
return console.log('not seeding DB with test db');
}
var fs = require('fs');
var cp = require('child_process');
var sql = fs.createReadStream(require.resolve('./test/schema.sql'));
var stdio = ['pipe', process.stdout, process.stderr];
process.env.PGHOST = process.env.TEST_POSTGRESQL_HOST ||
process.env.POSTGRESQL_HOST || process.env.PGHOST || 'localhost';
process.env.PGPORT = process.env.TEST_POSTGRESQL_PORT ||
process.env.POSTGRESQL_PORT || process.env.PGPORT || 5432;
process.env.PGUSER = process.env.TEST_POSTGRESQL_USER ||
process.env.POSTGRESQL_USER || process.env.PGUSER || 'test';
process.env.PGPASSWORD = process.env.TEST_POSTGRESQL_PASSWORD ||
process.env.POSTGRESQL_PASSWORD || process.env.PGPASSWORD || 'test';
console.log('seeding DB with test db...');
var psql = cp.spawn('psql', {stdio: stdio});
sql.pipe(psql.stdin);
psql.on('exit', function(code) {
console.log('done seeding DB');
setTimeout(function() {
process.exit(code);
}, 200);
});
}
init()