11 changed files with 1501 additions and 859 deletions
@ -1,171 +0,0 @@
|
||||
// karma.conf.js - the config file for karma, which runs our tests.
|
||||
|
||||
var path = require('path'); |
||||
var webpack = require('webpack'); |
||||
var wp_config = require('./webpack.config'); |
||||
|
||||
/* |
||||
* 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. |
||||
* |
||||
* If you run karma in multi-run mode (with `yarn test-multi`), it will watch |
||||
* 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; |
||||
|
||||
const webpack_config = wp_config({}, {mode: "development"}); |
||||
|
||||
/* 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']; |
||||
|
||||
// make sure we're flagged as development to avoid wasting time optimising
|
||||
webpack_config.mode = 'development'; |
||||
|
||||
// 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'; |
||||
|
||||
webpack_config.resolve.modules = [ |
||||
path.resolve('./test'), |
||||
"node_modules" |
||||
]; |
||||
|
||||
module.exports = function (config) { |
||||
const myconfig = { |
||||
// 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, |
||||
|
||||
// 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.
|
||||
{ |
||||
pattern: 'node_modules/matrix-react-sdk/res/img/*', |
||||
watched: false, included: false, served: true, nocache: false, |
||||
}, |
||||
{ |
||||
pattern: 'res/**', |
||||
watched: false, included: false, served: true, nocache: false, |
||||
}, |
||||
], |
||||
|
||||
proxies: { |
||||
// redirect img links to the karma server. See above.
|
||||
"/img/": "/base/node_modules/matrix-react-sdk/res/img/", |
||||
"/themes/": "/base/res/themes/", |
||||
"/welcome.html": "/base/res/welcome.html", |
||||
"/welcome/": "/base/res/welcome/", |
||||
}, |
||||
|
||||
// preprocess matching files before serving them to the browser
|
||||
// available preprocessors:
|
||||
// https://npmjs.org/browse/keyword/karma-preprocessor
|
||||
preprocessors: { |
||||
'{src,test}/**/*.js': ['webpack', 'sourcemap'], |
||||
}, |
||||
|
||||
// test results reporter to use
|
||||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
||||
reporters: ['logcapture', 'spec', '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, |
||||
}, |
||||
|
||||
// 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',
|
||||
//'ChromeHeadless'
|
||||
], |
||||
|
||||
customLaunchers: { |
||||
'VectorChromeHeadless': { |
||||
base: 'Chrome', |
||||
flags: [ |
||||
'--no-sandbox', |
||||
// 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', |
||||
], |
||||
} |
||||
}, |
||||
|
||||
// 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, |
||||
|
||||
webpack: webpack_config, |
||||
|
||||
webpackMiddleware: { |
||||
stats: { |
||||
// don't fill the console up with a mahoosive list of modules
|
||||
chunks: false, |
||||
}, |
||||
}, |
||||
}; |
||||
|
||||
// include the olm loader if we have it.
|
||||
if (olm_entry) { |
||||
myconfig.files.unshift(olm_entry); |
||||
} |
||||
|
||||
config.set(myconfig); |
||||
}; |
@ -1,13 +0,0 @@
|
||||
// all-tests.js
|
||||
//
|
||||
// Our master test file: uses the webpack require API to find our test files
|
||||
// and run them
|
||||
|
||||
// ideally these unit tests could be run under nodejs rather than in a browser
|
||||
// via karma, but having two separate test frameworks in the same project
|
||||
// seems confusing
|
||||
const unit_tests = require.context('./unit-tests', true, /\.js$/); |
||||
unit_tests.keys().forEach(unit_tests); |
||||
|
||||
const app_tests = require.context('./app-tests', true, /\.jsx?$/); |
||||
app_tests.keys().forEach(app_tests); |
@ -0,0 +1,14 @@
|
||||
// https://jestjs.io/docs/en/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
|
||||
Object.defineProperty(window, 'matchMedia', { |
||||
writable: true, |
||||
value: jest.fn().mockImplementation(query => ({ |
||||
matches: false, |
||||
media: query, |
||||
onchange: null, |
||||
addListener: jest.fn(), // deprecated
|
||||
removeListener: jest.fn(), // deprecated
|
||||
addEventListener: jest.fn(), |
||||
removeEventListener: jest.fn(), |
||||
dispatchEvent: jest.fn(), |
||||
})), |
||||
}); |
Loading…
Reference in new issue