You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2016/09/13 11:31:50 UTC
fauxton commit: updated refs/heads/master to e51775b
Repository: couchdb-fauxton
Updated Branches:
refs/heads/master 0fb3a19e0 -> e51775b8a
Run tests in browser with webpack
Run `npm run devtests` and navigate to http://127.0.0.1:8001 to see your
tests running in the browser. Edit test/dev.js to choose which files to
run
Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/e51775b8
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/e51775b8
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/e51775b8
Branch: refs/heads/master
Commit: e51775b8ac9a893a5fee1cbbb8ce4021eca214d5
Parents: 0fb3a19
Author: Garren Smith <ga...@gmail.com>
Authored: Tue Sep 13 11:48:28 2016 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Tue Sep 13 12:37:41 2016 +0200
----------------------------------------------------------------------
.gitignore | 1 +
app/addons/activetasks/components.react.jsx | 7 +-
app/addons/activetasks/stores.js | 62 +++++++------
.../tests/activetasks.componentsSpec.react.jsx | 19 ++--
.../activetasks/tests/activetasks.storesSpec.js | 12 +--
app/addons/cors/tests/actionsSpecs.js | 6 +-
package.json | 2 +
test/dev.html | 12 +++
test/dev.js | 19 ++++
webpack.config.test-dev.js | 97 ++++++++++++++++++++
10 files changed, 184 insertions(+), 53 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/e51775b8/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index e92ef53..f12dc06 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,5 +37,6 @@ test/nightwatch_tests/selenium/*
selenium-debug.log
npm-debug.log
test/bundle.js
+test/bundle.dev.js
test/templates.js
test/dashboard.assets
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/e51775b8/app/addons/activetasks/components.react.jsx
----------------------------------------------------------------------
diff --git a/app/addons/activetasks/components.react.jsx b/app/addons/activetasks/components.react.jsx
index 43c4115..4ce3a26 100644
--- a/app/addons/activetasks/components.react.jsx
+++ b/app/addons/activetasks/components.react.jsx
@@ -459,9 +459,8 @@ var ActiveTasksPollingWidgetController = React.createClass({
},
createPollingWidget: function () {
- var pollingInterval = this.state.pollingInterval;
- var s = this.getPluralForLabel();
- var onChangeHandle = this.pollingIntervalChange;
+ const {pollingInterval} = this.state;
+ const s = this.getPluralForLabel();
return (
<ul className="polling-interval-widget">
@@ -478,7 +477,7 @@ var ActiveTasksPollingWidgetController = React.createClass({
max="30"
step="1"
value={pollingInterval}
- onChange={onChangeHandle}/>
+ onChange={this.pollingIntervalChange}/>
</li>
</ul>
);
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/e51775b8/app/addons/activetasks/stores.js
----------------------------------------------------------------------
diff --git a/app/addons/activetasks/stores.js b/app/addons/activetasks/stores.js
index 547e8fd..f17088e 100644
--- a/app/addons/activetasks/stores.js
+++ b/app/addons/activetasks/stores.js
@@ -15,25 +15,28 @@ import FauxtonAPI from "../../core/api";
import ActionTypes from "./actiontypes";
var ActiveTasksStore = FauxtonAPI.Store.extend({
-
- initAfterFetching: function (collectionTable, backboneCollection) {
+ initialize () {
this._prevSortbyHeader = 'started-on';
this._headerIsAscending = true;
this._selectedRadio = 'All Tasks';
this._sortByHeader = 'started-on';
this._searchTerm = '';
- this._collection = collectionTable;
this._pollingIntervalSeconds = 5;
+
+ },
+
+ initAfterFetching (collectionTable, backboneCollection) {
+ this._collection = collectionTable;
this.sortCollectionByColumnHeader(this._sortByHeader);
this._backboneCollection = backboneCollection;
this.setIsLoading(true, new Date());
},
- isLoading: function () {
+ isLoading () {
return this._isLoading;
},
- setIsLoading: function (bool, time) {
+ setIsLoading (bool, time) {
if (bool) {
this._startTimeForLoading = time;
this._isLoading = true;
@@ -51,81 +54,84 @@ var ActiveTasksStore = FauxtonAPI.Store.extend({
}
},
- getSelectedRadio: function () {
+ getSelectedRadio () {
return this._selectedRadio;
},
- setSelectedRadio: function (selectedRadio) {
+ setSelectedRadio (selectedRadio) {
this._selectedRadio = selectedRadio;
},
- getPollingInterval: function () {
+ getPollingInterval () {
return this._pollingIntervalSeconds;
},
- setPollingInterval: function (pollingInterval) {
+ setPollingInterval (pollingInterval) {
this._pollingIntervalSeconds = pollingInterval;
},
- setPolling: function () {
+ setPolling () {
this.clearPolling();
- var id = setInterval(function () {
+ var id = setInterval(() => {
this._backboneCollection.pollingFetch();
this.setCollection(this._backboneCollection.table);
this.sortCollectionByColumnHeader(this._prevSortbyHeader, false);
this.triggerChange();
- }.bind(this), this.getPollingInterval() * 1000);
+ }, this.getPollingInterval() * 1000);
this.setIntervalID(id);
},
- clearPolling: function () {
+ clearPolling () {
clearInterval(this.getIntervalID());
},
- getIntervalID: function () {
+ getIntervalID () {
return this._intervalID;
},
- setIntervalID: function (id) {
+ setIntervalID (id) {
this._intervalID = id;
},
- setCollection: function (collection) {
+ setCollection (collection) {
this._collection = collection;
},
- getCollection: function () {
+ getCollection () {
return this._collection;
},
- setSearchTerm: function (searchTerm) {
+ setSearchTerm (searchTerm) {
this._searchTerm = searchTerm;
},
- getSearchTerm: function () {
+ getSearchTerm () {
return this._searchTerm;
},
- getSortByHeader: function () {
+ getSortByHeader () {
return this._sortByHeader;
},
- setSortByHeader: function (header) {
+ setSortByHeader (header) {
this._sortByHeader = header;
},
- getHeaderIsAscending: function () {
+ getHeaderIsAscending () {
return this._headerIsAscending;
},
- toggleHeaderIsAscending: function () {
+ toggleHeaderIsAscending () {
if (this._prevSortbyHeader === this._sortByHeader) {
this._headerIsAscending = !this._headerIsAscending;
+ return;
}
+
+ this._headerIsAscending = true;
},
- sortCollectionByColumnHeader: function (colName) {
+ sortCollectionByColumnHeader (colName) {
var collectionTable = this._collection;
var sorted = _.sortBy(collectionTable, function (item) {
@@ -141,7 +147,7 @@ var ActiveTasksStore = FauxtonAPI.Store.extend({
this._collection = sorted;
},
- getFilteredTable: function (collection) {
+ getFilteredTable (collection) {
var table = [];
//sort the table here
@@ -165,7 +171,7 @@ var ActiveTasksStore = FauxtonAPI.Store.extend({
return table;
},
- passesSearchFilter: function (item) {
+ passesSearchFilter (item) {
var searchTerm = this._searchTerm;
var regex = new RegExp(searchTerm, 'g');
@@ -183,12 +189,12 @@ var ActiveTasksStore = FauxtonAPI.Store.extend({
return regex.test(itemDatabasesTerm);
},
- passesRadioFilter: function (item) {
+ passesRadioFilter (item) {
var selectedRadio = this._selectedRadio.toLowerCase().replace(' ', '_');
return item.type === selectedRadio || selectedRadio === 'all_tasks';
},
- dispatch: function (action) {
+ dispatch (action) {
switch (action.type) {
case ActionTypes.ACTIVE_TASKS_FETCH_AND_SET:
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/e51775b8/app/addons/activetasks/tests/activetasks.componentsSpec.react.jsx
----------------------------------------------------------------------
diff --git a/app/addons/activetasks/tests/activetasks.componentsSpec.react.jsx b/app/addons/activetasks/tests/activetasks.componentsSpec.react.jsx
index 8b60af6..3b1dace 100644
--- a/app/addons/activetasks/tests/activetasks.componentsSpec.react.jsx
+++ b/app/addons/activetasks/tests/activetasks.componentsSpec.react.jsx
@@ -20,6 +20,7 @@ import Actions from "../actions";
import utils from "../../../../test/mocha/testUtils";
import TestUtils from "react-addons-test-utils";
import sinon from "sinon";
+import { mount } from 'enzyme';
var assert = utils.assert;
var restore = utils.restore;
var activeTasksStore = Stores.activeTasksStore;
@@ -28,27 +29,21 @@ activeTasksCollection.parse(fakedResponse);
describe('Active Tasks -- Components', function () {
+ afterEach(() => {
+ activeTasksStore.clearPolling();
+ });
+
describe('Active Tasks Polling (Components)', function () {
var pollingWidgetDiv, pollingWidget;
- beforeEach(function () {
- pollingWidgetDiv = document.createElement('div');
- pollingWidget = TestUtils.renderIntoDocument(
- <Components.ActiveTasksPollingWidgetController />, pollingWidgetDiv
- );
- });
-
afterEach(function () {
- ReactDOM.unmountComponentAtNode(pollingWidgetDiv);
restore(Actions.changePollingInterval);
});
it('should trigger update polling interval', function () {
+ const controller = mount(<Components.ActiveTasksPollingWidgetController />);
var spy = sinon.spy(Actions, 'changePollingInterval');
- var rangeNode = TestUtils.findRenderedDOMComponentWithTag(pollingWidget, 'input');
- var time = '9';
-
- TestUtils.Simulate.change(rangeNode, {target: {value: time}});
+ controller.find('#polling-range').simulate('change', {target: {value: 9}});
assert.ok(spy.calledOnce);
});
});
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/e51775b8/app/addons/activetasks/tests/activetasks.storesSpec.js
----------------------------------------------------------------------
diff --git a/app/addons/activetasks/tests/activetasks.storesSpec.js b/app/addons/activetasks/tests/activetasks.storesSpec.js
index d408ef2..b2d0b30 100644
--- a/app/addons/activetasks/tests/activetasks.storesSpec.js
+++ b/app/addons/activetasks/tests/activetasks.storesSpec.js
@@ -38,7 +38,6 @@ describe('Active Tasks -- Stores', function () {
});
describe('Active Task Stores - Polling', function () {
- var pollingWidgetDiv, pollingWidget;
beforeEach(function () {
activeTasksStore.initAfterFetching(activeTasksCollection.table, activeTasksCollection);
@@ -54,14 +53,14 @@ describe('Active Tasks -- Stores', function () {
var minTime = 1;
activeTasksStore.setPollingInterval(minTime);
activeTasksStore.setPolling();
- assert.ok(spy.calledOnce);
+ assert.ok(spy.calledOnce, 'not called');
setInterval(spy, minTime * 1000);
- clock.tick(minTime * 1000);
- assert.ok(spy.calledTwice);
+ clock.tick(minTime * 1001);
+ assert.ok(spy.calledTwice, 'not called twice');
- clock.tick(minTime * 1000);
- assert.ok(spy.calledThrice);
+ clock.tick(minTime * 1001);
+ assert.ok(spy.calledThrice, 'not called 3 times');
});
it('should poll at the max time', function () {
@@ -181,6 +180,7 @@ describe('Active Tasks -- Stores', function () {
it('should set header as ascending, if different header is selected', function () {
activeTasksStore._sortByHeader = 'differentHeader';
+ activeTasksStore._prevSortbyHeader = 'sameHeader';
activeTasksStore.toggleHeaderIsAscending();
assert.ok(activeTasksStore.getHeaderIsAscending());
});
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/e51775b8/app/addons/cors/tests/actionsSpecs.js
----------------------------------------------------------------------
diff --git a/app/addons/cors/tests/actionsSpecs.js b/app/addons/cors/tests/actionsSpecs.js
index 6778982..7391468 100644
--- a/app/addons/cors/tests/actionsSpecs.js
+++ b/app/addons/cors/tests/actionsSpecs.js
@@ -10,13 +10,13 @@
// License for the specific language governing permissions and limitations under
// the License.
import app from "../../../app";
-import testUtils from "testUtils";
+import utils from "../../../../test/mocha/testUtils";
import FauxtonAPI from "../../../core/api";
import Actions from "../actions";
import sinon from "sinon";
-const assert = testUtils.assert;
-const restore = testUtils.restore;
+const assert = utils.assert;
+const restore = utils.restore;
describe('CORS actions', function () {
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/e51775b8/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 7dfd465..0e38b94 100644
--- a/package.json
+++ b/package.json
@@ -19,6 +19,7 @@
"enzyme": "^2.4.1",
"es5-shim": "4.5.4",
"mocha": "^2.4.5",
+ "mocha-loader": "^1.0.0",
"mocha-phantomjs": "git+https://github.com/garrensmith/mocha-phantomjs.git",
"nightwatch": "~0.9.0",
"phantomjs-prebuilt": "^2.1.7",
@@ -106,6 +107,7 @@
"couchdb": "grunt couchdb",
"couchapp": "grunt couchapp_deploy",
"dev": "node ./devserver.js",
+ "devtests": "webpack-dev-server --config webpack.config.test-dev.js --debug --progress",
"nightwatch": "grunt nightwatch",
"start": "node ./bin/fauxton",
"start-debug": "DIST=./dist/debug node ./bin/fauxton",
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/e51775b8/test/dev.html
----------------------------------------------------------------------
diff --git a/test/dev.html b/test/dev.html
new file mode 100644
index 0000000..7430ea6
--- /dev/null
+++ b/test/dev.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Mocha</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
+ <script src="./bundle.dev.js"></script>
+ </head>
+ <body>
+ </body>
+</html>
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/e51775b8/test/dev.js
----------------------------------------------------------------------
diff --git a/test/dev.js b/test/dev.js
new file mode 100644
index 0000000..874a35e
--- /dev/null
+++ b/test/dev.js
@@ -0,0 +1,19 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+
+// This will search for files ending in .test.js and require them
+// so that they are added to the webpack bundle
+var context = require.context('../app/', true, /[Ss]pec/);
+console.log('Testing files', context.keys());
+context.keys().forEach(context);
+module.exports = context;
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/e51775b8/webpack.config.test-dev.js
----------------------------------------------------------------------
diff --git a/webpack.config.test-dev.js b/webpack.config.test-dev.js
new file mode 100644
index 0000000..c49102b
--- /dev/null
+++ b/webpack.config.test-dev.js
@@ -0,0 +1,97 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+var webpack = require('webpack');
+var path = require('path');
+
+module.exports = {
+ entry: [
+ 'mocha!./test/dev.js', //Our starting point for our testing.
+ ],
+ module: {
+ preLoaders: [
+ {
+ test: /\.jsx?$/,
+ loaders: ['eslint'],
+ exclude: /node_modules/
+ }
+ ],
+ loaders: [
+ {
+ test: /\.jsx?$/,
+ exclude: /node_modules/,
+ //loader: 'react-hot!babel'
+ loader: 'babel'
+ },
+ { test: require.resolve("jquery"),
+ loader: "expose?$!expose?jQuery"
+ },
+ { test: require.resolve("sinon"),
+ loader: "expose?sinon"
+ },
+ { test: require.resolve("backbone"),
+ loader: "expose?Backbone"
+ },
+ {
+ test: require.resolve("react"),
+ loader: "imports?shim=es5-shim/es5-shim&sham=es5-shim/es5-sham"
+ },
+ {
+ test: /\.less$/,
+ loader: 'style!css!less'
+ },
+ { test: /\.css$/, loader: 'style!css' },
+ {
+ test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
+ loader: 'url?limit=10000&mimetype=application/font-woff&name=dashboard.assets/fonts/[name].[ext]'
+ },
+ {
+ test: /\.woff2(\?\S*)?$/, loader: 'url?limit=10000&mimetype=application/font-woff2&name=dashboard.assets/fonts/[name].[ext]'
+ },
+ {
+ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/font-tff&name=dashboard.assets/fonts/[name].[ext]'
+ },
+ { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file?name=dashboard.assets/fonts/[name].[ext]' },
+ { test: /\.swf(\?v=\d+\.\d+\.\d+)?$/, loader: 'file?name=dashboard.assets/[name].[ext]' },
+ { test: /\.png(\?v=\d+\.\d+\.\d+)?$/, loader: 'file?name=dashboard.assets/img/[name].[ext]' },
+ { test: /\.gif(\?v=\d+\.\d+\.\d+)?$/, loader: 'file?name=dashboard.assets/img/[name].[ext]' },
+ { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=image/svg+xml&name=dashboard.assets/img/[name].[ext]' }
+ ]
+ },
+ resolve: {
+ extensions: ['', '.js', '.jsx'], //We can use .js and React's .jsx files using Babel
+ alias: {
+ "bootstrap": "../assets/js/libs/bootstrap",
+ "underscore": "lodash"
+ }
+ },
+ output: {
+ path: __dirname + '/test',
+ filename: 'bundle.dev.js' //All our code is compiled into a single file called bundle.js
+ },
+ externals: { //for webpack to play nice with enzyme
+ "jsdom": "window",
+ "cheerio": "window",
+ 'react/lib/ExecutionEnvironment': true,
+ 'react/lib/ReactContext': 'window',
+ 'react/addons': true
+ },
+ plugins: [
+ new webpack.optimize.LimitChunkCountPlugin({maxChunks: 1})
+ ],
+ devServer: {
+ host: '0.0.0.0',
+ port: 8001,
+ historyApiFallback: {
+ index: './test/dev.html'
+ }
+ }
+};