UNPKG

8.73 kBJavaScriptView Raw
1'use strict';
2
3module.exports = function (grunt) {
4
5 // Project configuration.
6 grunt.initConfig({
7 // Metadata.
8 pkg: grunt.file.readJSON('package.json'),
9 banner: '/*! <%= pkg.name %> - v<%= pkg.version %>' +
10 ' - <%= pkg.homepage %>' +
11 ' - (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>' +
12 ' - licensed <%= pkg.license %> */\n',
13 // Task configuration.
14 concat: {
15 options: {
16 banner: '<%= banner %>',
17 stripBanners: true
18 },
19 dist: {
20 src: ['lib/<%= pkg.name %>.js'],
21 dest: 'dist/<%= pkg.name %>.js'
22 }
23 },
24 uglify: {
25 options: {
26 banner: '<%= banner %>'
27 },
28 dist: {
29 src: '<%= concat.dist.dest %>',
30 dest: 'dist/<%= pkg.name %>.min.js'
31 }
32 },
33 jasmine: {
34 requirejs: {
35 src: [],
36 options: {
37 specs: 'test/*-test.js',
38 vendor: 'test/vendor/*.js',
39 helpers: 'test/*-helper.js',
40 template: require('grunt-template-jasmine-requirejs')
41 }
42 },
43 global: {
44 src: 'lib/**/*.js',
45 options: {
46 specs: 'test/global-integration.js',
47 vendor: 'test/vendor/*.js'
48 }
49 },
50 context: {
51 src: 'test/test-context-using-apply.generated.js',
52 options: {
53 specs: 'test/global-integration-with-new-context.js',
54 vendor: 'test/vendor/*.js'
55 }
56 },
57 withCoverage: {
58 src: 'lib/**/*.js',
59 options: {
60 specs: 'test/*-test.js',
61 vendor: 'test/vendor/*.js',
62 helpers: 'test/*-helper.js',
63 template: require('grunt-template-jasmine-istanbul'),
64 templateOptions: {
65 coverage: 'coverage/coverage.json',
66 report: [
67 {
68 type: 'html',
69 options: {
70 dir: 'coverage'
71 }
72 },
73 {
74 type: 'lcov',
75 options: {
76 dir: 'coverage'
77 }
78 }
79 ],
80
81 template: require('grunt-template-jasmine-requirejs'),
82 templateOptions: {
83 requireConfig: {
84 paths: {
85 "lib": '.grunt/grunt-contrib-jasmine/lib/'
86 }
87 }
88 }
89 }
90 }
91 }
92 },
93 "jasmine_node": {
94 options: {
95 match: "node-integration.",
96 matchall: true,
97 projectRoot: "./test",
98 useHelpers: false
99 }
100 },
101 coveralls: {
102 src: 'coverage/lcov.info'
103 },
104 open: {
105 jasmine: {
106 path: 'http://127.0.0.1:8000/_SpecRunner.html'
107 }
108 },
109 connect: {
110 test: {
111 port: 8000,
112 keepalive: true
113 }
114 },
115 'saucelabs-jasmine': {
116 // Requires valid SAUCE_USERNAME and SAUCE_ACCESS_KEY in env to run.
117 all: {
118 options: {
119 urls: ['http://localhost:8000/_SpecRunner.html'],
120 browsers: [
121 {"browserName": "firefox", "platform": "Windows 2003", "version": "3.6"},
122 {"browserName": "firefox", "platform": "Windows 2003", "version": "4"},
123 {"browserName": "firefox", "platform": "Windows 2003", "version": "25"},
124 {"browserName": "safari", "platform": "Mac 10.6", "version": "5"},
125 {"browserName": "safari", "platform": "Mac 10.8", "version": "6"},
126 {"browserName": "googlechrome", "platform": "Windows 7"},
127 {"browserName": "opera", "platform": "Windows 2003", "version": "12"},
128 // Disabled because old IE breaks the Jasmine runner; these have to be manually tested
129 // {"browserName": "iehta", "platform": "Windows XP", "version": "6"},
130 // {"browserName": "iehta", "platform": "Windows XP", "version": "7"},
131 // {"browserName": "iehta", "platform": "Windows XP", "version": "8"},
132 {"browserName": "iehta", "platform": "Windows 7", "version": "9"},
133 {"browserName": "iehta", "platform": "Windows 7", "version": "10"},
134 {"browserName": "opera", "platform": "Windows 7", "version": "12"},
135 {"browserName": "android", "platform": "Linux", "version": "4.0"},
136 {"browserName": "iphone", "platform": "OS X 10.8", "version": "6"}
137 ],
138 concurrency: 3,
139 detailedError: true,
140 testTimeout:10000,
141 testInterval:1000,
142 testReadyTimeout:2000,
143 testname: 'loglevel jasmine test',
144 tags: [process.env.TRAVIS_REPO_SLUG || "local", process.env.TRAVIS_COMMIT || "manual"]
145 }
146 }
147 },
148 jshint: {
149 options: {
150 jshintrc: '.jshintrc'
151 },
152 gruntfile: {
153 src: 'Gruntfile.js'
154 },
155 lib: {
156 options: {
157 jshintrc: 'lib/.jshintrc'
158 },
159 src: ['lib/**/*.js']
160 },
161 test: {
162 options: {
163 jshintrc: 'test/.jshintrc'
164 },
165 src: ['test/*.js', '!test/*.generated.js']
166 }
167 },
168 watch: {
169 gruntfile: {
170 files: '<%= jshint.gruntfile.src %>',
171 tasks: ['jshint:gruntfile']
172 },
173 lib: {
174 files: '<%= jshint.lib.src %>',
175 tasks: ['jshint:lib', 'test']
176 },
177 test: {
178 files: '<%= jshint.test.src %>',
179 tasks: ['jshint:test', 'test']
180 }
181 },
182 qunit: {
183 all: ['test/*-qunit.html']
184 },
185 preprocess: {
186 "test-context-using-apply": {
187 src: 'test/test-context-using-apply.js',
188 dest: 'test/test-context-using-apply.generated.js'
189 }
190 },
191 clean:{
192 test:['test/test-context-using-apply.generated.js']
193 }
194 });
195
196 // These plugins provide necessary tasks.
197 grunt.loadNpmTasks('grunt-contrib-concat');
198 grunt.loadNpmTasks('grunt-contrib-uglify');
199 grunt.loadNpmTasks('grunt-contrib-jasmine');
200 grunt.loadNpmTasks('grunt-coveralls');
201 grunt.loadNpmTasks('grunt-jasmine-node');
202 grunt.loadNpmTasks('grunt-contrib-jshint');
203 grunt.loadNpmTasks('grunt-contrib-watch');
204 grunt.loadNpmTasks('grunt-contrib-qunit');
205
206 grunt.loadNpmTasks('grunt-contrib-connect');
207 grunt.loadNpmTasks('grunt-open');
208 grunt.loadNpmTasks('grunt-saucelabs');
209 grunt.loadNpmTasks('grunt-preprocess');
210 grunt.loadNpmTasks('grunt-contrib-clean');
211
212 // Build a distributable release
213 grunt.registerTask('dist', ['test', 'concat', 'uglify']);
214
215 // Check everything is good
216 grunt.registerTask('test', ['jshint', 'jasmine:requirejs', 'jasmine:global', 'preprocess', 'jasmine:context', 'clean:test', 'jasmine_node', 'jasmine:withCoverage', 'qunit']);
217
218 // Test with a live server and an actual browser
219 grunt.registerTask('integration-test', ['jasmine:requirejs:src:build', 'open:jasmine', 'connect:test:keepalive']);
220
221 // Test with lots of browsers on saucelabs. Requires valid SAUCE_USERNAME and SAUCE_ACCESS_KEY in env to run.
222 grunt.registerTask('saucelabs', ['jasmine:requirejs:src:build', 'connect:test', 'saucelabs-jasmine']);
223
224 // Default task.
225 grunt.registerTask('default', 'test');
226 grunt.registerTask('ci', ['test', 'coveralls']);
227
228};