forked from karma-runner/karma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJakefile
222 lines (172 loc) · 6.06 KB
/
Jakefile
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
var child = require('child_process');
var plainError = function(msg) {
var e = new Error(msg);
e.stack = '';
return e;
};
var header = function(msg) {
console.log('');
console.log('================================================================================');
console.log(msg);
console.log('================================================================================');
};
var ENV = {
env: process.env,
cwd: __dirname
};
var ASYNC = {
async: true
};
var BROWSER_CMD, BROWSER_ARGS, BROWSERS;
if (process.env.TRAVIS) {
BROWSER_CMD = '/usr/bin/firefox';
BROWSER_ARGS = ['http://localhost:8080'];
BROWSERS = 'Firefox';
} else {
BROWSER_CMD = '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary';
BROWSER_ARGS = ['--user-data-dir=tmp', '--disable-metrics', '--no-first-run',
'--no-default-browser-checkck', 'http://localhost:8080'];
BROWSERS = 'Chrome,ChromeCanary,Firefox';
}
desc('Run all tests.');
task('test', ['test:unit', 'test:client', 'test:client2'], function() {});
namespace('test', function() {
desc('Run unit tests.');
task('unit', function() {
header('Running nodejs unit tests...');
var jasmine = child.spawn('jasmine-node', ['--coffee', 'test/unit'], ENV);
jasmine.stdout.pipe(process.stdout);
jasmine.stderr.pipe(process.stderr);
jasmine.on('exit', function(code) {
if (code) fail(plainError('Unit tests failed.'), code);
complete();
});
}, ASYNC);
// TODO(vojta): make it nicer, timeouts, handle errors, etc
desc('Run client unit tests.');
task('client2', ['build'], function() {
header('Running client tests in a browser...');
var server, browser, timeout, runner;
server = child.spawn('node', ['bin/testacular', 'test/client/config.js'], ENV);
server.stdout.pipe(process.stdout);
server.stderr.pipe(process.stderr);
server.stdout.on('data', function(buffer) {
if (!runner && buffer.toString().indexOf('Connected on socket') !== -1) {
runner = child.exec('node bin/testacular-run', function(error, stdout, stderr) {
browser.kill();
server.kill();
if (timeout) clearTimeout(timeout);
if (error) fail(plainError('Client tests failed.'), 1);
complete();
});
}
if (!browser) {
browser = child.spawn(BROWSER_CMD, BROWSER_ARGS);
browser.on('exit', function() {
child.exec('rm -rdf tmp');
});
}
});
timeout = setTimeout(function() {
fail(plainError('Time-outed after 30s.'), 1);
}, 30000);
}, ASYNC);
desc('Run client unit tests using single run mode.');
task('client', ['build'], function() {
header('Running client tests in a browser using single run mode...');
var timeout, server;
server = child.spawn('node', ['bin/testacular', 'test/client/config.js', '--browsers', BROWSERS, '--single-run'], ENV);
server.stdout.pipe(process.stdout);
server.stderr.pipe(process.stderr);
server.on('exit', function(code) {
if (timeout) clearTimeout(timeout);
if (code) {
fail(plainError(''), code);
}
complete();
});
timeout = setTimeout(function() {
fail(plainError('Time-outed after 30s.'), 1);
}, 30000);
}, ASYNC);
});
desc('Build all.');
task('build', ['build:jasmine-adapter', 'build:client'], function() {});
namespace('build', function() {
desc('Build testacular client.');
task('client', function() {
header('Building static/testacular.js...');
jake.exec([
'sed -e "/%CONTENT%/r static/testacular.src.js" -e "/%CONTENT%/d" static/testacular.wrapper > static/testacular.js'
], function () {
console.log('Successfully build.');
complete();
});
}, ASYNC);
desc('Build jasmine adapter.');
task('jasmine-adapter', function() {
header('Building adapter/jasmine.js...');
jake.exec([
'sed -e "/%CONTENT%/r adapter/jasmine.src.js" -e "/%CONTENT%/d" adapter/jasmine.wrapper > adapter/jasmine.js'
], function () {
console.log('Successfully build.');
complete();
});
}, ASYNC);
});
desc('Bump minor version, update changelog, create tag, push to github.');
task('version', function () {
header('Bumping version...');
var fs = require('fs');
var packagePath = process.cwd() + '/package.json';
var pkg = JSON.parse(fs.readFileSync(packagePath).toString());
var versionArray = pkg.version.split('.');
var previousVersionTag = 'v' + pkg.version;
// bump minor version
versionArray.push(parseInt(versionArray.pop(), 10) + 1);
pkg.version = versionArray.join('.');
// Update package.json with the new version-info
fs.writeFileSync(packagePath, JSON.stringify(pkg, true, 2));
var TEMP_FILE = '.changelog.temp';
var message = 'Bump version to v' + pkg.version;
jake.exec([
// update changelog
'echo "### v' + pkg.version + '" > ' + TEMP_FILE,
'git log --grep="\\[changelog\\]" --pretty=%s ' + previousVersionTag + '..HEAD >> ' + TEMP_FILE,
'echo "" >> ' + TEMP_FILE,
'mvim CHANGELOG.md -c ":0r ' + TEMP_FILE + '"',
'rm ' + TEMP_FILE,
// commit + push to github
'git commit package.json CHANGELOG.md -m "' + message + '"',
'git push origin master',
'git tag -a v' + pkg.version + ' -m "Version ' + pkg.version + '"',
'git push --tags'
], function () {
console.log(message);
complete();
});
}, ASYNC);
desc('Build, bump version, publish to npm.');
task('publish', ['version', 'build'], function() {
header('Publishing to npmjs.org...');
jake.exec([
'npm publish'
], function() {
console.log('Published to npm');
complete();
});
}, ASYNC);
desc('Run JSLint check.');
task('jsl', function() {
jake.exec(['jsl -conf jsl.conf'], complete, {stdout: true});
}, ASYNC);
desc('Show npm package content.');
task('npm-check', function() {
header('Show content of npm package if published...');
child.exec('npm pack', function(err, pkgFile) {
child.exec('tar -tf ' + pkgFile, function(err, pkgContent) {
console.log(pkgContent);
child.exec('rm ' + pkgFile, complete);
});
});
}, ASYNC);