1
0

karma.config.js 8.4 KB

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