Gruntfile.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. options: {
  92. match: "node-integration.",
  93. matchall: true,
  94. projectRoot: "./test",
  95. useHelpers: false
  96. }
  97. },
  98. coveralls: {
  99. src: 'coverage/lcov.info'
  100. },
  101. open: {
  102. jasmine: {
  103. path: 'http://127.0.0.1:8000/_SpecRunner.html'
  104. }
  105. },
  106. connect: {
  107. test: {
  108. port: 8000,
  109. keepalive: true
  110. }
  111. },
  112. 'saucelabs-jasmine': {
  113. // Requires valid SAUCE_USERNAME and SAUCE_ACCESS_KEY in env to run.
  114. all: {
  115. options: {
  116. urls: ['http://localhost:8000/_SpecRunner.html'],
  117. browsers: [
  118. {"browserName": "firefox", "platform": "Windows 2003", "version": "3.6"},
  119. {"browserName": "firefox", "platform": "Windows 2003", "version": "4"},
  120. {"browserName": "firefox", "platform": "Windows 2003", "version": "25"},
  121. {"browserName": "safari", "platform": "Mac 10.6", "version": "5"},
  122. {"browserName": "safari", "platform": "Mac 10.8", "version": "6"},
  123. {"browserName": "googlechrome", "platform": "Windows 7"},
  124. {"browserName": "opera", "platform": "Windows 2003", "version": "12"},
  125. // Disabled because old IE breaks the Jasmine runner; these have to be manually tested
  126. // {"browserName": "iehta", "platform": "Windows XP", "version": "6"},
  127. // {"browserName": "iehta", "platform": "Windows XP", "version": "7"},
  128. // {"browserName": "iehta", "platform": "Windows XP", "version": "8"},
  129. {"browserName": "iehta", "platform": "Windows 7", "version": "9"},
  130. {"browserName": "iehta", "platform": "Windows 7", "version": "10"},
  131. {"browserName": "opera", "platform": "Windows 7", "version": "12"},
  132. {"browserName": "android", "platform": "Linux", "version": "4.0"},
  133. {"browserName": "iphone", "platform": "OS X 10.8", "version": "6"}
  134. ],
  135. concurrency: 3,
  136. detailedError: true,
  137. testTimeout:10000,
  138. testInterval:1000,
  139. testReadyTimeout:2000,
  140. testname: 'loglevel jasmine test',
  141. tags: [process.env.TRAVIS_REPO_SLUG || "local", process.env.TRAVIS_COMMIT || "manual"]
  142. }
  143. }
  144. },
  145. jshint: {
  146. options: {
  147. jshintrc: '.jshintrc'
  148. },
  149. gruntfile: {
  150. src: 'Gruntfile.js'
  151. },
  152. lib: {
  153. options: {
  154. jshintrc: 'lib/.jshintrc'
  155. },
  156. src: ['lib/**/*.js']
  157. },
  158. test: {
  159. options: {
  160. jshintrc: 'test/.jshintrc'
  161. },
  162. src: ['test/*.js', '!test/*.generated.js']
  163. }
  164. },
  165. watch: {
  166. gruntfile: {
  167. files: '<%= jshint.gruntfile.src %>',
  168. tasks: ['jshint:gruntfile']
  169. },
  170. lib: {
  171. files: '<%= jshint.lib.src %>',
  172. tasks: ['jshint:lib', 'test']
  173. },
  174. test: {
  175. files: '<%= jshint.test.src %>',
  176. tasks: ['jshint:test', 'test']
  177. }
  178. },
  179. qunit: {
  180. all: ['test/*-qunit.html']
  181. },
  182. preprocess: {
  183. "test-context-using-apply": {
  184. src: 'test/test-context-using-apply.js',
  185. dest: 'test/test-context-using-apply.generated.js'
  186. }
  187. },
  188. clean:{
  189. test:['test/test-context-using-apply.generated.js']
  190. }
  191. });
  192. // These plugins provide necessary tasks.
  193. grunt.loadNpmTasks('grunt-contrib-concat');
  194. grunt.loadNpmTasks('grunt-contrib-uglify');
  195. grunt.loadNpmTasks('grunt-contrib-jasmine');
  196. grunt.loadNpmTasks('grunt-coveralls');
  197. grunt.loadNpmTasks('grunt-jasmine-node');
  198. grunt.loadNpmTasks('grunt-contrib-jshint');
  199. grunt.loadNpmTasks('grunt-contrib-watch');
  200. grunt.loadNpmTasks('grunt-contrib-qunit');
  201. grunt.loadNpmTasks('grunt-contrib-connect');
  202. grunt.loadNpmTasks('grunt-open');
  203. grunt.loadNpmTasks('grunt-saucelabs');
  204. grunt.loadNpmTasks('grunt-preprocess');
  205. grunt.loadNpmTasks('grunt-contrib-clean');
  206. // Build a distributable release
  207. grunt.registerTask('dist', ['test', 'concat', 'uglify']);
  208. // Check everything is good
  209. grunt.registerTask('test', ['jshint', 'jasmine:requirejs', 'jasmine:global', 'preprocess', 'jasmine:context', 'clean:test', 'jasmine_node', 'jasmine:withCoverage', 'qunit']);
  210. // Test with a live server and an actual browser
  211. grunt.registerTask('integration-test', ['jasmine:requirejs:src:build', 'open:jasmine', 'connect:test:keepalive']);
  212. // Test with lots of browsers on saucelabs. Requires valid SAUCE_USERNAME and SAUCE_ACCESS_KEY in env to run.
  213. grunt.registerTask('saucelabs', ['jasmine:requirejs:src:build', 'connect:test', 'saucelabs-jasmine']);
  214. // Default task.
  215. grunt.registerTask('default', 'test');
  216. grunt.registerTask('ci', ['test', 'coveralls']);
  217. };