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 2013/07/18 16:45:21 UTC
[3/3] git commit: updated refs/heads/fauxton-test-framework to c88b72a
added sinon, updated license and notice. Added tests
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/c88b72a9
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/c88b72a9
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/c88b72a9
Branch: refs/heads/fauxton-test-framework
Commit: c88b72a907d97f1e2c3cb6cf69bc285a153f737c
Parents: 251a7ef
Author: Garren Smith <ga...@gmail.com>
Authored: Thu Jul 18 16:45:01 2013 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Thu Jul 18 16:45:01 2013 +0200
----------------------------------------------------------------------
LICENSE | 63 +
NOTICE | 10 +
src/fauxton/Gruntfile.js | 7 +-
src/fauxton/app/addons/logs/tests/logSpec.js | 8 +-
src/fauxton/tasks/couchserver.js | 2 +-
src/fauxton/tasks/fauxton.js | 2 +
src/fauxton/test/core/routeObjectSpec.js | 71 +-
src/fauxton/test/mocha/sinon-chai.js | 109 +
src/fauxton/test/mocha/sinon.js | 4290 +++++++++++++++++++++
src/fauxton/test/mocha/testUtils.js | 25 +
src/fauxton/test/runner.html | 1 +
src/fauxton/test/test.config.js | 4 +-
12 files changed, 4558 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/c88b72a9/LICENSE
----------------------------------------------------------------------
diff --git a/LICENSE b/LICENSE
index d488036..d934a48 100644
--- a/LICENSE
+++ b/LICENSE
@@ -889,3 +889,66 @@ For src/fauxton/assets/js/plugins/codemirror-javascript.js
Please note that some subdirectories of the CodeMirror distribution
include their own LICENSE files, and are released under different
licences.
+
+For src/fauxton/test/mocha/mocha.js and src/fauxton/test/mocha/mocha.js
+
+ Copyright (c) 2011-2013 TJ Holowaychuk <tj...@vision-media.ca>
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ 'Software'), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+For src/fauxton/test/mocha/chai.js
+
+ Copyright (c) 2011-2013 Jake Luer jake@alogicalparadox.com
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ 'Software'), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+for src/fauxton/test/mocha/sinon-chai.js
+
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ Version 2, December 2004
+
+ Copyright © 2012–2013 Domenic Denicola <do...@domenicdenicola.com>
+
+ Everyone is permitted to copy and distribute verbatim or modified
+ copies of this license document, and changing it is allowed as long
+ as the name is changed.
+
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
+
http://git-wip-us.apache.org/repos/asf/couchdb/blob/c88b72a9/NOTICE
----------------------------------------------------------------------
diff --git a/NOTICE b/NOTICE
index 8379f97..71f9ade 100644
--- a/NOTICE
+++ b/NOTICE
@@ -142,4 +142,14 @@ This product also includes the following third-party components:
Copyright 2006-2013 (c) M. Alsup
+ * mocha.js (https://github.com/visionmedia/mocha)
+
+ Copyright (c) 2011-2013 TJ Holowaychuk <tj...@vision-media.ca>
+ * chaijs https://github.com/chaijs
+
+ Copyright (c) 2011-2013 Jake Luer jake@alogicalparadox.com
+
+ * sinon-chai
+
+ Copyright © 2012–2013 Domenic Denicola <do...@domenicdenicola.com>
http://git-wip-us.apache.org/repos/asf/couchdb/blob/c88b72a9/src/fauxton/Gruntfile.js
----------------------------------------------------------------------
diff --git a/src/fauxton/Gruntfile.js b/src/fauxton/Gruntfile.js
index 3992d91..6ebbb98 100644
--- a/src/fauxton/Gruntfile.js
+++ b/src/fauxton/Gruntfile.js
@@ -218,7 +218,7 @@ module.exports = function(grunt) {
watch: {
js: {
- files: helper.watchFiles(['.js'], ["./app/**/*.js", '!./app/load_addons.js',"./assets/**/*.js"]),
+ files: helper.watchFiles(['.js'], ["./app/**/*.js", '!./app/load_addons.js',"./assets/**/*.js", "./test/**/*.js"]),
tasks: ['watchRun'],
},
style: {
@@ -319,6 +319,11 @@ module.exports = function(grunt) {
if (!!filepath.match(/.js$/)) {
grunt.config(['jshint', 'all'], filepath);
}
+
+ console.log(filepath);
+ if (!!filepath.match(/[Ss]pec.js$/)) {
+ grunt.task.run(['mochaSetup','mocha_phantomjs']);
+ }
});
/*
http://git-wip-us.apache.org/repos/asf/couchdb/blob/c88b72a9/src/fauxton/app/addons/logs/tests/logSpec.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/logs/tests/logSpec.js b/src/fauxton/app/addons/logs/tests/logSpec.js
index 7b859f0..de164aa 100644
--- a/src/fauxton/app/addons/logs/tests/logSpec.js
+++ b/src/fauxton/app/addons/logs/tests/logSpec.js
@@ -4,13 +4,7 @@ define([
], function (Log, chai) {
var expect = chai.expect;
- describe('Example AMD test', function(){
-
- describe('Sum', function(){
- it('Should add two numbers together', function(){
- expect(10 + 2).to.equal(12);
- });
- });
+ describe('Logs Addon', function(){
describe('Log Model', function () {
var log;
http://git-wip-us.apache.org/repos/asf/couchdb/blob/c88b72a9/src/fauxton/tasks/couchserver.js
----------------------------------------------------------------------
diff --git a/src/fauxton/tasks/couchserver.js b/src/fauxton/tasks/couchserver.js
index 9641a88..bfc0c2e 100644
--- a/src/fauxton/tasks/couchserver.js
+++ b/src/fauxton/tasks/couchserver.js
@@ -49,7 +49,7 @@ module.exports = function (grunt) {
if (!!url.match(/assets/)) {
// serve any javascript or css files from here assets dir
filePath = path.join('./',url);
- } else if (!!url.match(/mocha|test\.config/)) {
+ } else if (!!url.match(/mocha|\/test\/core\/|test\.config/)) {
filePath = path.join('./test', url.replace('/test/',''));
} else if (!!url.match(/\.css|img/)) {
filePath = path.join(dist_dir,url);
http://git-wip-us.apache.org/repos/asf/couchdb/blob/c88b72a9/src/fauxton/tasks/fauxton.js
----------------------------------------------------------------------
diff --git a/src/fauxton/tasks/fauxton.js b/src/fauxton/tasks/fauxton.js
index cfcfc81..833a86d 100644
--- a/src/fauxton/tasks/fauxton.js
+++ b/src/fauxton/tasks/fauxton.js
@@ -103,6 +103,8 @@ module.exports = function(grunt) {
config: function (args) {
configInfo = args;
configInfo.paths['chai'] = "../test/mocha/chai";
+ configInfo.paths['sinon-chai'] = "../test/mocha/sinon-chai";
+ configInfo.paths['testUtils'] = "../test/mocha/testUtils";
configInfo.baseUrl = '../app';
delete configInfo.deps;
}
http://git-wip-us.apache.org/repos/asf/couchdb/blob/c88b72a9/src/fauxton/test/core/routeObjectSpec.js
----------------------------------------------------------------------
diff --git a/src/fauxton/test/core/routeObjectSpec.js b/src/fauxton/test/core/routeObjectSpec.js
index 7fdb719..45d95ac 100644
--- a/src/fauxton/test/core/routeObjectSpec.js
+++ b/src/fauxton/test/core/routeObjectSpec.js
@@ -1,8 +1,8 @@
define([
'api',
- 'chai'
-], function (FauxtonAPI, chai) {
- var assert = chai.assert,
+ 'testUtils'
+], function (FauxtonAPI, testUtils) {
+ var assert = testUtils.assert,
RouteObject = FauxtonAPI.RouteObject;
describe('RouteObjects', function () {
@@ -17,48 +17,71 @@ define([
testRouteObject = new TestRouteObject();
+ // Need to find a better way of doing this
mockLayout = {
- called: false,
- clearBreadcumbsCalled: false,
- setBreadcumbsCalled: false,
- setTemplate: function (layout) {
- this.called = true;
- },
-
- clearBreadcrumbs: function () {
- this.clearBreadcumbsCalled = true;
-
- },
-
- setBreadcrumbs: function () {
- this.setBreadcumbsCalled = true;
- }
+ setTemplate: sinon.spy(),
+ clearBreadcrumbs: sinon.spy(),
+ setView: sinon.spy(),
+ renderView: sinon.spy(),
+ hooks: [],
+ setBreadcrumbs: sinon.spy()
};
+
});
it('Should set template for first render ', function () {
testRouteObject.renderWith('the-route', mockLayout, 'args');
- assert.ok(mockLayout.called, 'setTempalte was called');
+ assert.ok(mockLayout.setTemplate.calledOnce, 'setTempalte was called');
});
it('Should not set template after first render', function () {
testRouteObject.renderWith('the-route', mockLayout, 'args');
- mockLayout.called = false;
testRouteObject.renderWith('the-route', mockLayout, 'args');
- assert.notOk(mockLayout.called, 'SetTemplate not meant to be called');
+ assert.ok(mockLayout.setTemplate.calledOnce, 'SetTemplate not meant to be called');
});
it('Should clear breadcrumbs', function () {
testRouteObject.renderWith('the-route', mockLayout, 'args');
- assert.ok(mockLayout.clearBreadcumbsCalled, 'Clear Breadcrumbs called');
+ assert.ok(mockLayout.clearBreadcrumbs.calledOnce, 'Clear Breadcrumbs called');
+ });
+
+ it('Should set breadcrumbs when breadcrumbs exist', function () {
+ testRouteObject.renderWith('the-route', mockLayout, 'args');
+ assert.ok(mockLayout.setBreadcrumbs.calledOnce, 'Set Breadcrumbs was called');
+ });
+
+ it("Should call establish of routeObject", function () {
+ var establishSpy = sinon.spy(testRouteObject,"establish");
+
+ testRouteObject.renderWith('the-route', mockLayout, 'args');
+ assert.ok(establishSpy.calledOnce, 'Calls establish');
+ });
+
+ it("Should render views", function () {
+ var view = new FauxtonAPI.View(),
+ getViewsSpy = sinon.stub(testRouteObject,"getViews"),
+ viewSpy = sinon.stub(view, "establish");
+
+ sinon.stub(view, "hasRendered").returns(false);
+ getViewsSpy.returns({'#view': view});
+
+ testRouteObject.renderWith('the-route', mockLayout, 'args');
+ assert.ok(viewSpy.calledOnce, 'Should render view');
});
- it('Should set breadcrumbs', function () {
+ it("Should not re-render a view", function () {
+ var view = new FauxtonAPI.View(),
+ getViewsSpy = sinon.stub(testRouteObject,"getViews"),
+ viewSpy = sinon.stub(view, "establish");
+
+ sinon.stub(view, "hasRendered").returns(true);
+ getViewsSpy.returns({'#view': view});
+
testRouteObject.renderWith('the-route', mockLayout, 'args');
- assert.ok(mockLayout.setBreadcumbsCalled, 'Set Breadcrumbs was called');
+ assert.notOk(viewSpy.calledOnce, 'Should render view');
});
});
http://git-wip-us.apache.org/repos/asf/couchdb/blob/c88b72a9/src/fauxton/test/mocha/sinon-chai.js
----------------------------------------------------------------------
diff --git a/src/fauxton/test/mocha/sinon-chai.js b/src/fauxton/test/mocha/sinon-chai.js
new file mode 100644
index 0000000..26cee36
--- /dev/null
+++ b/src/fauxton/test/mocha/sinon-chai.js
@@ -0,0 +1,109 @@
+(function (sinonChai) {
+ "use strict";
+
+ // Module systems magic dance.
+
+ if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
+ // NodeJS
+ module.exports = sinonChai;
+ } else if (typeof define === "function" && define.amd) {
+ // AMD
+ define(function () {
+ return sinonChai;
+ });
+ } else {
+ // Other environment (usually <script> tag): plug in to global chai instance directly.
+ chai.use(sinonChai);
+ }
+}(function sinonChai(chai, utils) {
+ "use strict";
+
+ var slice = Array.prototype.slice;
+
+ function isSpy(putativeSpy) {
+ return typeof putativeSpy === "function" &&
+ typeof putativeSpy.getCall === "function" &&
+ typeof putativeSpy.calledWithExactly === "function";
+ }
+
+ function isCall(putativeCall) {
+ return putativeCall && isSpy(putativeCall.proxy);
+ }
+
+ function assertCanWorkWith(assertion) {
+ if (!isSpy(assertion._obj) && !isCall(assertion._obj)) {
+ throw new TypeError(utils.inspect(assertion._obj) + " is not a spy or a call to a spy!");
+ }
+ }
+
+ function getMessages(spy, action, nonNegatedSuffix, always, args) {
+ var verbPhrase = always ? "always have " : "have ";
+ nonNegatedSuffix = nonNegatedSuffix || "";
+ if (isSpy(spy.proxy)) {
+ spy = spy.proxy;
+ }
+
+ function printfArray(array) {
+ return spy.printf.apply(spy, array);
+ }
+
+ return {
+ affirmative: printfArray(["expected %n to " + verbPhrase + action + nonNegatedSuffix].concat(args)),
+ negative: printfArray(["expected %n to not " + verbPhrase + action].concat(args))
+ };
+ }
+
+ function sinonProperty(name, action, nonNegatedSuffix) {
+ utils.addProperty(chai.Assertion.prototype, name, function () {
+ assertCanWorkWith(this);
+
+ var messages = getMessages(this._obj, action, nonNegatedSuffix, false);
+ this.assert(this._obj[name], messages.affirmative, messages.negative);
+ });
+ }
+
+ function createSinonMethodHandler(sinonName, action, nonNegatedSuffix) {
+ return function () {
+ assertCanWorkWith(this);
+
+ var alwaysSinonMethod = "always" + sinonName[0].toUpperCase() + sinonName.substring(1);
+ var shouldBeAlways = utils.flag(this, "always") && typeof this._obj[alwaysSinonMethod] === "function";
+ var sinonMethod = shouldBeAlways ? alwaysSinonMethod : sinonName;
+
+ var messages = getMessages(this._obj, action, nonNegatedSuffix, shouldBeAlways, slice.call(arguments));
+ this.assert(this._obj[sinonMethod].apply(this._obj, arguments), messages.affirmative, messages.negative);
+ };
+ }
+
+ function sinonMethodAsProperty(name, action, nonNegatedSuffix) {
+ var handler = createSinonMethodHandler(name, action, nonNegatedSuffix);
+ utils.addProperty(chai.Assertion.prototype, name, handler);
+ }
+
+ function exceptionalSinonMethod(chaiName, sinonName, action, nonNegatedSuffix) {
+ var handler = createSinonMethodHandler(sinonName, action, nonNegatedSuffix);
+ utils.addMethod(chai.Assertion.prototype, chaiName, handler);
+ }
+
+ function sinonMethod(name, action, nonNegatedSuffix) {
+ exceptionalSinonMethod(name, name, action, nonNegatedSuffix);
+ }
+
+ utils.addProperty(chai.Assertion.prototype, "always", function () {
+ utils.flag(this, "always", true);
+ });
+
+ sinonProperty("called", "been called", " at least once, but it was never called");
+ sinonProperty("calledOnce", "been called exactly once", ", but it was called %c%C");
+ sinonProperty("calledTwice", "been called exactly twice", ", but it was called %c%C");
+ sinonProperty("calledThrice", "been called exactly thrice", ", but it was called %c%C");
+ sinonMethodAsProperty("calledWithNew", "been called with new");
+ sinonMethod("calledBefore", "been called before %1");
+ sinonMethod("calledAfter", "been called after %1");
+ sinonMethod("calledOn", "been called with %1 as this", ", but it was called with %t instead");
+ sinonMethod("calledWith", "been called with arguments %*", "%C");
+ sinonMethod("calledWithExactly", "been called with exact arguments %*", "%C");
+ sinonMethod("calledWithMatch", "been called with arguments matching %*", "%C");
+ sinonMethod("returned", "returned %1");
+ exceptionalSinonMethod("thrown", "threw", "thrown %1");
+}));