-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
50 lines (41 loc) · 1.71 KB
/
test.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
const _ = require('lodash');
const exec = require('child_process').execSync;
const pluralize = require('pluralize');
const bandname = require('bandname');
const mkdirp = require('mkdirp');
const rimraf = require('rimraf');
const path = require('path');
const os = require('os');
const randomString = () => bandname().split(/[^\w]+/).slice(0, 2).join('_');
const pluralizableString = () => {
let name;
do {
name = randomString();
} while (name === pluralize(name) || name.length > 15);
return name.toLowerCase();
};
let dir;
if (process.env.SLOW_TEST) {
dir = path.join(os.tmpdir(), 'dendritic_tests', randomString());
} else {
dir = path.join(__dirname, 'dendritic_tests', randomString());
}
mkdirp.sync(dir);
const opts = { cwd: dir, stdio: 'inherit' };
const index = path.join(__dirname, 'index.js');
const appName = `dendritic_tests_${randomString()}`;
const modelName1 = pluralizableString();
const modelName2 = pluralizableString();
const userName = `${pluralizableString()}_user`;
exec(['node', index, 'base', appName].join(' '), opts);
exec(['node', index, 'resource', modelName1].join(' '), opts);
exec(['node', index, 'resource', modelName2, '-s', modelName1].join(' '), opts);
exec(['node', index, 'user', userName, '-m', modelName2].join(' '), opts);
exec(['node', index, 'migration'].join(' '), opts); // eslint only
if (process.env.SLOW_TEST) exec(['npm', 'install'].join(' '), opts);
exec(['cp', 'example.env', '.env'].join(' '), opts);
exec(['npm', 'test'].join(' '), opts);
exec(['npm', 'run', 'testdendritic'].join(' '), _.omit(opts, 'cwd'));
exec(['./node_modules/.bin/eslint', './dendritic_tests/'].join(' '), _.omit(opts, 'cwd'));
exec(['npm', 'run', 'lint'].join(' '), _.omit(opts, 'cwd'));
rimraf.sync(dir);