karma.config.js 8.6 KB

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