From f60dd93660449413244d19311c522718a7015f6f Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Thu, 24 Mar 2016 22:59:01 +0000 Subject: [PATCH] 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 --- .babelrc | 3 ++ karma.conf.js | 39 +++++++++++++++++++ package.json | 15 ++++++- .../components/structures/MatrixChat-test.js | 11 ++++++ tests/tests.js | 11 ++++++ 5 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 .babelrc create mode 100644 karma.conf.js create mode 100644 tests/components/structures/MatrixChat-test.js create mode 100644 tests/tests.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000000..0578679419 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["react", "es2015"] +} diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000000..a859e34edb --- /dev/null +++ b/karma.conf.js @@ -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'), + }, + }, + }, + }); +}; diff --git a/package.json b/package.json index d2e9c32d74..60ff7f7b05 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,9 @@ "build": "babel src -d lib --source-maps", "start": "babel src -w -d lib --source-maps", "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": { "classnames": "^2.1.2", @@ -45,6 +47,15 @@ "json-loader": "^0.5.3", "require-json": "0.0.1", "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" } } diff --git a/tests/components/structures/MatrixChat-test.js b/tests/components/structures/MatrixChat-test.js new file mode 100644 index 0000000000..917dbcba18 --- /dev/null +++ b/tests/components/structures/MatrixChat-test.js @@ -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 () { + }); +}); diff --git a/tests/tests.js b/tests/tests.js new file mode 100644 index 0000000000..5a2a44909b --- /dev/null +++ b/tests/tests.js @@ -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);