karma.config.js 8.4 KB

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