karma.config.js 9.5 KB

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