From 7bf92df4acaa0d6b1f1cf0724dc0d3aa0e5d3b28 Mon Sep 17 00:00:00 2001 From: Esco Obong Date: Sat, 30 Aug 2014 12:37:18 -0400 Subject: [PATCH 1/3] kick off testing with test for hasNextPages --- .gitignore | 2 ++ Readme.md | 18 ++++++++++++++++++ package.json | 10 ++++++++-- test/index-test.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 test/index-test.js diff --git a/.gitignore b/.gitignore index 76c9aed..bbb91f7 100644 --- a/.gitignore +++ b/.gitignore @@ -101,3 +101,5 @@ dwsync.xml # ------------------------------------------------------------------------------ # Add your custom excludes below # ------------------------------------------------------------------------------ + +coverage/ \ No newline at end of file diff --git a/Readme.md b/Readme.md index 737ca18..2e9a265 100644 --- a/Readme.md +++ b/Readme.md @@ -165,4 +165,22 @@ if paginate.hasPreviousPages || paginate.hasNextPages(pageCount) i.fa.fa-arrow-circle-right ``` +## Running Tests + To run the test suite, first invoke the following command within the repo, installing the development dependencies: + +```bash +$ npm install +``` + + Then run the tests: + +```bash +$ npm test +``` + + To get the coverage: + +```bash +$ npm run coverage +``` \ No newline at end of file diff --git a/package.json b/package.json index f15bb67..5a3b231 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,9 @@ "description": "Node.js pagination middleware and view helpers", "main": "./index.js", "scripts": { - "prepublish": "npm prune" + "prepublish": "npm prune", + "test": "node_modules/mocha/bin/_mocha --reporter spec test/**/*-test.js", + "coverage": "istanbul cover node_modules/mocha/bin/_mocha" }, "repository": { "type": "git", @@ -20,5 +22,9 @@ "lodash": "^2.4.1", "querystring": "^0.2.0" }, - "devDependencies": {} + "devDependencies": { + "chai": "^1.9.1", + "istanbul": "^0.3.0", + "mocha": "^1.21.4" + } } diff --git a/test/index-test.js b/test/index-test.js new file mode 100644 index 0000000..eb590fd --- /dev/null +++ b/test/index-test.js @@ -0,0 +1,44 @@ +var paginate = require('../index'); +var chai = require('chai'); + +chai.should(); + +describe('paginate', function(){ + + describe('.hasNextPages(req)', function(){ + + beforeEach(function(){ + this.req = {query:{page:3}}; + }); + + it('should return function', function(){ + paginate.hasNextPages(this.req).should.be.a('function'); + }); + + describe('the returned function', function(){ + + it('should return true when there are more pages', function(){ + paginate.hasNextPages(this.req)(4).should.be.true; + }); + + it('should return false when there are no more pages', function(){ + paginate.hasNextPages(this.req)(3).should.be.false; + }); + + it('should throw an error when pageCount is not a number', function(){ + (function(){ + paginate.hasNextPages(this.req)(''); + }).should.throw(/not a number/); + }); + + it('should throw an error when pageCount is less than zero', function(){ + (function(){ + paginate.hasNextPages(this.req)(''); + }).should.throw(/\> 0/); + }); + + }) + + }); + +}); \ No newline at end of file From 798d29707be4d62cd02f9f3770383f112c804ae8 Mon Sep 17 00:00:00 2001 From: Esco Obong Date: Mon, 1 Sep 2014 13:59:07 -0400 Subject: [PATCH 2/3] removed test commands from readme, added scripts based on jshttp style guid --- Readme.md | 20 -------------------- package.json | 11 ++++++----- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/Readme.md b/Readme.md index 2e9a265..3026dcd 100644 --- a/Readme.md +++ b/Readme.md @@ -163,24 +163,4 @@ if paginate.hasPreviousPages || paginate.hasNextPages(pageCount) a(href=paginate.href()).next | Next  i.fa.fa-arrow-circle-right -``` - -## Running Tests - - To run the test suite, first invoke the following command within the repo, installing the development dependencies: - -```bash -$ npm install -``` - - Then run the tests: - -```bash -$ npm test -``` - - To get the coverage: - -```bash -$ npm run coverage ``` \ No newline at end of file diff --git a/package.json b/package.json index 5a3b231..b27a60e 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,6 @@ "version": "0.0.2", "description": "Node.js pagination middleware and view helpers", "main": "./index.js", - "scripts": { - "prepublish": "npm prune", - "test": "node_modules/mocha/bin/_mocha --reporter spec test/**/*-test.js", - "coverage": "istanbul cover node_modules/mocha/bin/_mocha" - }, "repository": { "type": "git", "url": "git://github.com/niftylettuce/express-paginate.git" @@ -26,5 +21,11 @@ "chai": "^1.9.1", "istanbul": "^0.3.0", "mocha": "^1.21.4" + }, + "scripts": { + "prepublish": "npm prune", + "test": "mocha --reporter spec --bail --check-leaks test/", + "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/", + "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/" } } From 646b94026492604b309e81aaf347141eac66592d Mon Sep 17 00:00:00 2001 From: Esco Obong Date: Mon, 1 Sep 2014 14:09:30 -0400 Subject: [PATCH 3/3] create wrapper for chai.should and add require flag to test commands --- package.json | 8 ++++---- test/index-test.js | 3 --- test/support/should.js | 2 ++ 3 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 test/support/should.js diff --git a/package.json b/package.json index b27a60e..6a659f0 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,8 @@ }, "scripts": { "prepublish": "npm prune", - "test": "mocha --reporter spec --bail --check-leaks test/", - "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/", - "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/" + "test": "mocha --reporter spec --bail --check-leaks --require test/support/should test/", + "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks --require test/support/should test/", + "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks --require test/support/should test/" } -} +} \ No newline at end of file diff --git a/test/index-test.js b/test/index-test.js index eb590fd..6588f69 100644 --- a/test/index-test.js +++ b/test/index-test.js @@ -1,7 +1,4 @@ var paginate = require('../index'); -var chai = require('chai'); - -chai.should(); describe('paginate', function(){ diff --git a/test/support/should.js b/test/support/should.js new file mode 100644 index 0000000..1ad2fe8 --- /dev/null +++ b/test/support/should.js @@ -0,0 +1,2 @@ +var chai = require('chai'); +chai.should(); \ No newline at end of file