forked from tejacques/crosstab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
116 lines (112 loc) · 3.94 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
module.exports = function (grunt) {
var fs = require('fs');
var envPath = './.env.js';
if (fs.existsSync(envPath)) {
console.log("Adding environment variables");
require(envPath);
}
var browsers = require('./test/browsers');
var reporter = require('saucelabs-mocha-reporter');
var gruntConfig = {
pkg: grunt.file.readJSON('package.json'),
jshint: {
files: ['Gruntfile.js', 'src/*.js', 'test/**.js'],
options: {
laxbreak: true
}
},
watch: {
scripts: {
files: ['<%= jshint.files %>'],
tasks: ['jshint']
}
},
connect: {
server: {
options: {
port: 9000,
hostname: '*',
base: '.'
}
}
},
mocha_phantomjs: {
test: {
options: {
urls: [
'http://localhost:9000/test/mocha_test.html'
]
}
}
},
'saucelabs-mocha': {
// Settings programatically added below
}
};
var addTag = function(envVar) {
var ev = process.env[envVar];
if (ev && ev.length > 0) {
if (ev === 'false' || ev === 'true') {
if (ev === 'true') {
tags.push(envVar);
}
} else {
tags.push(ev);
}
}
};
var onTestComplete;
for (var browser in browsers) {
var taskBrowsers = browsers[browser];
var tags = [];
['TRAVIS', 'TRAVIS_PULL_REQUEST', 'TRAVIS_BRANCH'].forEach(addTag);
gruntConfig['saucelabs-mocha'][browser] = {
options: {
urls: ["http://127.0.0.1:9000/test/mocha_test.html"],
tunnelTimeout: 5,
build: process.env.TRAVIS_JOB_ID,
tags: tags,
concurrency: 3,
browsers: taskBrowsers,
testname: browser + ' mocha tests',
'pollInterval': 1000,
'max-duration': 60
}
};
}
grunt.initConfig(gruntConfig);
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-mocha-phantomjs');
grunt.loadNpmTasks('grunt-saucelabs');
grunt.registerTask('default', ['connect', 'watch']);
grunt.registerTask('test', 'Run tests', function (type, testType, multiple) {
if(!type) {
grunt.task.run(['connect', 'mocha_phantomjs']);
} else if (browsers[type]) {
var useTests = JSON.parse(testType || null);
gruntConfig['saucelabs-mocha'][type].options.onTestComplete = reporter.create(useTests);
if (type === 'ci') {
gruntConfig['saucelabs-mocha'][type].options.statusCheckAttempts = 600;
gruntConfig['saucelabs-mocha'][type].options['max-duration'] = 600;
grunt.task.run(['connect', 'mocha_phantomjs', 'saucelabs-mocha:' + type]);
} else {
multiple = parseInt(multiple);
if (multiple > 0) {
var browserList = [];
var configOptions = gruntConfig['saucelabs-mocha'][type].options;
for(var i = 0; i < multiple; i++) {
browserList.push.apply(browserList, configOptions.browsers);
}
configOptions.browsers = browserList;
}
grunt.task.run(['connect', 'saucelabs-mocha:' + type]);
}
} else {
// Error!
console.log("Couldn't find: " + type + " in browser config. Running phantomjs instead");
grunt.task.run(['connect', 'mocha_phantomjs']);
}
});
};