mirror of https://github.com/vector-im/riot-web
Stub out the matrix client
parent
7e1e2347b5
commit
5f3b82a767
|
@ -7,7 +7,6 @@ var path = require('path');
|
||||||
* the easiest way to load our dependencies from node_modules.
|
* the easiest way to load our dependencies from node_modules.
|
||||||
*
|
*
|
||||||
* TODO:
|
* TODO:
|
||||||
* - how do we stub out the js-sdk
|
|
||||||
* - can we run one test at a time
|
* - can we run one test at a time
|
||||||
* - can we can we run under phantomjs/jsdom?
|
* - can we can we run under phantomjs/jsdom?
|
||||||
* - write junit out
|
* - write junit out
|
||||||
|
@ -20,7 +19,14 @@ module.exports = function (config) {
|
||||||
|
|
||||||
// list of files / patterns to load in the browser
|
// list of files / patterns to load in the browser
|
||||||
files: [
|
files: [
|
||||||
'test/tests.js'
|
'test/tests.js',
|
||||||
|
],
|
||||||
|
|
||||||
|
// list of files to exclude
|
||||||
|
// (this doesn't work, and I don't know why - we still rerun the tests
|
||||||
|
// when lockfiles are created)
|
||||||
|
exclude: [
|
||||||
|
'**/.#*'
|
||||||
],
|
],
|
||||||
|
|
||||||
// preprocess matching files before serving them to the browser
|
// preprocess matching files before serving them to the browser
|
||||||
|
@ -70,13 +76,21 @@ module.exports = function (config) {
|
||||||
module: {
|
module: {
|
||||||
loaders: [
|
loaders: [
|
||||||
{ test: /\.json$/, loader: "json" },
|
{ test: /\.json$/, loader: "json" },
|
||||||
{ test: /\.js$/, loader: "babel",
|
{
|
||||||
include: [path.resolve('./src'),
|
// disable 'require' and 'define' for sinon, per
|
||||||
path.resolve('./test'),
|
// https://github.com/webpack/webpack/issues/304#issuecomment-170883329
|
||||||
],
|
test: /sinon\/pkg\/sinon\.js/,
|
||||||
query: {
|
// TODO: use 'query'?
|
||||||
presets: ['react', 'es2015']
|
loader: 'imports?define=>false,require=>false',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
test: /\.js$/, loader: "babel",
|
||||||
|
include: [path.resolve('./src'),
|
||||||
|
path.resolve('./test'),
|
||||||
|
],
|
||||||
|
query: {
|
||||||
|
presets: ['react', 'es2015']
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
noParse: [
|
noParse: [
|
||||||
|
@ -91,6 +105,7 @@ module.exports = function (config) {
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'matrix-react-sdk': path.resolve('src/index.js'),
|
'matrix-react-sdk': path.resolve('src/index.js'),
|
||||||
|
'sinon': 'sinon/pkg/sinon.js',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
devtool: 'inline-source-map',
|
devtool: 'inline-source-map',
|
||||||
|
|
|
@ -3,14 +3,21 @@ var TestUtils = require('react-addons-test-utils');
|
||||||
var expect = require('expect');
|
var expect = require('expect');
|
||||||
|
|
||||||
var sdk = require('matrix-react-sdk');
|
var sdk = require('matrix-react-sdk');
|
||||||
var MatrixChat;
|
|
||||||
|
var test_utils = require('../../test-utils');
|
||||||
|
var peg = require('../../../src/MatrixClientPeg.js');
|
||||||
|
var q = require('q');
|
||||||
|
|
||||||
describe('MatrixChat', function () {
|
describe('MatrixChat', function () {
|
||||||
|
var MatrixChat;
|
||||||
before(function() {
|
before(function() {
|
||||||
|
test_utils.stubClient();
|
||||||
MatrixChat = sdk.getComponent('structures.MatrixChat');
|
MatrixChat = sdk.getComponent('structures.MatrixChat');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('gives a login panel by default', function () {
|
it('gives a login panel by default', function () {
|
||||||
|
peg.get().loginFlows.returns(q({}));
|
||||||
|
|
||||||
var res = TestUtils.renderIntoDocument(
|
var res = TestUtils.renderIntoDocument(
|
||||||
<MatrixChat config={{}}/>
|
<MatrixChat config={{}}/>
|
||||||
);
|
);
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var peg = require('../src/MatrixClientPeg.js');
|
||||||
|
var jssdk = require('matrix-js-sdk');
|
||||||
|
var sinon = require('sinon');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stub out the MatrixClient, and configure the MatrixClientPeg object to
|
||||||
|
* return it when get() is called.
|
||||||
|
*/
|
||||||
|
module.exports.stubClient = function() {
|
||||||
|
var pegstub = sinon.stub(peg);
|
||||||
|
|
||||||
|
var matrixClientStub = sinon.createStubInstance(jssdk.MatrixClient);
|
||||||
|
pegstub.get.returns(matrixClientStub);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* make the test fail, with the given exception
|
||||||
|
*
|
||||||
|
* <p>This is useful for use with integration tests which use asyncronous
|
||||||
|
* methods: it can be added as a 'catch' handler in a promise chain.
|
||||||
|
*
|
||||||
|
* @param {Error} error exception to be reported
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* it("should not throw", function(done) {
|
||||||
|
* asynchronousMethod().then(function() {
|
||||||
|
* // some tests
|
||||||
|
* }).catch(utils.failTest).done(done);
|
||||||
|
* });
|
||||||
|
*/
|
||||||
|
module.exports.failTest = function(error) {
|
||||||
|
expect(error.stack).toBe(null);
|
||||||
|
};
|
Loading…
Reference in New Issue