karma.config.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. 'files_versions',
  47. 'systemtags',
  48. {
  49. name: 'files_sharing',
  50. srcFiles: [
  51. // only test these files, others are not ready and mess
  52. // up with the global namespace/classes/state
  53. 'apps/files_sharing/js/dist/additionalScripts.js',
  54. 'apps/files_sharing/js/dist/files_sharing_tab.js',
  55. 'apps/files_sharing/js/dist/files_sharing.js',
  56. 'apps/files_sharing/js/dist/main.js',
  57. 'apps/files_sharing/js/dist/sidebar.js',
  58. 'apps/files_sharing/js/files_drop.js',
  59. 'apps/files_sharing/js/public.js',
  60. 'apps/files_sharing/js/sharedfilelist.js',
  61. 'apps/files_sharing/js/templates.js',
  62. ],
  63. testFiles: ['apps/files_sharing/tests/js/*.js']
  64. },
  65. {
  66. name: 'files_external',
  67. srcFiles: [
  68. // only test these files, others are not ready and mess
  69. // up with the global namespace/classes/state
  70. 'apps/files_external/js/app.js',
  71. 'apps/files_external/js/templates.js',
  72. 'apps/files_external/js/mountsfilelist.js',
  73. 'apps/files_external/js/settings.js',
  74. 'apps/files_external/js/statusmanager.js'
  75. ],
  76. testFiles: ['apps/files_external/tests/js/*.js']
  77. },
  78. {
  79. name: 'comments',
  80. srcFiles: [
  81. 'apps/comments/js/comments.js'
  82. ],
  83. testFiles: ['apps/comments/tests/js/**/*.js']
  84. }
  85. ];
  86. }
  87. // respect NOCOVERAGE env variable
  88. // it is useful to disable coverage for debugging
  89. // because the coverage preprocessor will wrap the JS files somehow
  90. var enableCoverage = !parseInt(process.env.NOCOVERAGE, 10);
  91. console.log(
  92. 'Coverage preprocessor: ',
  93. enableCoverage ? 'enabled' : 'disabled'
  94. );
  95. // default apps to test when none is specified (TODO: read from filesystem ?)
  96. var appsToTest = process.env.KARMA_TESTSUITE;
  97. if (appsToTest) {
  98. appsToTest = appsToTest.split(' ');
  99. } else {
  100. appsToTest = ['core'].concat(findApps());
  101. }
  102. console.log('Apps to test: ', appsToTest);
  103. // read core files from core.json,
  104. // these are required by all apps so always need to be loaded
  105. // note that the loading order is important that's why they
  106. // are specified in a separate file
  107. var corePath = 'core/js/';
  108. var coreModule = require('../' + corePath + 'core.json');
  109. var testCore = false;
  110. var files = [];
  111. var index;
  112. var preprocessors = {};
  113. // find out what apps to test from appsToTest
  114. index = appsToTest.indexOf('core');
  115. if (index > -1) {
  116. appsToTest.splice(index, 1);
  117. testCore = true;
  118. }
  119. files.push(corePath + 'tests/html-domparser.js');
  120. files.push('core/js/dist/main.js');
  121. files.push('core/js/dist/files_fileinfo.js');
  122. files.push('core/js/dist/files_client.js');
  123. files.push('core/js/dist/systemtags.js');
  124. // core mocks
  125. files.push(corePath + 'tests/specHelper.js');
  126. var srcFile, i;
  127. // add core library files
  128. for (i = 0; i < coreModule.libraries.length; i++) {
  129. srcFile = corePath + coreModule.libraries[i];
  130. files.push(srcFile);
  131. }
  132. // add core modules files
  133. for (i = 0; i < coreModule.modules.length; i++) {
  134. srcFile = corePath + coreModule.modules[i];
  135. files.push(srcFile);
  136. if (enableCoverage) {
  137. preprocessors[srcFile] = 'coverage';
  138. }
  139. }
  140. // TODO: settings pages
  141. // need to test the core app as well ?
  142. if (testCore) {
  143. // core tests
  144. files.push(corePath + 'tests/specs/**/*.js');
  145. }
  146. function addApp(app) {
  147. // if only a string was specified, expand to structure
  148. if (typeof app === 'string') {
  149. app = {
  150. srcFiles: 'apps/' + app + '/js/**/*.js',
  151. testFiles: 'apps/' + app + '/tests/js/**/*.js'
  152. };
  153. }
  154. // add source files/patterns
  155. files = files.concat(app.srcFiles || []);
  156. // add test files/patterns
  157. files = files.concat(app.testFiles || []);
  158. if (enableCoverage) {
  159. // add coverage entry for each file/pattern
  160. for (var i = 0; i < app.srcFiles.length; i++) {
  161. preprocessors[app.srcFiles[i]] = 'coverage';
  162. }
  163. }
  164. }
  165. // add source files for apps to test
  166. for (i = 0; i < appsToTest.length; i++) {
  167. addApp(appsToTest[i]);
  168. }
  169. // serve images to avoid warnings
  170. files.push({
  171. pattern: 'core/img/**/*',
  172. watched: false,
  173. included: false,
  174. served: true
  175. });
  176. files.push({
  177. pattern: 'core/css/images/*',
  178. watched: false,
  179. included: false,
  180. served: true
  181. });
  182. // include core CSS
  183. files.push({
  184. pattern: 'core/css/*.css',
  185. watched: true,
  186. included: true,
  187. served: true
  188. });
  189. files.push({
  190. pattern: 'tests/css/*.css',
  191. watched: true,
  192. included: true,
  193. served: true
  194. });
  195. // Allow fonts
  196. files.push({
  197. pattern: 'core/fonts/*',
  198. watched: false,
  199. included: false,
  200. served: true
  201. });
  202. config.set({
  203. // base path, that will be used to resolve files and exclude
  204. basePath: '..',
  205. // frameworks to use
  206. frameworks: ['jasmine', 'jasmine-sinon', 'viewport'],
  207. // list of files / patterns to load in the browser
  208. files: files,
  209. // list of files to exclude
  210. exclude: [],
  211. proxies: {
  212. // prevent warnings for images
  213. '/base/tests/img/': 'http://localhost:9876/base/core/img/',
  214. '/base/tests/css/': 'http://localhost:9876/base/core/css/',
  215. '/base/core/css/images/': 'http://localhost:9876/base/core/css/images/',
  216. '/actions/': 'http://localhost:9876/base/core/img/actions/',
  217. '/base/core/fonts/': 'http://localhost:9876/base/core/fonts/'
  218. },
  219. // test results reporter to use
  220. // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
  221. reporters: ['dots', 'junit', 'coverage'],
  222. junitReporter: {
  223. outputFile: 'tests/autotest-results-js.xml'
  224. },
  225. // web server port
  226. port: 9876,
  227. preprocessors: preprocessors,
  228. coverageReporter: {
  229. dir: 'tests/karma-coverage',
  230. reporters: [
  231. { type: 'html' },
  232. { type: 'cobertura' },
  233. { type: 'lcovonly' }
  234. ]
  235. },
  236. // enable / disable colors in the output (reporters and logs)
  237. colors: true,
  238. // level of logging
  239. // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
  240. logLevel: config.LOG_INFO,
  241. // enable / disable watching file and executing tests whenever any file changes
  242. autoWatch: true,
  243. // Start these browsers, currently available:
  244. // - Chrome
  245. // - ChromeCanary
  246. // - Firefox
  247. // - Opera (has to be installed with `npm install karma-opera-launcher`)
  248. // - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
  249. // - PhantomJS
  250. // - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
  251. // use PhantomJS_debug for extra local debug
  252. browsers: ['PhantomJS'],
  253. plugins: [
  254. 'karma-phantomjs-launcher',
  255. 'karma-coverage',
  256. 'karma-jasmine',
  257. 'karma-jasmine-sinon',
  258. 'karma-viewport',
  259. 'karma-junit-reporter'
  260. ],
  261. // you can define custom flags
  262. customLaunchers: {
  263. PhantomJS_debug: {
  264. base: 'PhantomJS',
  265. debug: true
  266. }
  267. },
  268. // If browser does not capture in given timeout [ms], kill it
  269. captureTimeout: 60000,
  270. // Continuous Integration mode
  271. // if true, it capture browsers, run tests and exit
  272. singleRun: false
  273. });
  274. };