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

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