Gruntfile.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. 'use strict';
  2. var Jasmine = require('jasmine');
  3. module.exports = function (grunt) {
  4. var jasmineRequireJsOptions = {
  5. specs: 'test/*-test.js',
  6. helpers: 'test/*-helper.js',
  7. };
  8. // Project configuration.
  9. grunt.initConfig({
  10. // Metadata.
  11. pkg: grunt.file.readJSON('package.json'),
  12. banner: '/*! <%= pkg.name %> - v<%= pkg.version %>' +
  13. ' - <%= pkg.homepage %>' +
  14. ' - (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>' +
  15. ' - licensed <%= pkg.license %> */\n',
  16. // Task configuration.
  17. concat: {
  18. options: {
  19. banner: '<%= banner %>',
  20. stripBanners: true
  21. },
  22. dist: {
  23. src: ['lib/<%= pkg.name %>.js'],
  24. dest: 'dist/<%= pkg.name %>.js'
  25. }
  26. },
  27. uglify: {
  28. options: {
  29. banner: '<%= banner %>'
  30. },
  31. dist: {
  32. src: '<%= concat.dist.dest %>',
  33. dest: 'dist/<%= pkg.name %>.min.js'
  34. }
  35. },
  36. jasmine: {
  37. requirejs: {
  38. src: [],
  39. options: {
  40. specs: jasmineRequireJsOptions.specs,
  41. helpers: jasmineRequireJsOptions.helpers,
  42. template: require('./vendor/grunt-template-jasmine-requirejs')
  43. }
  44. },
  45. global: {
  46. src: 'lib/**/*.js',
  47. options: {
  48. specs: 'test/global-integration.js',
  49. }
  50. },
  51. context: {
  52. src: 'test/test-context-using-apply.generated.js',
  53. options: {
  54. specs: 'test/global-integration-with-new-context.js',
  55. }
  56. }
  57. },
  58. jasmine_node: {
  59. options: {
  60. specs: ['test/node-integration.js']
  61. }
  62. },
  63. open: {
  64. jasmine: {
  65. path: 'http://127.0.0.1:8000/_SpecRunner.html'
  66. }
  67. },
  68. connect: {
  69. test: {
  70. port: 8000,
  71. keepalive: true
  72. }
  73. },
  74. jshint: {
  75. options: {
  76. jshintrc: '.jshintrc'
  77. },
  78. gruntfile: {
  79. src: 'Gruntfile.js'
  80. },
  81. lib: {
  82. options: {
  83. jshintrc: 'lib/.jshintrc'
  84. },
  85. src: ['lib/**/*.js']
  86. },
  87. test: {
  88. options: {
  89. jshintrc: 'test/.jshintrc'
  90. },
  91. src: ['test/*.js', '!test/*.generated.js']
  92. }
  93. },
  94. watch: {
  95. gruntfile: {
  96. files: '<%= jshint.gruntfile.src %>',
  97. tasks: ['jshint:gruntfile']
  98. },
  99. lib: {
  100. files: '<%= jshint.lib.src %>',
  101. tasks: ['jshint:lib', 'test']
  102. },
  103. test: {
  104. files: '<%= jshint.test.src %>',
  105. tasks: ['jshint:test', 'test']
  106. }
  107. },
  108. preprocess: {
  109. "test-context-using-apply": {
  110. src: 'test/test-context-using-apply.js',
  111. dest: 'test/test-context-using-apply.generated.js'
  112. }
  113. },
  114. clean:{
  115. test:['test/test-context-using-apply.generated.js']
  116. }
  117. });
  118. // These plugins provide necessary tasks.
  119. grunt.loadNpmTasks('grunt-contrib-concat');
  120. grunt.loadNpmTasks('grunt-contrib-uglify');
  121. grunt.loadNpmTasks('grunt-contrib-jasmine');
  122. grunt.loadNpmTasks('grunt-contrib-jshint');
  123. grunt.loadNpmTasks('grunt-contrib-watch');
  124. grunt.loadNpmTasks('grunt-contrib-connect');
  125. grunt.loadNpmTasks('grunt-open');
  126. grunt.loadNpmTasks('grunt-preprocess');
  127. grunt.loadNpmTasks('grunt-contrib-clean');
  128. // Run Jasmine with Node.js tests (as opposed to browser tests).
  129. //
  130. // NOTE: This is designed for Jasmine 2.4, which matches the version used
  131. // in `grunt-contrib-jasmine`. If that package is updated, this should also
  132. // be updated to match.
  133. grunt.registerTask('jasmine_node', 'Run Jasmine in Node.js', function() {
  134. var done = this.async();
  135. var jasmine = new Jasmine({ projectBaseDir: __dirname });
  136. jasmine.onComplete(function(success) {
  137. done(success);
  138. });
  139. jasmine.execute(this.options().specs);
  140. });
  141. // Build a distributable release
  142. grunt.registerTask('dist', ['test', 'dist-build']);
  143. grunt.registerTask('dist-build', ['concat', 'uglify']);
  144. // Check everything is good
  145. grunt.registerTask('test', ['jshint', 'test-browser', 'test-node']);
  146. grunt.registerTask('test-browser', ['jasmine:global', 'test-browser-context', 'jasmine:requirejs']);
  147. grunt.registerTask('test-browser-context', ['preprocess', 'jasmine:context', 'clean:test']);
  148. grunt.registerTask('test-node', ['jasmine_node']);
  149. // Test with a live server and an actual browser
  150. grunt.registerTask('integration-test', ['jasmine:requirejs:src:build', 'open:jasmine', 'connect:test:keepalive']);
  151. // Default task.
  152. grunt.registerTask('default', 'test');
  153. };