-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGruntfile.js
154 lines (134 loc) · 4.03 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
'use strict';
global.rootRequire = function(name) {
return require(__dirname + '/' + name);
};
var _ = require('lodash');
var desireds = rootRequire('desireds');
var local_desireds = rootRequire('local_desireds');
var testGenerator = rootRequire('test_generator/create_test.js');
var moonstoneExtraCheck = rootRequire('moonstone-extra-checks');
var enyoBuild = rootRequire('enyo-version-on-build');
var globalConfig = {};
var gruntConfig = {
globalConfig: globalConfig,
env: {
// dynamically filled
},
simplemocha: {
all: {
options: {
timeout: 240000,
reporter: 'spec'
},
src: moonstoneExtraCheck.getAllUsedTests()
},
spec: {
options: {
timeout: 240000,
reporter: 'spec'
},
src: ['test/**/<%= globalConfig.file %>-specs.js']
}
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
gruntfile: {
src: 'Gruntfile.js'
},
test: {
options: {
jshintrc: 'test/.jshintrc'
},
src: ['./test/**/*.js']
}
},
concurrent: {
'test-sauce': [] // dynamically filled
},
watch: {
gruntfile: {
files: '<%= jshint.gruntfile.src %>',
tasks: ['jshint:gruntfile']
},
test: {
files: '<%= jshint.test.src %>',
tasks: ['jshint:test']
}
}
};
_.each(desireds, function(desired, key) {
gruntConfig.env[key] = {
DESIRED: JSON.stringify(desired),
SAUCE: 'true'
};
gruntConfig.concurrent['test-sauce'].push('test:sauce:' + key);
});
_.each(local_desireds, function(desired, key) {
gruntConfig.env['local_'+key] = {
DESIRED: JSON.stringify(desired),
SAUCE: 'false'
};
});
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig(gruntConfig);
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-env');
grunt.loadNpmTasks('grunt-simple-mocha');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
// Default task.
grunt.registerTask('default', ['test:sauce:' + _(desireds).keys().first()]);
_.each(desireds, function(desired, key) {
grunt.registerTask('test:sauce:' + key, ['env:' + key, 'simplemocha:all']);
grunt.registerTask('spec:sauce:' + key, function(filename) {
grunt.task.run('env:' + key);
globalConfig.file = filename;
grunt.task.run('simplemocha:spec');
});
});
grunt.registerTask('enyo:init', function() {
var enyoDev = require('enyo-dev');
var done = this.async();
var initializer = enyoDev.initialize({
initLibs: true,
linkAllLibs: false,
linkAvailLibs: false
});
initializer.on('end', done);
});
grunt.registerTask('test:sauce:parallel', ['concurrent:test-sauce']);
_.each(local_desireds, function(desired, key) {
grunt.registerTask('test:local:' + key, ['env:local_' + key, 'simplemocha:all']);
grunt.registerTask('spec:local:' + key, function(filename) {
grunt.task.run('env:local_' + key);
//Needed for when we want enyo libraries to match the versions on the BUILD_NUMBER
if(process.env.BUILD_NUMBER && process.env.BOARD_NUMBER && process.env.NAME && process.env.PASSWORD){
//forces grunt to wait for enyo versions to checkout
var done = this.async();
enyoBuild.changeEnyoVersions(process.env.BUILD_NUMBER, process.env.BOARD_NUMBER, process.env.NAME, process.env.PASSWORD, done);
}
//Needed for TAS to work properly with MOONSTONE_EXTRA flag
//Currently does not work with * (e.g. GT-12345*), but TAS uses full file names so it is currently a non-issue
if(process.env.MOONSTONE_EXTRA === 'false'){
var moonstoneExtraTests = moonstoneExtraCheck.getMoonstoneExtraTests();
var isTestMoonstoneExtra = _.includes(moonstoneExtraTests, filename);
if(!isTestMoonstoneExtra){
globalConfig.file = filename;
}
//if test is not a moonstone test do nothing and test will not run.
} else {
globalConfig.file = filename;
}
grunt.task.run('simplemocha:spec');
});
});
grunt.registerTask('generate:test', function(){
//forces grunt to wait for task to finish.
var done = this.async();
testGenerator.createTest(done);
});
};