From cacc2e1bc347897f602fecfd58d13368157f5aff Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Mon, 26 Oct 2015 14:22:41 +0000 Subject: [PATCH 1/4] Move testing to Jest --- client/.gitignore | 1 + .../components/__tests__/node-details-test.js | 6 ++- .../stores/__tests__/app-store-test.js | 11 ++++-- client/package.json | 39 ++++++++++++------- 4 files changed, 38 insertions(+), 19 deletions(-) diff --git a/client/.gitignore b/client/.gitignore index a8187ae69..74baa49d8 100644 --- a/client/.gitignore +++ b/client/.gitignore @@ -1,3 +1,4 @@ node_modules build/app.js build/*[woff2?|ttf|eot|svg] +coverage/ diff --git a/client/app/scripts/components/__tests__/node-details-test.js b/client/app/scripts/components/__tests__/node-details-test.js index 7fc1d2dc1..655751aa4 100644 --- a/client/app/scripts/components/__tests__/node-details-test.js +++ b/client/app/scripts/components/__tests__/node-details-test.js @@ -1,3 +1,7 @@ +jest.dontMock('../node-details.js'); +jest.dontMock('../../mixins/node-color-mixin'); +jest.dontMock('../../utils/title-utils'); + describe('NodeDetails', () => { let NodeDetails; let nodes; @@ -28,4 +32,4 @@ describe('NodeDetails', () => { expect(title.getDOMNode().textContent).toBe('Node 1'); }); -}); \ No newline at end of file +}); diff --git a/client/app/scripts/stores/__tests__/app-store-test.js b/client/app/scripts/stores/__tests__/app-store-test.js index 3dd4f17e3..197c58610 100644 --- a/client/app/scripts/stores/__tests__/app-store-test.js +++ b/client/app/scripts/stores/__tests__/app-store-test.js @@ -1,7 +1,11 @@ +jest.dontMock('../../constants/action-types'); +jest.dontMock('../app-store'); + // Appstore test suite using Jasmine matchers describe('AppStore', function() { const ActionTypes = require('../../constants/action-types'); + let AppDispatcher; let AppStore; let registeredCallback; @@ -121,10 +125,9 @@ describe('AppStore', function() { }; beforeEach(function() { - // clear AppStore singleton - delete require.cache[require.resolve('../app-store')]; + AppDispatcher = require('../../dispatcher/app-dispatcher'); AppStore = require('../app-store'); - registeredCallback = AppStore.registeredCallback; + registeredCallback = AppDispatcher.register.mock.calls[0][0]; }); // topology tests @@ -309,4 +312,4 @@ describe('AppStore', function() { expect(AppStore.getAdjacentNodes().size).toEqual(0); }); -}); \ No newline at end of file +}); diff --git a/client/package.json b/client/package.json index 841e743ab..d80dc3afe 100644 --- a/client/package.json +++ b/client/package.json @@ -19,10 +19,9 @@ "materialize-css": "^0.96.1", "object-assign": "^2.0.0", "page": "^1.6.3", - "react": "^0.13.3", + "react": "0.13.3", "react-motion": "^0.2.7", "react-tap-event-plugin": "^0.1.7", - "react-tween-state": "0.0.5", "reqwest": "~1.1.5", "timely": "^0.1.0" }, @@ -30,6 +29,7 @@ "autoprefixer-core": "^5.2.0", "babel-core": "^5.4.7", "babel-eslint": "^3.1.9", + "babel-jest": "^5.3.0", "babel-loader": "^5.1.3", "css-loader": "^0.14.4", "eslint": "^0.21.2", @@ -39,22 +39,13 @@ "express": "^4.13.3", "express-http-proxy": "^0.6.0", "file-loader": "^0.8.4", - "istanbul-instrumenter-loader": "^0.1.3", - "jasmine-core": "^2.3.4", + "jest-cli": "0.4.19", "json-loader": "^0.5.2", - "karma": "^0.13.3", - "karma-cli": "0.0.4", - "karma-coverage": "^0.4.2", - "karma-jasmine": "^0.3.5", - "karma-phantomjs-launcher": "^0.1.4", - "karma-webpack": "^1.7.0", "less": "^2.5.1", "less-loader": "^2.2.0", - "phantomjs": "^1.9.18", "postcss-loader": "^0.4.3", "proxy-middleware": "^0.13.1", "react-hot-loader": "^1.2.8", - "react-tools": "^0.13.3", "style-loader": "^0.12.3", "url": "^0.10.3", "url-loader": "^0.5.6", @@ -62,15 +53,35 @@ "webpack-dev-server": "^1.10.1" }, "scripts": { - "postinstall": "npm run build", "build": "webpack -p --config webpack.production.config.js", "start": "node server.js", "start-production": "NODE_ENV=production node server.js", - "test": "karma start test/karma.conf.js --single-run", + "test": "jest --coverage", "coveralls": "cat coverage/lcov.info | coveralls", "lint": "eslint app", "clean": "rm build/app.js" }, + "jest": { + "scriptPreprocessor": "/node_modules/babel-jest", + "testFileExtensions": [ + "es6", + "js" + ], + "moduleFileExtensions": [ + "js", + "json", + "es6" + ], + "unmockedModulePathPatterns": [ + "react", + "immutable", + "d3", + "keymirror", + "object-assign", + "lodash", + "debug" + ] + }, "engines": { "node": ">=0.10.0" } From a2877102f1abe9e21ab20c2a2d32e359902a1e6d Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Mon, 26 Oct 2015 14:41:03 +0000 Subject: [PATCH 2/4] remove old karma test config, make webpackdevserver optional `npm install` continues to install everything, but `npm install --no-optional` wont install the dev server. --- client/Dockerfile | 3 ++- client/package.json | 10 +++++--- client/test/README.md | 9 ------- client/test/karma.conf.js | 49 ------------------------------------ client/test/polyfill.js | 21 ---------------- client/test/preprocessor.js | 7 ------ client/test/tests.webpack.js | 2 -- 7 files changed, 8 insertions(+), 93 deletions(-) delete mode 100644 client/test/README.md delete mode 100644 client/test/karma.conf.js delete mode 100644 client/test/polyfill.js delete mode 100644 client/test/preprocessor.js delete mode 100644 client/test/tests.webpack.js diff --git a/client/Dockerfile b/client/Dockerfile index b757b42cf..14445b647 100644 --- a/client/Dockerfile +++ b/client/Dockerfile @@ -1,5 +1,6 @@ FROM node:0.10 WORKDIR /home/weave COPY package.json /home/weave/ -RUN npm install +# Dont install optional developer tools +RUN npm install --no-optional COPY webpack.local.config.js webpack.production.config.js server.js .eslintrc /home/weave/ diff --git a/client/package.json b/client/package.json index d80dc3afe..7f22dbc04 100644 --- a/client/package.json +++ b/client/package.json @@ -36,20 +36,22 @@ "eslint-loader": "^0.11.2", "eslint-plugin-jasmine": "^1.0.0", "eslint-plugin-react": "^2.3.0", - "express": "^4.13.3", - "express-http-proxy": "^0.6.0", "file-loader": "^0.8.4", "jest-cli": "0.4.19", "json-loader": "^0.5.2", "less": "^2.5.1", "less-loader": "^2.2.0", "postcss-loader": "^0.4.3", - "proxy-middleware": "^0.13.1", - "react-hot-loader": "^1.2.8", "style-loader": "^0.12.3", "url": "^0.10.3", "url-loader": "^0.5.6", "webpack": "^1.9.10", + }, + "optionalDependencies": { + "express": "^4.13.3", + "express-http-proxy": "^0.6.0", + "proxy-middleware": "^0.13.1", + "react-hot-loader": "^1.2.8", "webpack-dev-server": "^1.10.1" }, "scripts": { diff --git a/client/test/README.md b/client/test/README.md deleted file mode 100644 index f8419bcf9..000000000 --- a/client/test/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Testing - -Scope unit testing is done unsing Karma/Jasmine. (Jest was too big and slow.) - -To run tests, do `npm test` in the toplevel directory. - -The tests are placed in `__tests__` directories, relative to what they are testing. - -For more info see [Testing Flux Apps with Karma](http://kentor.me/posts/testing-react-and-flux-applications-with-karma-and-webpack/) diff --git a/client/test/karma.conf.js b/client/test/karma.conf.js deleted file mode 100644 index fd7979048..000000000 --- a/client/test/karma.conf.js +++ /dev/null @@ -1,49 +0,0 @@ -module.exports = function(config) { - config.set({ - browsers: [ - 'PhantomJS' - ], - files: [ - './polyfill.js', - { - pattern: 'tests.webpack.js', - watched: false - } - ], - frameworks: [ - 'jasmine' - ], - preprocessors: { - 'tests.webpack.js': ['webpack'] - }, - reporters: [ - 'dots', - 'coverage' - ], - coverageReporter: { - type: 'text-summary' - }, - webpack: { - module: { - loaders: [ - { - test: /\.js?$/, - exclude: /node_modules/, - loader: 'babel-loader' - } - ], - postLoaders: [ - { - test: /\.js$/, - exclude: /(test|node_modules|bower_components)\//, - loader: 'istanbul-instrumenter' - } - ] - }, - watch: true - }, - webpackServer: { - noInfo: true - } - }); -}; diff --git a/client/test/polyfill.js b/client/test/polyfill.js deleted file mode 100644 index 40e036c7d..000000000 --- a/client/test/polyfill.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Function.prototype.bind polyfill used by PhantomJS - */ -if (typeof Function.prototype.bind != 'function') { - Function.prototype.bind = function bind(obj) { - var args = Array.prototype.slice.call(arguments, 1), - self = this, - nop = function() { - }, - bound = function() { - return self.apply( - this instanceof nop ? this : (obj || {}), args.concat( - Array.prototype.slice.call(arguments) - ) - ); - }; - nop.prototype = this.prototype || {}; - bound.prototype = new nop(); - return bound; - }; -} diff --git a/client/test/preprocessor.js b/client/test/preprocessor.js deleted file mode 100644 index 4c91ab16b..000000000 --- a/client/test/preprocessor.js +++ /dev/null @@ -1,7 +0,0 @@ -var ReactTools = require('react-tools'); - -module.exports = { - process: function(src) { - return ReactTools.transform(src); - } -}; diff --git a/client/test/tests.webpack.js b/client/test/tests.webpack.js deleted file mode 100644 index e0bf705c2..000000000 --- a/client/test/tests.webpack.js +++ /dev/null @@ -1,2 +0,0 @@ -var context = require.context('../app/scripts', true, /-test\.js$/); -context.keys().forEach(context); From 92e56a492b207fbf8e99d7a34dbc0294d20d2674 Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Mon, 26 Oct 2015 14:49:20 +0000 Subject: [PATCH 3/4] Fix package.json syntax error --- client/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/package.json b/client/package.json index 7f22dbc04..7799b0d90 100644 --- a/client/package.json +++ b/client/package.json @@ -45,7 +45,7 @@ "style-loader": "^0.12.3", "url": "^0.10.3", "url-loader": "^0.5.6", - "webpack": "^1.9.10", + "webpack": "^1.9.10" }, "optionalDependencies": { "express": "^4.13.3", From e2d488182dbe83562d76830a23d05e7dfc3c07df Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Mon, 26 Oct 2015 15:00:15 +0000 Subject: [PATCH 4/4] JS test dirs are now inlined --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a0d06b71c..56ca020c7 100644 --- a/Makefile +++ b/Makefile @@ -65,13 +65,13 @@ static: client/build/app.js esc -o app/static.go -prefix client/build client/build ifeq ($(BUILD_IN_CONTAINER),true) -client/build/app.js: client/app/scripts/* +client/build/app.js: $(shell find client/app/scripts -type f) mkdir -p client/build $(SUDO) docker run -ti $(RM) -v $(shell pwd)/client/app:/home/weave/app \ -v $(shell pwd)/client/build:/home/weave/build \ $(SCOPE_UI_BUILD_IMAGE) npm run build -client-test: client/test/* +client-test: $(shell find client/app/scripts -type f) $(SUDO) docker run -ti $(RM) -v $(shell pwd)/client/app:/home/weave/app \ -v $(shell pwd)/client/test:/home/weave/test \ $(SCOPE_UI_BUILD_IMAGE) npm test