Initial implementation of some karma/mocha tests

It does something, but things I don't like:

* it churns for 15 seconds webpacking everything. Do we really need to get
  webpack involved here?

* I don't think there's any way to control which tests get run and which don't.

Other things I'd want to fix up include:

* Make it run on jsdom or phantomjs instead of Chrome
* figure out how to configure babel without a .babelrc
This commit is contained in:
Richard van der Hoff 2016-03-24 22:59:01 +00:00
parent e099aa9ce0
commit f60dd93660
5 changed files with 77 additions and 2 deletions

3
.babelrc Normal file
View file

@ -0,0 +1,3 @@
{
"presets": ["react", "es2015"]
}

39
karma.conf.js Normal file
View file

@ -0,0 +1,39 @@
// karma.conf.js
var webpack = require('webpack');
var path = require('path');
module.exports = function (config) {
config.set({
browsers: ['Chrome'],
singleRun: true,
frameworks: ['mocha'],
files: [
'tests/tests.js'
],
preprocessors: {
'tests/tests.js': ['webpack', 'sourcemap']
},
reporters: ['dots'],
webpack: {
module: {
loaders: [
{ test: /\.json$/, loader: "json" },
{ test: /\.js$/, loader: "babel", include: path.resolve('./src') },
],
noParse: [
// 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.
/highlight\.js\/lib\/languages/,
],
},
resolve: {
alias: {
'matrix-react-sdk': path.resolve('src/index.js'),
},
},
},
});
};

View file

@ -17,7 +17,9 @@
"build": "babel src -d lib --source-maps", "build": "babel src -d lib --source-maps",
"start": "babel src -w -d lib --source-maps", "start": "babel src -w -d lib --source-maps",
"clean": "rimraf lib", "clean": "rimraf lib",
"prepublish": "npm run build; git rev-parse HEAD > git-revision.txt" "prepublish": "npm run build; git rev-parse HEAD > git-revision.txt",
"test": "karma start",
"test-multi": "karma start --single-run=false"
}, },
"dependencies": { "dependencies": {
"classnames": "^2.1.2", "classnames": "^2.1.2",
@ -45,6 +47,15 @@
"json-loader": "^0.5.3", "json-loader": "^0.5.3",
"require-json": "0.0.1", "require-json": "0.0.1",
"rimraf": "^2.4.3", "rimraf": "^2.4.3",
"source-map-loader": "^0.1.5" "source-map-loader": "^0.1.5",
"karma": "^0.0.0",
"karma-cli": "^0.0.0",
"karma-mocha": "^0.0.0",
"karma-webpack": "^0.0.0",
"karma-sourcemap-loader": "^0.0.0",
"karma-chrome-launcher": "^0.0.0",
"mocha": "^0.0.0",
"expect": "^0.0.0"
} }
} }

View file

@ -0,0 +1,11 @@
var React = require('react');
var expect = require('expect');
var sdk = require("matrix-react-sdk");
var MatrixChat = sdk.getComponent('structures.MatrixChat');
describe('MatrixChat', function () {
it('does something', function () {
});
});

11
tests/tests.js Normal file
View file

@ -0,0 +1,11 @@
// tests.js
//
// Our master test file: uses the webpack require API to find our test files
// and run them
// this is a handly place to make sure the sdk has been skinned
var sdk = require("matrix-react-sdk");
sdk.loadSkin(require('../src/component-index'));
var context = require.context('.', true, /-test\.jsx?$/);
context.keys().forEach(context);