Gruntfile.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. module.exports = function(grunt) {
  2. var DEV_SERVER_PORT = 8383;
  3. var TEST_SERVER_PORT = 8387;
  4. // Tell our Express server that Grunt launched it
  5. process.env.GRUNTED = true;
  6. // Project configuration.
  7. grunt.initConfig({
  8. pkg: grunt.file.readJSON('package.json'),
  9. font: {
  10. icons: {
  11. src: ['app/public/fonts/svg-icons/*.svg'],
  12. destCss: 'app/public/styles/less/icons.less',
  13. destFonts: 'app/public/fonts/icons.woff',
  14. // Optional: Custom routing of font filepaths for CSS
  15. cssRouter: function (fontpath) {
  16. var pathArray = fontpath.split('/');
  17. var fileName = pathArray[pathArray.length - 1];
  18. return '/public/fonts/' + fileName;
  19. }
  20. }
  21. },
  22. less: {
  23. all: {
  24. files: {
  25. 'app/public/styles/main.css': [ 'app/public/styles/less/main.less' ],
  26. 'app/public/styles/index.css': [ 'app/public/styles/less/index.less' ],
  27. 'app/public/styles/launchTest.css': [ 'app/public/styles/less/launchTest.less' ],
  28. 'app/public/styles/results.css': [ 'app/public/styles/less/results.less' ]
  29. }
  30. }
  31. },
  32. jshint: {
  33. all: [
  34. '*.js',
  35. 'app/lib/*.js',
  36. 'bin/*.js',
  37. 'lib/**/*.js',
  38. 'app/nodeControllers/*.js',
  39. 'app/public/scripts/*.js',
  40. 'phantomas_custom/**/*.js',
  41. 'test/**/*.js',
  42. 'front/src/js/**/*.js'
  43. ]
  44. },
  45. clean: {
  46. icons: {
  47. src: ['tmp']
  48. },
  49. coverage: {
  50. src: ['coverage/']
  51. }
  52. },
  53. copy: {
  54. coverage: {
  55. files: [
  56. {src: ['test/**'], dest: 'coverage/'},
  57. {src: ['lib/metadata/**'], dest: 'coverage/'},
  58. {src: ['bin/**'], dest: 'coverage/'}
  59. ]
  60. }
  61. },
  62. blanket: {
  63. coverageApp: {
  64. src: ['app/'],
  65. dest: 'coverage/app/'
  66. },
  67. coverageLib: {
  68. src: ['lib/'],
  69. dest: 'coverage/lib/'
  70. },
  71. coverageBin: {
  72. src: ['bin/'],
  73. dest: 'coverage/bin/'
  74. }
  75. },
  76. mochaTest: {
  77. test: {
  78. options: {
  79. reporter: 'spec',
  80. },
  81. src: ['coverage/test/core/*.js', 'coverage/test/api/*.js']
  82. },
  83. 'test-current-work': {
  84. options: {
  85. reporter: 'spec',
  86. },
  87. src: ['coverage/test/api/apiTest.js']
  88. },
  89. coverage: {
  90. options: {
  91. reporter: 'html-cov',
  92. quiet: true,
  93. captureFile: 'coverage/coverage.html'
  94. },
  95. src: ['coverage/test/core/*.js', 'coverage/test/api/*.js']
  96. }
  97. },
  98. express: {
  99. dev: {
  100. options: {
  101. port: 8383,
  102. server: './bin/server.js',
  103. serverreload: true,
  104. showStack: true
  105. }
  106. },
  107. testSuite: {
  108. options: {
  109. port: 8388,
  110. bases: 'test/www'
  111. }
  112. }
  113. }
  114. });
  115. // Custom task: copies the test settings.json file to the coverage folder, and checks if there's no missing fields
  116. grunt.registerTask('copy-test-server-settings', function() {
  117. var mainSettingsFile = './server_config/settings.json';
  118. var testSettingsFile = './test/fixtures/settings.json';
  119. var mainSettings = grunt.file.readJSON(mainSettingsFile);
  120. var testSettings = grunt.file.readJSON(testSettingsFile);
  121. // Recursively compare keys of two objects (not the values)
  122. function compareKeys(original, copy, context) {
  123. for (var key in original) {
  124. if (!copy[key] && copy[key] !== '' && copy[key] !== 0) {
  125. grunt.fail.warn('Settings file ' + testSettingsFile + ' doesn\'t contain key ' + context + '.' + key);
  126. }
  127. if (original[key] !== null && typeof original[key] === 'object') {
  128. compareKeys(original[key], copy[key], context + '.' + key);
  129. }
  130. }
  131. }
  132. compareKeys(mainSettings, testSettings, 'settings');
  133. var outputFile = './coverage/server_config/settings.json';
  134. grunt.file.write(outputFile, JSON.stringify(testSettings, null, 4));
  135. grunt.log.ok('File ' + outputFile + ' created');
  136. });
  137. require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
  138. grunt.registerTask('icons', [
  139. 'font:icons',
  140. 'less',
  141. 'clean:icons'
  142. ]);
  143. grunt.registerTask('build', [
  144. 'less'
  145. ]);
  146. grunt.registerTask('hint', [
  147. 'jshint'
  148. ]);
  149. grunt.registerTask('dev', [
  150. 'express:dev'
  151. ]);
  152. grunt.registerTask('test', [
  153. 'build',
  154. 'jshint',
  155. 'express:testSuite',
  156. 'clean:coverage',
  157. 'copy-test-server-settings',
  158. 'blanket',
  159. 'copy:coverage',
  160. 'mochaTest:test',
  161. 'mochaTest:coverage'
  162. ]);
  163. grunt.registerTask('test-current-work', [
  164. 'build',
  165. 'jshint',
  166. 'express:testSuite',
  167. 'clean:coverage',
  168. 'copy-test-server-settings',
  169. 'blanket',
  170. 'copy:coverage',
  171. 'mochaTest:test-current-work'
  172. ]);
  173. };