1
0

karma.config.js 7.1 KB

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