You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

194 lines
5.2 KiB

  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. const chrome = require('puppeteer').executablePath()
  21. process.env.CHROMIUM_BIN = chrome
  22. }
  23. /* jshint node: true */
  24. module.exports = function(config) {
  25. // respect NOCOVERAGE env variable
  26. // it is useful to disable coverage for debugging
  27. // because the coverage preprocessor will wrap the JS files somehow
  28. var enableCoverage = !parseInt(process.env.NOCOVERAGE, 10);
  29. console.log(
  30. 'Coverage preprocessor: ',
  31. enableCoverage ? 'enabled' : 'disabled'
  32. );
  33. // read core files from core.json,
  34. // these are required by all apps so always need to be loaded
  35. // note that the loading order is important that's why they
  36. // are specified in a separate file
  37. var corePath = 'dist/';
  38. var coreModule = require('../core/js/core.json');
  39. var files = [
  40. // core mocks
  41. 'core/js/tests/specHelper.js',
  42. ];
  43. var preprocessors = {};
  44. var srcFile, i;
  45. // add core library files
  46. for (i = 0; i < coreModule.libraries.length; i++) {
  47. srcFile = corePath + coreModule.libraries[i];
  48. files.push(srcFile);
  49. }
  50. files.push('core/js/tests/html-domparser.js');
  51. files.push('dist/core-main.js');
  52. files.push('dist/core-files_fileinfo.js');
  53. files.push('dist/core-files_client.js');
  54. files.push('dist/core-systemtags.js');
  55. // add core modules files
  56. for (i = 0; i < coreModule.modules.length; i++) {
  57. srcFile = corePath + coreModule.modules[i];
  58. files.push(srcFile);
  59. if (enableCoverage) {
  60. preprocessors[srcFile] = 'coverage';
  61. }
  62. }
  63. // core tests
  64. files.push('core/js/tests/specs/**/*.js');
  65. // serve images to avoid warnings
  66. files.push({
  67. pattern: 'core/img/**/*',
  68. watched: false,
  69. included: false,
  70. served: true
  71. });
  72. // include core CSS
  73. files.push({
  74. pattern: 'core/css/*.css',
  75. watched: true,
  76. included: true,
  77. served: true
  78. });
  79. // Allow fonts
  80. files.push({
  81. pattern: 'core/fonts/*',
  82. watched: false,
  83. included: false,
  84. served: true
  85. });
  86. console.log(files)
  87. config.set({
  88. // base path, that will be used to resolve files and exclude
  89. basePath: '..',
  90. // frameworks to use
  91. frameworks: ['jasmine', 'jasmine-sinon', 'viewport'],
  92. // list of files / patterns to load in the browser
  93. files,
  94. // list of files to exclude
  95. exclude: [],
  96. proxies: {
  97. // prevent warnings for images
  98. '/base/tests/img/': 'http://localhost:9876/base/core/img/',
  99. '/base/tests/css/': 'http://localhost:9876/base/core/css/',
  100. '/base/core/css/images/': 'http://localhost:9876/base/core/css/images/',
  101. '/actions/': 'http://localhost:9876/base/core/img/actions/',
  102. '/base/core/fonts/': 'http://localhost:9876/base/core/fonts/',
  103. '/svg/': '../core/img/'
  104. },
  105. // test results reporter to use
  106. // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
  107. reporters: ['spec'],
  108. specReporter: {
  109. maxLogLines: 5,
  110. suppressErrorSummary: false,
  111. suppressFailed: false,
  112. suppressPassed: true,
  113. suppressSkipped: true,
  114. showSpecTiming: false,
  115. },
  116. junitReporter: {
  117. outputFile: 'tests/autotest-results-js.xml'
  118. },
  119. // web server port
  120. port: 9876,
  121. preprocessors: preprocessors,
  122. coverageReporter: {
  123. dir: 'tests/karma-coverage',
  124. reporters: [
  125. { type: 'html' },
  126. { type: 'cobertura' },
  127. { type: 'lcovonly' }
  128. ]
  129. },
  130. // enable / disable colors in the output (reporters and logs)
  131. colors: true,
  132. // level of logging
  133. // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
  134. logLevel: config.LOG_INFO,
  135. // enable / disable watching file and executing tests whenever any file changes
  136. autoWatch: true,
  137. // Start these browsers, currently available:
  138. // - Chrome
  139. // - ChromeCanary
  140. // - Firefox
  141. // - Opera (has to be installed with `npm install karma-opera-launcher`)
  142. // - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
  143. // - PhantomJS
  144. // - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
  145. // use PhantomJS_debug for extra local debug
  146. browsers: ['Chrome_without_sandbox'],
  147. // you can define custom flags
  148. customLaunchers: {
  149. PhantomJS_debug: {
  150. base: 'PhantomJS',
  151. debug: true
  152. },
  153. // fix CI
  154. Chrome_without_sandbox: {
  155. base: 'ChromiumHeadless',
  156. flags: ['--no-sandbox'],
  157. },
  158. },
  159. // If browser does not capture in given timeout [ms], kill it
  160. captureTimeout: 60000,
  161. // Continuous Integration mode
  162. // if true, it capture browsers, run tests and exit
  163. singleRun: false
  164. });
  165. };