forked from rollbar/rollbar.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
220 lines (182 loc) · 6.11 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
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
/**
* Build and test rollbar.js
*
* Test with browserstack:
* $> BROWSER_STACK_USERNAME=username BROWSER_STACK_ACCESS_KEY=12345asdf grunt test --browsers=bs_ie_latest
*
*/
'use strict';
var glob = require('glob');
var path = require('path');
var pkg = require('./package.json');
var fs = require('fs');
var webpackConfig = require('./webpack.config.js');
var browserStackBrowsers = require('./browserstack.browsers');
function findTests() {
var files = glob.sync('test/**/*.test.js');
var mapping = {};
files.forEach(function(file) {
var testName = path.basename(file, '.test.js');
mapping[testName] = file;
});
return mapping;
}
function buildGruntKarmaConfig(singleRun, browsers, tests, reporters) {
var config = {
options: {
configFile: './karma.conf.js',
singleRun: singleRun,
files: [
// Files that the tests will load
{
pattern: 'dist/**/*.js',
included: false,
served: true,
watched: false
},
{
pattern: 'src/**/*.js',
included: false,
served: true,
watched: false
}
]
},
};
if (browsers && browsers.length) {
config.options.browsers = browsers;
}
if (reporters && reporters.length) {
config.options.reporters = reporters;
}
for (var testName in tests) {
var testFile = tests[testName];
var testConfig = config[testName] = {};
// Special case for testing requirejs integration.
// Include the requirejs module as a framework so
// Karma will inclue it in the web page.
if (testName === 'requirejs') {
testConfig.files = [
{src: './test/requirejs-loader.js'},
{src: './test/requirejs.test.js', included: false},
{src: './dist/rollbar.umd.js', included: false}
];
// NOTE: requirejs should go first in case the subsequent libraries
// check for the existence of `define()`
testConfig.frameworks = ['requirejs', 'expect', 'mocha'];
} else {
testConfig.files = [{src: [testFile]}];
}
// Special config for BrowserStack IE tests
if (testName.slice(0, 3) === 'bs' && testName.indexOf('ie_') >= 0) {
// Long timeout since IE 6/7/8 is slow
testConfig.captureTimeout = 60000 * 10;
}
}
return config;
}
module.exports = function(grunt) {
require('time-grunt')(grunt);
var tests = findTests();
var browsers = grunt.option('browsers');
if (browsers) {
browsers = browsers.split(',');
var browserStackAliases = [];
var nonBrowserStackAliases = [];
browsers.forEach(function(browserName) {
if (browserName.slice(0, 3) === 'bs_') {
browserStackAliases.push(browserName);
} else {
nonBrowserStackAliases.push(browserName);
}
});
var expandedBrowsers = browserStackBrowsers.filter.apply(null, browserStackAliases);
var expandedBrowserNames = [];
expandedBrowsers.forEach(function(browser) {
expandedBrowserNames.push(browser._alias);
});
browsers = nonBrowserStackAliases.concat(expandedBrowserNames);
}
var singleRun = grunt.option('singleRun');
if (singleRun === undefined) {
singleRun = true;
}
var reporters = grunt.option('reporters');
if (reporters !== undefined) {
reporters = reporters.split(',');
}
grunt.loadNpmTasks('grunt-express');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-webpack');
grunt.loadNpmTasks('grunt-text-replace');
var rollbarJsSnippet = fs.readFileSync('dist/rollbar.snippet.js');
var rollbarjQuerySnippet = fs.readFileSync('dist/plugins/jquery.min.js');
grunt.initConfig({
pkg: pkg,
webpack: webpackConfig,
karma: buildGruntKarmaConfig(singleRun, browsers, tests, reporters),
// Serves up responses to requests from the tests
express: {
defaults: {
options: {
server: './test/express',
port: 3000
}
}
},
replace: {
snippets: {
src: ['*.md', 'test/**/*.html', 'src/**/*.js', 'examples/*.+(html|js)', 'examples/*/*.+(html|js)', 'docs/**/*.md'],
overwrite: true,
replacements: [
// Main rollbar snippet
{
from: new RegExp('^(.*// Rollbar Snippet)[\n\r]+(.*[\n\r])*(.*// End Rollbar Snippet)', 'm'),
to: function(match, index, fullText, captures) {
captures[1] = rollbarJsSnippet;
return captures.join('\n');
}
},
// jQuery rollbar plugin snippet
{
from: new RegExp('^(.*// Rollbar jQuery Snippet)[\n\r]+(.*[\n\r])*(.*// End Rollbar jQuery Snippet)', 'm'),
to: function(match, index, fullText, captures) {
captures[1] = rollbarjQuerySnippet;
return captures.join('\n');
}
},
// README travis link
{
from: new RegExp('(https://api\.travis-ci\.org/rollbar/rollbar\.js\.png\\?branch=v)([0-9.-a-zA-Z]+)'),
to: function(match, index, fullText, captures) {
captures[1] = pkg.version;
return captures.join('');
}
}
]
}
}
// TODO: Upload assets to CDN
});
grunt.registerTask('build', ['webpack', 'replace:snippets']);
grunt.registerTask('default', ['build']);
grunt.registerTask('test', ['express', 'karma']);
grunt.registerTask('release', ['build', 'copyrelease']);
grunt.registerTask('test', function(target) {
var karmaTask = 'karma' + (target ? ':' + target : '');
var tasks = ['express', karmaTask];
grunt.task.run.apply(grunt.task, tasks);
});
grunt.registerTask('copyrelease', function createRelease() {
var version = pkg.version;
var builds = ['', '.nojson', '.umd', '.umd.nojson'];
builds.forEach(function (buildName) {
var js = 'dist/rollbar' + buildName + '.js';
var minJs = 'dist/rollbar' + buildName + '.min.js';
var releaseJs = 'release/rollbar' + buildName + '-' + version + '.js';
var releaseMinJs = 'release/rollbar' + buildName + '-' + version + '.min.js';
grunt.file.copy(js, releaseJs);
grunt.file.copy(minJs, releaseMinJs);
});
});
};