2016-03-29 00:29:49 +02:00
|
|
|
// karma.conf.js - the config file for karma, which runs our tests.
|
|
|
|
|
2016-03-24 23:59:01 +01:00
|
|
|
var path = require('path');
|
2016-04-05 12:08:02 +02:00
|
|
|
var fs = require('fs');
|
2016-03-24 23:59:01 +01:00
|
|
|
|
2016-03-28 18:36:22 +02:00
|
|
|
/*
|
2016-03-29 00:29:49 +02: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.
|
2016-03-28 18:47:06 +02:00
|
|
|
*
|
2016-03-31 01:48:46 +02:00
|
|
|
* If you run karma in multi-run mode (with `npm run test-multi`), it will watch
|
|
|
|
* the tests for changes, and webpack will rebuild using a cache. This is much quicker
|
|
|
|
* than a clean rebuild.
|
2016-03-28 18:36:22 +02:00
|
|
|
*/
|
2016-03-29 00:29:49 +02:00
|
|
|
|
2016-04-07 18:49:39 +02:00
|
|
|
// the name of the test file. By default, a special file which runs all tests.
|
|
|
|
//
|
|
|
|
// TODO: this could be a pattern, and karma would run each file, with a
|
|
|
|
// separate webpack bundle for each file. But then we get a separate instance
|
|
|
|
// of the sdk, and each of the dependencies, for each test file, and everything
|
|
|
|
// gets very confused. Can we persuade webpack to put all of the dependencies
|
|
|
|
// in a 'common' bundle?
|
|
|
|
//
|
|
|
|
var testFile = process.env.KARMA_TEST_FILE || 'test/all-tests.js';
|
|
|
|
|
2018-10-09 17:32:39 +02:00
|
|
|
|
2016-03-29 00:29:49 +02:00
|
|
|
process.env.PHANTOMJS_BIN = 'node_modules/.bin/phantomjs';
|
|
|
|
|
2016-04-05 12:08:02 +02:00
|
|
|
function fileExists(name) {
|
|
|
|
try {
|
|
|
|
fs.statSync(gsCss);
|
|
|
|
return true;
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// try find the gemini-scrollbar css in an npm-version-agnostic way
|
|
|
|
var gsCss = 'node_modules/gemini-scrollbar/gemini-scrollbar.css';
|
|
|
|
if (!fileExists(gsCss)) {
|
|
|
|
gsCss = 'node_modules/react-gemini-scrollbar/'+gsCss;
|
|
|
|
}
|
|
|
|
|
2016-04-07 18:49:39 +02:00
|
|
|
|
2016-03-24 23:59:01 +01:00
|
|
|
module.exports = function (config) {
|
|
|
|
config.set({
|
2016-03-28 18:36:22 +02:00
|
|
|
// frameworks to use
|
|
|
|
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
2016-03-24 23:59:01 +01:00
|
|
|
frameworks: ['mocha'],
|
2016-03-28 18:36:22 +02:00
|
|
|
|
|
|
|
// list of files / patterns to load in the browser
|
2016-03-24 23:59:01 +01:00
|
|
|
files: [
|
2016-04-07 18:49:39 +02:00
|
|
|
testFile,
|
2016-04-05 12:08:02 +02:00
|
|
|
gsCss,
|
2016-04-21 14:40:43 +02:00
|
|
|
|
|
|
|
// some images to reduce noise from the tests
|
|
|
|
{pattern: 'test/img/*', watched: false, included: false,
|
|
|
|
served: true, nocache: false},
|
2017-05-26 12:58:45 +02:00
|
|
|
// translation files
|
|
|
|
{pattern: 'src/i18n/strings/*', watcheed: false, included: false, served: true},
|
|
|
|
{pattern: 'test/i18n/*', watched: false, included: false, served: true},
|
2016-03-28 23:59:34 +02:00
|
|
|
],
|
|
|
|
|
2016-04-21 14:40:43 +02:00
|
|
|
proxies: {
|
2017-05-26 12:58:45 +02:00
|
|
|
// redirect img links to the karma server
|
2016-04-21 14:40:43 +02:00
|
|
|
"/img/": "/base/test/img/",
|
2017-05-26 12:58:45 +02:00
|
|
|
// special languages.json file for the tests
|
|
|
|
"/i18n/languages.json": "/base/test/i18n/languages.json",
|
|
|
|
// and redirect i18n requests
|
|
|
|
"/i18n/": "/base/src/i18n/strings/",
|
2016-04-21 14:40:43 +02:00
|
|
|
},
|
|
|
|
|
2016-03-28 23:59:34 +02:00
|
|
|
// list of files to exclude
|
2016-03-31 01:48:46 +02:00
|
|
|
//
|
|
|
|
// This doesn't work. It turns out that it's webpack which does the
|
2016-04-07 18:49:39 +02:00
|
|
|
// watching of the /test directory (karma only watches `testFile`
|
|
|
|
// itself). Webpack watches the directory so that it can spot
|
2016-03-31 01:48:46 +02:00
|
|
|
// new tests, which is fair enough; unfortunately it triggers a rebuild
|
|
|
|
// every time a lockfile is created in that directory, and there
|
|
|
|
// doesn't seem to be any way to tell webpack to ignore particular
|
|
|
|
// files in a watched directory.
|
|
|
|
//
|
|
|
|
// exclude: [
|
|
|
|
// '**/.#*'
|
|
|
|
// ],
|
2016-03-28 18:36:22 +02:00
|
|
|
|
|
|
|
// preprocess matching files before serving them to the browser
|
|
|
|
// available preprocessors:
|
|
|
|
// https://npmjs.org/browse/keyword/karma-preprocessor
|
2016-03-24 23:59:01 +01:00
|
|
|
preprocessors: {
|
2016-04-07 18:49:39 +02:00
|
|
|
'test/**/*.js': ['webpack', 'sourcemap']
|
2016-03-24 23:59:01 +01:00
|
|
|
},
|
2016-03-28 18:36:22 +02:00
|
|
|
|
|
|
|
// test results reporter to use
|
|
|
|
// possible values: 'dots', 'progress'
|
|
|
|
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
2017-07-27 15:47:22 +02:00
|
|
|
reporters: ['logcapture', 'spec', 'junit', 'summary'],
|
|
|
|
|
|
|
|
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-03-28 18:36:22 +02: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
|
2017-07-27 15:47:22 +02:00
|
|
|
//
|
|
|
|
// This is strictly for logs that would be generated by the browser itself and we
|
|
|
|
// don't want to log about missing images, which are emitted on LOG_WARN.
|
|
|
|
logLevel: config.LOG_ERROR,
|
2016-03-28 18:36:22 +02:00
|
|
|
|
|
|
|
// 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 15:39:02 +02:00
|
|
|
//'ChromeHeadless',
|
2016-03-28 18:36:22 +02:00
|
|
|
],
|
|
|
|
|
2017-07-05 15:39:02 +02:00
|
|
|
customLaunchers: {
|
|
|
|
'ChromeHeadless': {
|
|
|
|
base: 'Chrome',
|
|
|
|
flags: [
|
|
|
|
// 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-03-28 18:36:22 +02:00
|
|
|
// Continuous Integration mode
|
|
|
|
// if true, Karma captures browsers, runs the tests and exits
|
2017-07-05 15:39:02 +02:00
|
|
|
// singleRun: false,
|
2016-03-28 18:36:22 +02:00
|
|
|
|
|
|
|
// Concurrency level
|
|
|
|
// how many browser should be started simultaneous
|
|
|
|
concurrency: Infinity,
|
|
|
|
|
2016-03-29 00:35:36 +02:00
|
|
|
junitReporter: {
|
|
|
|
outputDir: 'karma-reports',
|
|
|
|
},
|
|
|
|
|
2016-03-24 23:59:01 +01:00
|
|
|
webpack: {
|
|
|
|
module: {
|
2018-10-09 17:32:39 +02:00
|
|
|
rules: [
|
2016-03-28 23:59:34 +02:00
|
|
|
{
|
2018-10-09 17:32:39 +02:00
|
|
|
test: /\.js$/, loader: "babel-loader",
|
2016-03-28 23:59:34 +02:00
|
|
|
include: [path.resolve('./src'),
|
|
|
|
path.resolve('./test'),
|
2016-10-13 10:48:07 +02:00
|
|
|
]
|
2016-03-28 18:36:22 +02:00
|
|
|
},
|
2016-03-24 23:59:01 +01:00
|
|
|
],
|
|
|
|
noParse: [
|
2017-04-22 15:52:20 +02:00
|
|
|
// for cross platform compatibility use [\\\/] as the path separator
|
|
|
|
// this ensures that the regex trips on both Windows and *nix
|
|
|
|
|
2016-03-24 23:59:01 +01:00
|
|
|
// don't parse the languages within highlight.js. They
|
|
|
|
// cause stack overflows
|
|
|
|
// (https://github.com/webpack/webpack/issues/1721), and
|
|
|
|
// there is no need for webpack to parse them - they can
|
|
|
|
// just be included as-is.
|
2017-04-22 15:52:20 +02:00
|
|
|
/highlight\.js[\\\/]lib[\\\/]languages/,
|
|
|
|
|
|
|
|
// olm takes ages for webpack to process, and it's already heavily
|
|
|
|
// optimised, so there is little to gain by us uglifying it.
|
|
|
|
/olm[\\\/](javascript[\\\/])?olm\.js$/,
|
2016-03-31 01:48:46 +02:00
|
|
|
|
|
|
|
// also disable parsing for sinon, because it
|
|
|
|
// tries to do voodoo with 'require' which upsets
|
|
|
|
// webpack (https://github.com/webpack/webpack/issues/304)
|
2017-04-22 15:52:20 +02:00
|
|
|
/sinon[\\\/]pkg[\\\/]sinon\.js$/,
|
2016-03-24 23:59:01 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
2016-04-21 09:10:58 +02:00
|
|
|
// alias any requires to the react module to the one in our
|
|
|
|
// path, otherwise we tend to get the react source included
|
|
|
|
// twice when using npm link.
|
|
|
|
react: path.resolve('./node_modules/react'),
|
|
|
|
|
2016-04-07 18:49:39 +02:00
|
|
|
'matrix-react-sdk': path.resolve('test/skinned-sdk.js'),
|
2016-03-28 23:59:34 +02:00
|
|
|
'sinon': 'sinon/pkg/sinon.js',
|
2016-03-24 23:59:01 +01:00
|
|
|
},
|
2018-10-09 17:40:25 +02:00
|
|
|
modules: [
|
|
|
|
path.resolve('./test'),
|
|
|
|
"node_modules"
|
|
|
|
],
|
2016-03-24 23:59:01 +01:00
|
|
|
},
|
2016-03-28 19:19:37 +02:00
|
|
|
devtool: 'inline-source-map',
|
2017-06-01 19:58:07 +02:00
|
|
|
externals: {
|
|
|
|
// Don't try to bundle electron: leave it as a commonjs dependency
|
|
|
|
// (the 'commonjs' here means it will output a 'require')
|
|
|
|
"electron": "commonjs electron",
|
|
|
|
},
|
2018-10-09 17:40:25 +02:00
|
|
|
// make sure we're flagged as development to avoid wasting time optimising
|
|
|
|
mode: 'development',
|
2016-03-24 23:59:01 +01:00
|
|
|
},
|
2017-01-31 23:40:53 +01:00
|
|
|
|
|
|
|
webpackMiddleware: {
|
|
|
|
stats: {
|
|
|
|
// don't fill the console up with a mahoosive list of modules
|
|
|
|
chunks: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2016-07-05 15:34:33 +02:00
|
|
|
browserNoActivityTimeout: 15000,
|
2016-03-24 23:59:01 +01:00
|
|
|
});
|
|
|
|
};
|