From 889336b6d02230f3b0d61a631db071c07981e946 Mon Sep 17 00:00:00 2001 From: Chris Andrews Date: Fri, 14 Dec 2018 11:03:09 +0000 Subject: [PATCH] travis and coveralls --- .travis.yml | 8 +++ README.md | 162 +++++++++++++++++++--------------------------- package-lock.json | 40 ++++++++++++ package.json | 3 +- 4 files changed, 117 insertions(+), 96 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..ad58ba8 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: node_js +node_js: + - "6" +script: + - npm run style + - npm run test:coverage +after_script: + - cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js \ No newline at end of file diff --git a/README.md b/README.md index 8402afd..c781ee3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Chai Assertions for Nock -[![npm version](https://img.shields.io/npm/v/chai-nock.svg?style=flat)](https://www.npmjs.com/package/chai-nock) +[![Build Status](https://travis-ci.org/chrisandrews7/chai-nock.svg?branch=master)](https://travis-ci.org/chrisandrews7/chai-nock) [![Coverage Status](https://coveralls.io/repos/github/chrisandrews7/chai-nock/badge.svg?branch=master)](https://coveralls.io/github/chrisandrews7/chai-nock?branch=master) [![npm version](https://img.shields.io/npm/v/chai-nock.svg?style=flat)](https://www.npmjs.com/package/chai-nock) **Nock Chai** extends [Chai](http://chaijs.com/) with a language for asserting facts about [Nock](https://www.npmjs.com/package/nock). @@ -37,123 +37,98 @@ chai.use(chaiNock); ## Assertions -### `requested` +### requested Asserts that a request has been made to the nock. ```javascript -expect(nock).to.have.been.requested; -expect(nock).not.to.have.been.requested; -``` - -#### Example +it('requested', () => { + const requestNock = nock('http://bbc.co.uk') + .get('/') + .reply(200); -```javascript -const { expect } = require('chai'); -const nock = require('nock'); -const request = require('request-promise-native'); - -describe('example', () => { - it('should make a request to bbc.co.uk', function() { - const requestNock = nock('http://bbc.co.uk') - .get('/') - .reply(200); - - request({ - uri: 'http://bbc.co.uk', - }); - - return expect(requestNock).to.have.been.requested; + request({ + uri: 'http://bbc.co.uk', }); + + return expect(requestNock).to.have.been.requested; }); ``` -### `requestedWith(body)` +### requestedWith(body) Asserts that a request has been made to the nock with a body that exactly matches the object provided. ```javascript -expect(nock).to.have.been.requestedWith(body); -expect(nock).not.to.have.been.requestedWith(body); -``` - -#### Example - -```javascript -const { expect } = require('chai'); -const nock = require('nock'); -const request = require('request-promise-native'); - -describe('example', () => { - it('should make a request to bbc.co.uk', function() { - const requestNock = nock('http://bbc.co.uk') - .get('/') - .reply(200); - - request({ - json: true, - uri: 'http://bbc.co.uk', - body: { - hello: 'world' - } - }); - - return expect(requestNock).to.have.been.requestedWith({ hello: 'world' }); +it('requestedWith', () => { + const requestNock = nock('http://bbc.co.uk') + .get('/') + .reply(200); + + request({ + json: true, + uri: 'http://bbc.co.uk', + body: { + hello: 'world' + } }); + + return expect(requestNock).to.have.been.requestedWith({ hello: 'world' }); }); ``` -### `requestedWithHeaders(headers)` +### requestedWithHeaders(headers) Asserts that a request has been made to the nock with headers that exactly match the object provided. ```javascript -expect(nock).to.have.been.requestedWithHeaders(headers); -expect(nock).not.to.have.been.requestedWithHeaders(headers); -``` - -#### Example - -```javascript -const { expect } = require('chai'); -const nock = require('nock'); -const request = require('request-promise-native'); - -describe('example', () => { - it('should make a request to bbc.co.uk with exactly correct headers', function() { - const requestNock = nock('http://bbc.co.uk') - .get('/') - .reply(200); - - request({ - json: true, - uri: 'http://bbc.co.uk', - headers: { - myHeader: 'myHeaderValue' - } - }); - - return expect(requestNock).to.have.been.requestedWithHeaders({ - host: 'bbc.co.uk', - accept: 'application/json', +it('requestedWithHeaders', () => { + const requestNock = nock('http://bbc.co.uk') + .get('/') + .reply(200); + + request({ + json: true, + uri: 'http://bbc.co.uk', + headers: { myHeader: 'myHeaderValue' - }); + } + }); + + return expect(requestNock).to.have.been.requestedWithHeaders({ + host: 'bbc.co.uk', + accept: 'application/json', + myHeader: 'myHeaderValue' }); }); ``` -_Note: request-promise-native library adds `host` and `accept` headers from the `uri` and `json` options provided so we need to include them in our exact headers object_ - -### `requestedWithHeadersMatch(headers)` +### requestedWithHeadersMatch(partialHeaders) Asserts that a request has been made to the nock with headers that contain the key/value pairs in the object provided. ```javascript -expect(nock).to.have.been.requestedWithHeadersMatch(headers); -expect(nock).not.to.have.been.requestedWithHeadersMatch(headers); +it('requestedWithHeadersMatch', () => { + const requestNock = nock('http://bbc.co.uk') + .get('/') + .reply(200); + + request({ + json: true, + uri: 'http://bbc.co.uk', + headers: { + myHeader: 'myHeaderValue', + otherHeader: 'otherHeaderValue' + } + }); + + return expect(requestNock).to.have.been.requestedWithHeadersMatch({ + myHeader: 'myHeaderValue' + }); +}); ``` -#### Example +## Usage ```javascript const { expect } = require('chai'); @@ -161,23 +136,20 @@ const nock = require('nock'); const request = require('request-promise-native'); describe('example', () => { - it('should make a request to bbc.co.uk the correct myHeader value in the headers', function() { + it('test', () => { const requestNock = nock('http://bbc.co.uk') - .get('/') - .reply(200); + .get('/') + .reply(200); request({ json: true, uri: 'http://bbc.co.uk', - headers: { - myHeader: 'myHeaderValue', - otherHeader: 'otherHeaderValue' + body: { + hello: 'world' } }); - return expect(requestNock).to.have.been.requestedWithHeadersMatch({ - myHeader: 'myHeaderValue' - }); + return expect(requestNock).to.have.been.requestedWith({ hello: 'world' }); }); }); ``` diff --git a/package-lock.json b/package-lock.json index b61c1a3..f835740 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1155,6 +1155,28 @@ "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", "dev": true }, + "coveralls": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/coveralls/-/coveralls-3.0.2.tgz", + "integrity": "sha512-Tv0LKe/MkBOilH2v7WBiTBdudg2ChfGbdXafc/s330djpF3zKOmuehTeRwjXWc7pzfj9FrDUTA7tEx6Div8NFw==", + "dev": true, + "requires": { + "growl": "1.10.5", + "js-yaml": "3.12.0", + "lcov-parse": "0.0.10", + "log-driver": "1.2.7", + "minimist": "1.2.0", + "request": "2.88.0" + }, + "dependencies": { + "minimist": { + "version": "1.2.0", + "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "dev": true + } + } + }, "cross-spawn": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", @@ -2677,6 +2699,12 @@ "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==", "dev": true }, + "growl": { + "version": "1.10.5", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", + "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", + "dev": true + }, "growly": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/growly/-/growly-1.3.0.tgz", @@ -3831,6 +3859,12 @@ "invert-kv": "1.0.0" } }, + "lcov-parse": { + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/lcov-parse/-/lcov-parse-0.0.10.tgz", + "integrity": "sha1-GwuP+ayceIklBYK3C3ExXZ2m2aM=", + "dev": true + }, "left-pad": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/left-pad/-/left-pad-1.3.0.tgz", @@ -3888,6 +3922,12 @@ "integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=", "dev": true }, + "log-driver": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/log-driver/-/log-driver-1.2.7.tgz", + "integrity": "sha512-U7KCmLdqsGHBLeWqYlFA0V0Sl6P08EE1ZrmA9cxjUE0WVqT9qnyVDPz1kzpFEP0jdJuFnasWIfSd7fsaNXkpbg==", + "dev": true + }, "loose-envify": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", diff --git a/package.json b/package.json index 2ddafcb..53b9401 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "test": "jest test", - "test:watch": "jest test --watch", + "test:coverage": "npm test -- --coverage", "style": "eslint ." }, "keywords": [ @@ -28,6 +28,7 @@ }, "homepage": "https://github.com/chrisandrews7/chai-nock#readme", "devDependencies": { + "coveralls": "^3.0.2", "eslint": "^5.9.0", "eslint-config-airbnb-base": "^13.1.0", "eslint-config-prettier": "^3.3.0",