-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGruntfile.js
173 lines (149 loc) · 4.43 KB
/
Gruntfile.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
var path = require('path');
var cp = require('child_process');
var shell = require('shelljs');
var depPath = require('./util/dep-path');
module.exports = function(grunt) {
'use strict';
// load npm tasks
require('load-grunt-tasks')(grunt);
grunt.loadNpmTasks('intern');
var env = process.env;
env.HOODIE_SETUP_PASSWORD = '12345';
var ports = require('./ports');
var appname = 'myapp';
// Project configuration.
grunt.initConfig({
watch: {
dev: {
files: ['tests/**/*'],
tasks: [
'rm-data',
'hoodie:start',
'intern:tests',
'hoodie:stop',
]
},
gruntfile: {
files: ['Gruntfile.js']
}
},
hoodie: {
start: {
options: {
childProcessOptions: {
cwd: process.cwd() + '/myapp',
env: env
},
'custom-ports': [ports.www, ports.admin, ports.couch].join(','),
callback: function(config) {
var output = {};
Object.keys(config.stack).forEach(function(type) {
if (config.stack[type].port !== ports[type]) {
grunt.fail.fatal('Hoodie not running on custom ports');
}
grunt.log.ok('Hoodie running on correct ' + type + ' port: ' + ports[type]);
output[type] = 'http://' +
config.stack[type].host +
':' +
config.stack[type].port +
'/';
});
var fs = require('fs');
fs.writeFileSync('./hosts.json', JSON.stringify(output, null, 2));
grunt.log.writeflags(ports, 'Hoodie running on correct ports');
}
}
},
stop: {}
},
shell: {
options: {
execOptions: {
// https://www.npmjs.com/package/grunt-shell#execoptions
maxBuffer: 400*1024
}
},
createApp: {
command: './node_modules/.bin/hoodie new ' + appname
},
installTestPlugin: {
command: 'cd ' + appname + ' && ./../node_modules/.bin/hoodie install test && cd -'
}
},
intern: {
options: {
config: 'intern.js',
runType: 'runner'
},
tests: {}
}
});
grunt.registerTask('install-selenium', function() {
shell.exec('sh util/install-selenium.sh');
});
grunt.registerTask('rm-app', function() {
shell.rm('-rf', 'myapp');
});
grunt.registerTask('rm-data', function() {
shell.rm('-rf', 'myapp/data');
});
// Default task(s).
grunt.registerTask('dev', [
'rm-app',
'shell:createApp',
'shell:installTestPlugin',
'watch'
]);
grunt.registerTask('test', function() {
var module = this.args.join('');
var tasksPre = ['shell:createApp', 'shell:installTestPlugin'];
var tasksPost = ['hoodie:start', 'intern:tests', 'hoodie:stop', 'rm-app'];
if (process.env.CI) {
tasksPre.push('install-selenium');
}
if (!module) {
return grunt.task.run(tasksPre.concat(tasksPost));
}
grunt.registerTask('deep-link', function() {
var done = this.async();
var modulePath = depPath.dependenciesMap[module];
if (!modulePath) {
grunt.log.warn('Dependencies do not contain the module ' + module);
return done();
}
cp.exec('npm link ' + module, {
cwd: path.resolve(path.join(appname, modulePath)),
maxBuffer: 400*1024
}, function(err, stdout, stderr) {
if (err) {
console.log('execution error: ', err);
}
console.log(stdout);
console.log(stderr);
grunt.task.run(tasksPost);
done();
});
// see https://github.com/hoodiehq/hoodie-integration-test/issues/19
// depPath(appname, module, function(depPath) {
// if (!depPath) {
// grunt.log.warn('Dependencies do not contain the module ' + module);
// return done();
// }
// cp.exec('npm link ' + module, {
// cwd: path.resolve(path.join(appname, depPath)),
// maxBuffer: 400*1024
// }, function(err, stdout, stderr) {
// if (err) {
// console.log('execution error: ', err);
// }
// console.log(stdout);
// console.log(stderr);
// grunt.task.run(tasksPost);
// done();
// });
// });
});
grunt.task.run(tasksPre.concat(['deep-link']));
});
grunt.registerTask('default', ['rm-app', 'test']);
};