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