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.

309 lines
9.1 KiB

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