karma.config.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /**
  2. * ownCloud
  3. *
  4. * @author Vincent Petry
  5. * @copyright 2014 Vincent Petry <pvince81@owncloud.com>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  9. * License as published by the Free Software Foundation; either
  10. * version 3 of the License, or any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public
  18. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. /**
  22. * This node module is run by the karma executable to specify its configuration.
  23. *
  24. * The list of files from all needed JavaScript files including the ones from the
  25. * apps to test, and the test specs will be passed as configuration object.
  26. *
  27. * Note that it is possible to test a single app by setting the KARMA_TESTSUITE
  28. * environment variable to the apps name, for example "core" or "files_encryption".
  29. * Multiple apps can be specified by separating them with space.
  30. *
  31. * Setting the environment variable NOCOVERAGE to 1 will disable the coverage
  32. * preprocessor, which is needed to be able to debug tests properly in a browser.
  33. */
  34. /* jshint node: true */
  35. module.exports = function(config) {
  36. function findApps() {
  37. /*
  38. var fs = require('fs');
  39. var apps = fs.readdirSync('apps');
  40. return apps;
  41. */
  42. // other apps tests don't run yet... needs further research / clean up
  43. return [
  44. 'files',
  45. 'files_trashbin',
  46. {
  47. name: 'files_sharing',
  48. srcFiles: [
  49. // only test these files, others are not ready and mess
  50. // up with the global namespace/classes/state
  51. 'apps/files_sharing/js/app.js',
  52. 'apps/files_sharing/js/sharedfilelist.js',
  53. 'apps/files_sharing/js/share.js'
  54. ],
  55. testFiles: ['apps/files_sharing/tests/js/*.js']
  56. },
  57. {
  58. name: 'files_external',
  59. srcFiles: [
  60. // only test these files, others are not ready and mess
  61. // up with the global namespace/classes/state
  62. 'apps/files_external/js/app.js',
  63. 'apps/files_external/js/mountsfilelist.js'
  64. ],
  65. testFiles: ['apps/files_external/tests/js/*.js']
  66. }];
  67. }
  68. // respect NOCOVERAGE env variable
  69. // it is useful to disable coverage for debugging
  70. // because the coverage preprocessor will wrap the JS files somehow
  71. var enableCoverage = !parseInt(process.env.NOCOVERAGE, 10);
  72. console.log('Coverage preprocessor: ', enableCoverage?'enabled':'disabled');
  73. // default apps to test when none is specified (TODO: read from filesystem ?)
  74. var appsToTest = process.env.KARMA_TESTSUITE;
  75. if (appsToTest) {
  76. appsToTest = appsToTest.split(' ');
  77. }
  78. else {
  79. appsToTest = ['core'].concat(findApps());
  80. }
  81. console.log('Apps to test: ', appsToTest);
  82. // read core files from core.json,
  83. // these are required by all apps so always need to be loaded
  84. // note that the loading order is important that's why they
  85. // are specified in a separate file
  86. var corePath = 'core/js/';
  87. var coreModule = require('../' + corePath + 'core.json');
  88. var testCore = false;
  89. var files = [];
  90. var index;
  91. var preprocessors = {};
  92. // find out what apps to test from appsToTest
  93. index = appsToTest.indexOf('core');
  94. if (index > -1) {
  95. appsToTest.splice(index, 1);
  96. testCore = true;
  97. }
  98. // extra test libs
  99. files.push(corePath + 'tests/lib/sinon-1.7.3.js');
  100. // core mocks
  101. files.push(corePath + 'tests/specHelper.js');
  102. var srcFile, i;
  103. // add core library files
  104. for ( i = 0; i < coreModule.libraries.length; i++ ) {
  105. srcFile = corePath + coreModule.libraries[i];
  106. files.push(srcFile);
  107. }
  108. // add core modules files
  109. for ( i = 0; i < coreModule.modules.length; i++ ) {
  110. srcFile = corePath + coreModule.modules[i];
  111. files.push(srcFile);
  112. if (enableCoverage) {
  113. preprocessors[srcFile] = 'coverage';
  114. }
  115. }
  116. // TODO: settings pages
  117. // need to test the core app as well ?
  118. if (testCore) {
  119. // core tests
  120. files.push(corePath + 'tests/specs/*.js');
  121. }
  122. function addApp(app) {
  123. // if only a string was specified, expand to structure
  124. if (typeof(app) === 'string') {
  125. app = {
  126. srcFiles: 'apps/' + app + '/js/*.js',
  127. testFiles: 'apps/' + app + '/tests/js/*.js'
  128. };
  129. }
  130. // add source files/patterns
  131. files = files.concat(app.srcFiles || []);
  132. // add test files/patterns
  133. files = files.concat(app.testFiles || []);
  134. if (enableCoverage) {
  135. // add coverage entry for each file/pattern
  136. for (var i = 0; i < app.srcFiles.length; i++) {
  137. preprocessors[app.srcFiles[i]] = 'coverage';
  138. }
  139. }
  140. }
  141. // add source files for apps to test
  142. for ( i = 0; i < appsToTest.length; i++ ) {
  143. addApp(appsToTest[i]);
  144. }
  145. // serve images to avoid warnings
  146. files.push({pattern: 'core/img/**/*', watched: false, included: false, served: true});
  147. // include core CSS
  148. files.push({pattern: 'core/css/*.css', watched: true, included: true, served: true});
  149. config.set({
  150. // base path, that will be used to resolve files and exclude
  151. basePath: '..',
  152. // frameworks to use
  153. frameworks: ['jasmine'],
  154. // list of files / patterns to load in the browser
  155. files: files,
  156. // list of files to exclude
  157. exclude: [
  158. ],
  159. proxies: {
  160. // prevent warnings for images
  161. '/context.html//core/img/': 'http://localhost:9876/base/core/img/',
  162. '/context.html//core/css/': 'http://localhost:9876/base/core/css/',
  163. '/context.html//core/fonts/': 'http://localhost:9876/base/core/fonts/'
  164. },
  165. // test results reporter to use
  166. // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
  167. reporters: ['dots', 'junit', 'coverage'],
  168. junitReporter: {
  169. outputFile: 'tests/autotest-results-js.xml'
  170. },
  171. // web server port
  172. port: 9876,
  173. preprocessors: preprocessors,
  174. coverageReporter: {
  175. dir:'tests/karma-coverage',
  176. reporters: [
  177. { type: 'html' },
  178. { type: 'cobertura' }
  179. ]
  180. },
  181. // enable / disable colors in the output (reporters and logs)
  182. colors: true,
  183. // level of logging
  184. // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
  185. logLevel: config.LOG_INFO,
  186. // enable / disable watching file and executing tests whenever any file changes
  187. autoWatch: true,
  188. // Start these browsers, currently available:
  189. // - Chrome
  190. // - ChromeCanary
  191. // - Firefox
  192. // - Opera (has to be installed with `npm install karma-opera-launcher`)
  193. // - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
  194. // - PhantomJS
  195. // - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
  196. browsers: ['PhantomJS'],
  197. // If browser does not capture in given timeout [ms], kill it
  198. captureTimeout: 60000,
  199. // Continuous Integration mode
  200. // if true, it capture browsers, run tests and exit
  201. singleRun: false
  202. });
  203. };