diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8bdef76 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +node_modules +.DS_Store +*~ +*.log +npm-debug.log +package-lock.json diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..08c56af --- /dev/null +++ b/.jshintrc @@ -0,0 +1,32 @@ +{ + "curly": true, + "eqeqeq": true, + "immed": true, + "newcap": true, + "noarg": true, + "sub": true, + "undef": true, + "unused": true, + "eqnull": true, + "browser": true, + "node": true, + "strict": true, + "globalstrict": true, + "white": true, + "indent": 2, + "maxlen": 100, + "globals": { + "process": false, + "global": false, + "require": false, + "console": false, + "describe": false, + "before": false, + "beforeEach": false, + "after": false, + "afterEach": false, + "it": false, + "emit": false, + "mocha": false + } +} diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..0b1dd70 --- /dev/null +++ b/.npmignore @@ -0,0 +1,6 @@ +.git* +dist +node_modules +.DS_Store +*~ +npm-debug.log diff --git a/README.md b/README.md index ec4f195..f363e4f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # slouch -Interface with CouchDB without the heavy lifting + +## Install + + $ npm install couch-slouch diff --git a/TESTING.md b/TESTING.md new file mode 100644 index 0000000..be8ee86 --- /dev/null +++ b/TESTING.md @@ -0,0 +1,55 @@ +# Testing + +## Test in node + +This will run the tests in node: + + $ npm run node-test + +You can also check for 100% code coverage using: + + $ npm run node-full-test + You can then view the test coverage by opening cache/coverage/node/lcov-report/index.html in a browser + +Run specific tests: + + $ npm run node-test -- -- -g 'some reg-ex' + +Run specific tests and generate code coverage: + + $ npm run node-test -- -- --coverage -g 'some reg-ex' + + +## Manual browser tests + + $ npm run browser-server + Use any browser to visit http://127.0.0.1:8001/index.html + And you can filter the tests, e.g. http://127.0.0.1:8001/index.html?grep=reg-ex + + +## Automated browser tests + +phantomjs: + + $ npm run browser-test-phantomjs + +You can also filter the tests, e.g. + + $ npm run browser-test-phantomjs -- -g 'some reg-ex' + +Chrome: + +Note: you must have Chrome installed + + $ npm run browser-test-phantomjs -- -b selenium:chrome + +Firefox: + +Note: you must have Firefox installed + + $ npm run browser-test-phantomjs -- -b selenium:firefox + +Test in phantomjs, generate code coverage and check for 100% coverage: + + $ npm run browser-coverage-full-test + You can then view the test coverage by opening cache/coverage/browser/lcov-report/index.html in any browser diff --git a/beautify.json b/beautify.json new file mode 100644 index 0000000..48add22 --- /dev/null +++ b/beautify.json @@ -0,0 +1,6 @@ +{ + "indent_size": 2, + "jslint_happy": true, + "wrap_line_length": 100, + "end_with_newline": true +} diff --git a/cache/.gitignore b/cache/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/cache/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..474ffc5 --- /dev/null +++ b/circle.yml @@ -0,0 +1,21 @@ +# Doesn't actually work! +# node: +# version: 7.10.0 + +dependencies: + pre: + - nvm install 7.10.0 + - nvm use 7.10.0 && npm install -g npm + + override: + - nvm use 7.10.0 && npm install + +test: + pre: + - nvm use 7.10.0 && npm run assert-beautified + - nvm use 7.10.0 && npm run jshint + + override: + - nvm use 7.10.0 && npm run node-full-test + - nvm use 7.10.0 && npm run browser-test-phantomjs + - nvm use 7.10.0 && npm run browser-coverage-full-test diff --git a/index.js b/index.js new file mode 100644 index 0000000..5f164ea --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = require('./scripts'); diff --git a/package.json b/package.json new file mode 100644 index 0000000..f314c0f --- /dev/null +++ b/package.json @@ -0,0 +1,58 @@ +{ + "name": "couch-slouch", + "version": "0.0.1", + "description": "Interface with CouchDB without the heavy lifting", + "main": "index.js", + "repository": { + "type": "git", + "url": "git://github.com/redgeoff/couch-slouch" + }, + "keywords": [ + "js", + "seed" + ], + "author": "Geoffrey Cox", + "license": "MIT", + "bugs": { + "url": "https://github.com/redgeoff/couch-slouch/issues" + }, + "scripts": { + "assert-beautified": "beautify-proj -i test -c beautify.json && beautify-proj -i scripts -c beautify.json", + "beautify": "beautify-proj -i test -o . -c beautify.json && beautify-proj -i scripts -o . -c beautify.json", + "jshint": "jshint -c .jshintrc test scripts", + "node-test": "istanbul test --dir cache/coverage/node node_modules/mocha/bin/_mocha test/node.js", + "node-full-test": "npm run node-test --coverage && istanbul check-coverage --lines 100 --function 100 --statements 100 --branches 100", + "browser-server": "node_modules/gofur/scripts/browser/serve.js -c cache -t test/browser.js", + "browser-test": "node_modules/gofur/scripts/browser/test.js -c cache -t test/browser.js", + "browser-test-firefox": "node_modules/gofur/scripts/browser/test.js -c cache -t test/browser.js -b selenium:firefox", + "browser-test-chrome": "node_modules/gofur/scripts/browser/test.js -c cache -t test/browser.js -b selenium:chrome", + "browser-test-phantomjs": "node_modules/gofur/scripts/browser/test.js -c cache -t test/browser.js -b selenium:phantomjs", + "browser-coverage-server": "node_modules/gofur/scripts/browser-coverage/serve.js -c cache -t test/browser.js", + "browser-coverage-test": "node_modules/gofur/scripts/browser-coverage/test.js -c cache -t test/browser.js", + "browser-coverage-report": "istanbul report --dir cache/coverage/browser --root cache/coverage/browser lcov", + "browser-coverage-check": "istanbul check-coverage --lines 100 --function 100 --statements 100 --branches 100 cache/coverage/browser/coverage.json", + "browser-coverage-full-test": "npm run browser-coverage-test && npm run browser-coverage-report && npm run browser-coverage-check", + "test": "npm run assert-beautified && npm run jshint && npm run node-full-test && npm run browser-coverage-full-test", + "TODO-build": "", + "TODO-test-in-sauce": "" + }, + "dependencies": { + "bluebird": "^3.5.0" + }, + "devDependencies": { + "beautify-proj": "^1.0.0", + "browserify": "^14.4.0", + "chai": "^4.1.0", + "chai-as-promised": "^6.0.0", + "gofur": "^0.0.7", + "istanbul": "^0.4.5", + "jshint": "^2.9.4", + "mocha": "^3.4.2", + "request": "^2.81.0" + }, + "greenkeeper": { + "ignore": [ + "chai-as-promised" + ] + } +} diff --git a/scripts/foo.js b/scripts/foo.js new file mode 100644 index 0000000..8f09e93 --- /dev/null +++ b/scripts/foo.js @@ -0,0 +1,13 @@ +'use strict'; + +var Promise = require('bluebird'); + +var Foo = function () { + this._thing = 'yar'; +}; + +Foo.prototype.bar = function () { + return Promise.resolve(this._thing); +}; + +module.exports = Foo; diff --git a/test/browser.js b/test/browser.js new file mode 100644 index 0000000..13e6e7e --- /dev/null +++ b/test/browser.js @@ -0,0 +1,21 @@ +'use strict'; + +var chai = require('chai'); +chai.use(require('chai-as-promised')); +chai.should(); + +var Foo = require('../scripts/foo'); + +require('./node-and-browser'); + +describe('browser', function () { + + it('should test in only the browser', function () { + // TODO: insert tests that can only be tested in the browser + var foo = new Foo(); + return foo.bar().then(function (thing) { + thing.should.eql('yar'); + }); + }); + +}); diff --git a/test/node-and-browser.js b/test/node-and-browser.js new file mode 100644 index 0000000..42bfaff --- /dev/null +++ b/test/node-and-browser.js @@ -0,0 +1,15 @@ +'use strict'; + +var Foo = require('../scripts/foo'); + +describe('node and browser', function () { + + it('should test in both node and the browser', function () { + // TODO: insert tests that can be tested in both node and the browser + var foo = new Foo(); + return foo.bar().then(function (thing) { + thing.should.eql('yar'); + }); + }); + +}); diff --git a/test/node.js b/test/node.js new file mode 100644 index 0000000..e1d445d --- /dev/null +++ b/test/node.js @@ -0,0 +1,21 @@ +'use strict'; + +var chai = require('chai'); +chai.use(require('chai-as-promised')); +chai.should(); + +var Foo = require('../scripts/foo'); + +require('./node-and-browser'); + +describe('node', function () { + + it('should test only in node', function () { + // TODO: insert tests that can only be tested in node + var foo = new Foo(); + return foo.bar().then(function (thing) { + thing.should.eql('yar'); + }); + }); + +});