Gruntfile.js 8.6 KB

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