You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

karma.config.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 ['files'];
  44. }
  45. // respect NOCOVERAGE env variable
  46. // it is useful to disable coverage for debugging
  47. // because the coverage preprocessor will wrap the JS files somehow
  48. var enableCoverage = !parseInt(process.env.NOCOVERAGE, 10);
  49. console.log('Coverage preprocessor: ', enableCoverage?'enabled':'disabled');
  50. // default apps to test when none is specified (TODO: read from filesystem ?)
  51. var appsToTest = process.env.KARMA_TESTSUITE;
  52. if (appsToTest) {
  53. appsToTest = appsToTest.split(' ');
  54. }
  55. else {
  56. appsToTest = ['core'].concat(findApps());
  57. }
  58. console.log('Apps to test: ', appsToTest);
  59. // read core files from core.json,
  60. // these are required by all apps so always need to be loaded
  61. // note that the loading order is important that's why they
  62. // are specified in a separate file
  63. var corePath = 'core/js/';
  64. var coreModule = require('../' + corePath + 'core.json');
  65. var testCore = false;
  66. var files = [];
  67. var index;
  68. var preprocessors = {};
  69. // find out what apps to test from appsToTest
  70. index = appsToTest.indexOf('core');
  71. if (index > -1) {
  72. appsToTest.splice(index, 1);
  73. testCore = true;
  74. }
  75. // extra test libs
  76. files.push(corePath + 'tests/lib/sinon-1.7.3.js');
  77. // core mocks
  78. files.push(corePath + 'tests/specHelper.js');
  79. // add core library files
  80. for ( var i = 0; i < coreModule.libraries.length; i++ ) {
  81. var srcFile = corePath + coreModule.libraries[i];
  82. files.push(srcFile);
  83. }
  84. // add core modules files
  85. for ( var i = 0; i < coreModule.modules.length; i++ ) {
  86. var srcFile = corePath + coreModule.modules[i];
  87. files.push(srcFile);
  88. if (enableCoverage) {
  89. preprocessors[srcFile] = 'coverage';
  90. }
  91. }
  92. // TODO: settings pages
  93. // need to test the core app as well ?
  94. if (testCore) {
  95. // core tests
  96. files.push(corePath + 'tests/specs/*.js');
  97. }
  98. for ( var i = 0; i < appsToTest.length; i++ ) {
  99. // add app JS
  100. var srcFile = 'apps/' + appsToTest[i] + '/js/*.js';
  101. files.push(srcFile);
  102. if (enableCoverage) {
  103. preprocessors[srcFile] = 'coverage';
  104. }
  105. // add test specs
  106. files.push('apps/' + appsToTest[i] + '/tests/js/*.js');
  107. }
  108. // serve images to avoid warnings
  109. files.push({pattern: 'core/img/**/*', watched: false, included: false, served: true});
  110. config.set({
  111. // base path, that will be used to resolve files and exclude
  112. basePath: '..',
  113. // frameworks to use
  114. frameworks: ['jasmine'],
  115. // list of files / patterns to load in the browser
  116. files: files,
  117. // list of files to exclude
  118. exclude: [
  119. ],
  120. proxies: {
  121. // prevent warnings for images
  122. '/context.html//core/img/': 'http://localhost:9876/base/core/img/'
  123. },
  124. // test results reporter to use
  125. // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
  126. reporters: ['dots', 'junit', 'coverage'],
  127. junitReporter: {
  128. outputFile: 'tests/autotest-results-js.xml'
  129. },
  130. // web server port
  131. port: 9876,
  132. preprocessors: preprocessors,
  133. coverageReporter: {
  134. dir:'tests/karma-coverage',
  135. reporters: [
  136. { type: 'html' },
  137. { type: 'cobertura' }
  138. ]
  139. },
  140. // enable / disable colors in the output (reporters and logs)
  141. colors: true,
  142. // level of logging
  143. // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
  144. logLevel: config.LOG_INFO,
  145. // enable / disable watching file and executing tests whenever any file changes
  146. autoWatch: true,
  147. // Start these browsers, currently available:
  148. // - Chrome
  149. // - ChromeCanary
  150. // - Firefox
  151. // - Opera (has to be installed with `npm install karma-opera-launcher`)
  152. // - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
  153. // - PhantomJS
  154. // - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
  155. browsers: ['PhantomJS'],
  156. // If browser does not capture in given timeout [ms], kill it
  157. captureTimeout: 60000,
  158. // Continuous Integration mode
  159. // if true, it capture browsers, run tests and exit
  160. singleRun: false
  161. });
  162. };