2016-04-13 09:15:04 +00:00
|
|
|
// karma.conf.js - the config file for karma, which runs our tests.
|
|
|
|
|
|
|
|
var path = require('path');
|
|
|
|
var webpack = require('webpack');
|
2020-01-14 00:38:34 +00:00
|
|
|
var wp_config = require('./webpack.config');
|
2016-04-13 09:15:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We use webpack to build our tests. It's a pain to have to wait for webpack
|
|
|
|
* to build everything; however it's the easiest way to load our dependencies
|
|
|
|
* from node_modules.
|
|
|
|
*
|
2019-03-12 11:06:57 +00:00
|
|
|
* If you run karma in multi-run mode (with `yarn test-multi`), it will watch
|
2016-04-13 09:15:04 +00:00
|
|
|
* the tests for changes, and webpack will rebuild using a cache. This is much quicker
|
|
|
|
* than a clean rebuild.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// the name of the test file. By default, a special file which runs all tests.
|
|
|
|
var testFile = process.env.KARMA_TEST_FILE || 'test/all-tests.js';
|
|
|
|
|
|
|
|
process.env.PHANTOMJS_BIN = 'node_modules/.bin/phantomjs';
|
|
|
|
process.env.Q_DEBUG = 1;
|
|
|
|
|
2020-01-14 00:38:34 +00:00
|
|
|
const webpack_config = wp_config({}, {mode: "development"});
|
|
|
|
|
2017-02-02 23:31:22 +00:00
|
|
|
/* the webpack config is based on the real one, to (a) try to simulate the
|
|
|
|
* deployed environment as closely as possible, and (b) to avoid a shedload of
|
|
|
|
* cut-and-paste.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// find out if we're shipping olm, and where it is, if so.
|
|
|
|
const olm_entry = webpack_config.entry['olm'];
|
|
|
|
|
|
|
|
// remove the default entries - karma provides its own (via the 'files' and
|
|
|
|
// 'preprocessors' config below)
|
|
|
|
delete webpack_config['entry'];
|
|
|
|
|
2018-09-26 00:39:05 +00:00
|
|
|
// make sure we're flagged as development to avoid wasting time optimising
|
|
|
|
webpack_config.mode = 'development';
|
|
|
|
|
2017-02-02 23:31:22 +00:00
|
|
|
// disable parsing for sinon, because it
|
|
|
|
// tries to do voodoo with 'require' which upsets
|
|
|
|
// webpack (https://github.com/webpack/webpack/issues/304)
|
|
|
|
webpack_config.module.noParse.push(/sinon\/pkg\/sinon\.js$/);
|
|
|
|
|
|
|
|
// ?
|
|
|
|
webpack_config.resolve.alias['sinon'] = 'sinon/pkg/sinon.js';
|
|
|
|
|
2018-04-27 09:32:59 +00:00
|
|
|
webpack_config.resolve.modules = [
|
2017-02-02 23:31:22 +00:00
|
|
|
path.resolve('./test'),
|
2018-04-27 09:32:59 +00:00
|
|
|
"node_modules"
|
2017-02-02 23:31:22 +00:00
|
|
|
];
|
|
|
|
|
2016-04-13 09:15:04 +00:00
|
|
|
module.exports = function (config) {
|
2017-02-02 23:31:22 +00:00
|
|
|
const myconfig = {
|
2016-04-13 09:15:04 +00:00
|
|
|
// frameworks to use
|
|
|
|
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
|
|
|
frameworks: ['mocha'],
|
|
|
|
|
|
|
|
// list of files / patterns to load in the browser
|
|
|
|
files: [
|
|
|
|
testFile,
|
2017-01-18 21:30:53 +00:00
|
|
|
|
|
|
|
// make the images available via our httpd. They will be avaliable
|
|
|
|
// below http://localhost:[PORT]/base/. See also `proxies` which
|
|
|
|
// defines alternative URLs for them.
|
|
|
|
//
|
|
|
|
// This isn't required by any of the tests, but it stops karma
|
|
|
|
// logging warnings when it serves a 404 for them.
|
|
|
|
{
|
2018-04-15 22:52:52 +00:00
|
|
|
pattern: 'node_modules/matrix-react-sdk/res/img/*',
|
2017-01-18 21:30:53 +00:00
|
|
|
watched: false, included: false, served: true, nocache: false,
|
|
|
|
},
|
2018-04-15 23:14:05 +00:00
|
|
|
{
|
2019-02-11 11:17:40 +00:00
|
|
|
pattern: 'res/**',
|
2018-04-15 23:14:05 +00:00
|
|
|
watched: false, included: false, served: true, nocache: false,
|
|
|
|
},
|
2016-04-13 09:15:04 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
proxies: {
|
2017-01-18 21:30:53 +00:00
|
|
|
// redirect img links to the karma server. See above.
|
2018-04-15 22:52:52 +00:00
|
|
|
"/img/": "/base/node_modules/matrix-react-sdk/res/img/",
|
2018-04-15 23:19:08 +00:00
|
|
|
"/themes/": "/base/res/themes/",
|
2019-02-11 11:17:40 +00:00
|
|
|
"/welcome.html": "/base/res/welcome.html",
|
|
|
|
"/welcome/": "/base/res/welcome/",
|
2016-04-13 09:15:04 +00:00
|
|
|
},
|
2016-06-16 06:39:34 +00:00
|
|
|
|
2016-04-13 09:15:04 +00:00
|
|
|
// preprocess matching files before serving them to the browser
|
|
|
|
// available preprocessors:
|
|
|
|
// https://npmjs.org/browse/keyword/karma-preprocessor
|
|
|
|
preprocessors: {
|
2017-08-08 18:04:25 +00:00
|
|
|
'{src,test}/**/*.js': ['webpack', 'sourcemap'],
|
2016-04-13 09:15:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// test results reporter to use
|
|
|
|
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
2019-05-03 10:40:53 +00:00
|
|
|
reporters: ['logcapture', 'spec', 'summary'],
|
2017-08-08 18:05:58 +00:00
|
|
|
|
|
|
|
specReporter: {
|
|
|
|
suppressErrorSummary: false, // do print error summary
|
|
|
|
suppressFailed: false, // do print information about failed tests
|
|
|
|
suppressPassed: false, // do print information about passed tests
|
|
|
|
showSpecTiming: true, // print the time elapsed for each spec
|
|
|
|
},
|
|
|
|
|
|
|
|
client: {
|
|
|
|
captureLogs: true,
|
|
|
|
},
|
2016-04-13 09:15:04 +00:00
|
|
|
|
|
|
|
// web server port
|
|
|
|
port: 9876,
|
|
|
|
|
|
|
|
// enable / disable colors in the output (reporters and logs)
|
|
|
|
colors: true,
|
|
|
|
|
|
|
|
// level of logging
|
|
|
|
// possible values: config.LOG_DISABLE || config.LOG_ERROR ||
|
|
|
|
// config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
|
|
|
logLevel: config.LOG_INFO,
|
|
|
|
|
|
|
|
// enable / disable watching file and executing tests whenever any file
|
|
|
|
// changes
|
|
|
|
autoWatch: true,
|
|
|
|
|
|
|
|
// start these browsers
|
|
|
|
// available browser launchers:
|
|
|
|
// https://npmjs.org/browse/keyword/karma-launcher
|
|
|
|
browsers: [
|
|
|
|
'Chrome',
|
|
|
|
//'PhantomJS',
|
2017-07-05 08:35:51 +00:00
|
|
|
//'ChromeHeadless'
|
2016-04-13 09:15:04 +00:00
|
|
|
],
|
|
|
|
|
2017-07-05 08:35:51 +00:00
|
|
|
customLaunchers: {
|
2019-03-14 01:46:52 +00:00
|
|
|
'VectorChromeHeadless': {
|
2017-07-05 08:35:51 +00:00
|
|
|
base: 'Chrome',
|
|
|
|
flags: [
|
2019-03-14 01:46:52 +00:00
|
|
|
'--no-sandbox',
|
2017-07-05 08:35:51 +00:00
|
|
|
// See https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
|
|
|
|
'--headless',
|
|
|
|
'--disable-gpu',
|
|
|
|
// Without a remote debugging port, Google Chrome exits immediately.
|
|
|
|
'--remote-debugging-port=9222',
|
|
|
|
],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-04-13 09:15:04 +00:00
|
|
|
// Continuous Integration mode
|
|
|
|
// if true, Karma captures browsers, runs the tests and exits
|
|
|
|
// singleRun: false,
|
|
|
|
|
|
|
|
// Concurrency level
|
|
|
|
// how many browser should be started simultaneous
|
|
|
|
concurrency: Infinity,
|
|
|
|
|
2017-02-02 23:31:22 +00:00
|
|
|
webpack: webpack_config,
|
|
|
|
|
|
|
|
webpackMiddleware: {
|
|
|
|
stats: {
|
|
|
|
// don't fill the console up with a mahoosive list of modules
|
|
|
|
chunks: false,
|
2016-04-13 09:15:04 +00:00
|
|
|
},
|
|
|
|
},
|
2017-02-02 23:31:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// include the olm loader if we have it.
|
|
|
|
if (olm_entry) {
|
|
|
|
myconfig.files.unshift(olm_entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
config.set(myconfig);
|
2016-04-13 09:15:04 +00:00
|
|
|
};
|