1
0

karma.config.js 6.8 KB

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