karma.config.js 7.7 KB

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