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 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. name: 'settings',
  69. srcFiles: [
  70. 'settings/js/users/deleteHandler.js'
  71. ],
  72. testFiles: ['settings/tests/js/users/deleteHandlerSpec.js']
  73. }
  74. ];
  75. }
  76. // respect NOCOVERAGE env variable
  77. // it is useful to disable coverage for debugging
  78. // because the coverage preprocessor will wrap the JS files somehow
  79. var enableCoverage = !parseInt(process.env.NOCOVERAGE, 10);
  80. console.log('Coverage preprocessor: ', enableCoverage?'enabled':'disabled');
  81. // default apps to test when none is specified (TODO: read from filesystem ?)
  82. var appsToTest = process.env.KARMA_TESTSUITE;
  83. if (appsToTest) {
  84. appsToTest = appsToTest.split(' ');
  85. }
  86. else {
  87. appsToTest = ['core'].concat(findApps());
  88. }
  89. console.log('Apps to test: ', appsToTest);
  90. // read core files from core.json,
  91. // these are required by all apps so always need to be loaded
  92. // note that the loading order is important that's why they
  93. // are specified in a separate file
  94. var corePath = 'core/js/';
  95. var vendorPath = 'core/vendor/';
  96. var coreModule = require('../' + corePath + 'core.json');
  97. var testCore = false;
  98. var files = [];
  99. var index;
  100. var preprocessors = {};
  101. // find out what apps to test from appsToTest
  102. index = appsToTest.indexOf('core');
  103. if (index > -1) {
  104. appsToTest.splice(index, 1);
  105. testCore = true;
  106. }
  107. // extra test libs
  108. files.push(corePath + 'tests/lib/sinon-1.7.3.js');
  109. // core mocks
  110. files.push(corePath + 'tests/specHelper.js');
  111. var srcFile, i;
  112. // add vendor library files
  113. for ( i = 0; i < coreModule.vendor.length; i++ ) {
  114. srcFile = vendorPath + coreModule.vendor[i];
  115. files.push(srcFile);
  116. }
  117. // add core library files
  118. for ( i = 0; i < coreModule.libraries.length; i++ ) {
  119. srcFile = corePath + coreModule.libraries[i];
  120. files.push(srcFile);
  121. }
  122. // add core modules files
  123. for ( i = 0; i < coreModule.modules.length; i++ ) {
  124. srcFile = corePath + coreModule.modules[i];
  125. files.push(srcFile);
  126. if (enableCoverage) {
  127. preprocessors[srcFile] = 'coverage';
  128. }
  129. }
  130. // TODO: settings pages
  131. // need to test the core app as well ?
  132. if (testCore) {
  133. // core tests
  134. files.push(corePath + 'tests/specs/*.js');
  135. }
  136. function addApp(app) {
  137. // if only a string was specified, expand to structure
  138. if (typeof(app) === 'string') {
  139. app = {
  140. srcFiles: 'apps/' + app + '/js/*.js',
  141. testFiles: 'apps/' + app + '/tests/js/*.js'
  142. };
  143. }
  144. // add source files/patterns
  145. files = files.concat(app.srcFiles || []);
  146. // add test files/patterns
  147. files = files.concat(app.testFiles || []);
  148. if (enableCoverage) {
  149. // add coverage entry for each file/pattern
  150. for (var i = 0; i < app.srcFiles.length; i++) {
  151. preprocessors[app.srcFiles[i]] = 'coverage';
  152. }
  153. }
  154. }
  155. // add source files for apps to test
  156. for ( i = 0; i < appsToTest.length; i++ ) {
  157. addApp(appsToTest[i]);
  158. }
  159. // serve images to avoid warnings
  160. files.push({pattern: 'core/img/**/*', watched: false, included: false, served: true});
  161. // include core CSS
  162. files.push({pattern: 'core/css/*.css', watched: true, included: true, served: true});
  163. config.set({
  164. // base path, that will be used to resolve files and exclude
  165. basePath: '..',
  166. // frameworks to use
  167. frameworks: ['jasmine'],
  168. // list of files / patterns to load in the browser
  169. files: files,
  170. // list of files to exclude
  171. exclude: [
  172. ],
  173. proxies: {
  174. // prevent warnings for images
  175. '/context.html//core/img/': 'http://localhost:9876/base/core/img/',
  176. '/context.html//core/css/': 'http://localhost:9876/base/core/css/',
  177. '/context.html//core/fonts/': 'http://localhost:9876/base/core/fonts/'
  178. },
  179. // test results reporter to use
  180. // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
  181. reporters: ['dots', 'junit', 'coverage'],
  182. junitReporter: {
  183. outputFile: 'tests/autotest-results-js.xml'
  184. },
  185. // web server port
  186. port: 9876,
  187. preprocessors: preprocessors,
  188. coverageReporter: {
  189. dir:'tests/karma-coverage',
  190. reporters: [
  191. { type: 'html' },
  192. { type: 'cobertura' }
  193. ]
  194. },
  195. // enable / disable colors in the output (reporters and logs)
  196. colors: true,
  197. // level of logging
  198. // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
  199. logLevel: config.LOG_INFO,
  200. // enable / disable watching file and executing tests whenever any file changes
  201. autoWatch: true,
  202. // Start these browsers, currently available:
  203. // - Chrome
  204. // - ChromeCanary
  205. // - Firefox
  206. // - Opera (has to be installed with `npm install karma-opera-launcher`)
  207. // - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
  208. // - PhantomJS
  209. // - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
  210. browsers: ['PhantomJS'],
  211. // If browser does not capture in given timeout [ms], kill it
  212. captureTimeout: 60000,
  213. // Continuous Integration mode
  214. // if true, it capture browsers, run tests and exit
  215. singleRun: false
  216. });
  217. };