From 824821f2c8cd9d062e50027f8807ad14fc9f7b60 Mon Sep 17 00:00:00 2001 From: lukasmartinelli Date: Wed, 23 Nov 2016 14:38:09 +0100 Subject: [PATCH] Add karma based testing --- .travis.yml | 3 +++ karma.conf.js | 29 +++++++++++++++++++++++++++++ package.json | 10 +++++++--- test/stylestore_test.js | 16 ++++++++++++++++ webpack.config.js | 1 + 5 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 karma.conf.js create mode 100644 test/stylestore_test.js diff --git a/.travis.yml b/.travis.yml index 3792107..cacbfff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,9 @@ node_js: - "6.1" before_script: - npm install -g eslint eslint-plugin-react + # prepare firefox + - export DISPLAY=:99.0 + - sh -e /etc/init.d/xvfb start install: - npm install script: diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..b06ac4c --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,29 @@ +var webpackConfig = require('./webpack.config.js'); + +// Karma configuration +module.exports = function(config) { + config.set({ + browsers: [ 'Chrome' ], //run in Chrome + frameworks: [ 'mocha' ], //use the mocha test framework + // ... normal karma configuration + files: [ + // all files ending in "_test" + {pattern: 'test/*_test.js', watched: false}, + {pattern: 'test/**/*_test.js', watched: false} + // each file acts as entry point for the webpack configuration + ], + + preprocessors: { + // add webpack as preprocessor + 'test/*_test.js': ['webpack'], + 'test/**/*_test.js': ['webpack'] + }, + + webpack: webpackConfig, + webpackMiddleware: { + // webpack-dev-middleware configuration + // i. e. + stats: 'errors-only' + } + }); +}; diff --git a/package.json b/package.json index 23341e6..b9632e9 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,10 @@ "scripts": { "stats": "webpack --config webpack.production.config.js --profile --json > stats.json", "build": "webpack --config webpack.production.config.js --progress --profile --colors", + "test": "karma start --single-run", + "test-watch": "karma start", "start": "webpack-dev-server --progress --profile --colors", - "lint": "eslint --ext js --ext jsx src" + "lint": "eslint --ext js --ext jsx {src,test}" }, "repository": { "type": "git", @@ -68,8 +70,6 @@ } }, "devDependencies": { - "sass-loader": "^4.0.1", - "node-sass": "^3.9.2", "babel-core": "6.14.0", "babel-eslint": "^6.1.2", "babel-loader": "6.2.4", @@ -87,7 +87,11 @@ "file-loader": "0.9.0", "html-webpack-plugin": "^2.22.0", "json-loader": "^0.5.4", + "karma": "^1.3.0", + "karma-webpack": "^1.8.0", + "node-sass": "^3.9.2", "react-hot-loader": "1.3.0", + "sass-loader": "^4.0.1", "style-loader": "0.13.1", "transform-loader": "^0.2.3", "url-loader": "0.5.7", diff --git a/test/stylestore_test.js b/test/stylestore_test.js new file mode 100644 index 0000000..691e4f5 --- /dev/null +++ b/test/stylestore_test.js @@ -0,0 +1,16 @@ +import { SettingsStore } from '../src/stylestore.js' +import assert from 'assert' + +describe('SettingsStore', () => { + const store = new SettingsStore() + + it('#get should return access token from local storage', () => { + window.localStorage.setItem('maputnik:access_token', 'OLD_TOKEN') + assert.equal(store.accessToken, 'OLD_TOKEN') + }) + + it('#set should set access token in local storage', () => { + store.accessToken = 'NEW_TOKEN' + assert.equal(window.localStorage.getItem('maputnik:access_token'), 'NEW_TOKEN') + }) +}) diff --git a/webpack.config.js b/webpack.config.js index b3dae73..1159966 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -34,6 +34,7 @@ loaders.push({ }); module.exports = { + target: 'web', entry: [ `webpack-dev-server/client?http://${HOST}:${PORT}`, `webpack/hot/only-dev-server`,