Skip to content

Commit

Permalink
Tests, coverage and much more... 🍟
Browse files Browse the repository at this point in the history
- Added badge in README.md
- Added coverage
- Added coveralls
- Added more tests for coverage
- Added an index coverage file, so we know everything of exported files
  • Loading branch information
Pierre-Alexandre St-Jean committed Apr 26, 2016
1 parent 99689b5 commit 4ef7beb
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 53 deletions.
14 changes: 10 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
.DS_STORE

dist/*
dist_test/*
node_modules/*
typings/*
# Package management
node_modules
typings
npm-debug.log

# Build files
dist
dist_test
.nyc_output
node_modules
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ install:
- npm install
- "$(npm bin)/typings install"
script:
- npm run-script build:tsc
- npm run-script build:webpack
- npm run-script build
- npm test
- npm run-script coveralls

deploy:
- provider: npm
skip_cleanup: true
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
[![Build Status](https://travis-ci.org/coveo/coveo.analytics.js.svg?branch=master)](https://travis-ci.org/coveo/coveo.analytics.js)
[![dependency status](https://david-dm.org/coveo/coveo.analytics.js.svg)](https://david-dm.org/coveo/coveo.analytics.js)
[![dev dependency status](https://david-dm.org/coveo/coveo.analytics.js/dev-status.svg)](https://david-dm.org/coveo/coveo.analytics.js#info=devDependencies)
[![Coverage Status](https://coveralls.io/repos/github/coveo/coveo.analytics.js/badge.svg?branch=master)](https://coveralls.io/github/coveo/coveo.analytics.js?branch=master)

> Coveo's usage analytics javascript client
> Coveo's usage analytics' javascript client
## Usage

You have to provide your own `promise` and `fetch` API compatible libraries.
You have to provide your own `fetch` API compatible libraries.

```bash
npm install coveo.analytics
npm install coveo.analytics isomorphic-fetch
```

Then use in typescript or javascript

```js
import fetch from 'isomorphic-fetch'; // isomorphic-fetch modifies global environment
import coveoanalytics from 'coveo.analytics';

// Create an api client
Expand All @@ -31,7 +33,6 @@ client.sendCustomEvent({
### Web Analytics Usage

```html
CoVeo
<script>
(function(c,o,v,e,O,u,a){
a='coveoua';c[a]=c[a]||function(){(c[a].q=c[a].q|| []).push(arguments)};
Expand Down
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
"main": "dist/index.js",
"browser": "dist/bundle.js",
"scripts": {
"lint": "tslint -s \"node_modules/tslint-loader/formatters/\" \"test/**/*.ts\" \"src/**/*.ts\"",
"build:webpack": "webpack",
"build:tsc": "tsc",
"test": "tsc -p tsconfig.test.json && ava \"**/*test.js\"",
"build": "npm run-script lint && npm run-script build:webpack && npm run-script build:tsc",
"test": "tsc -p tsconfig.test.json && nyc ava \"**/*test.js\"",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"clean": "rm -rf dist/*"
},
"author": "Pierre-Alexandre St-Jean <[email protected]>",
Expand All @@ -17,13 +20,15 @@
},
"license": "MIT",
"devDependencies": {
"ava": "^0.14.0",
"ava": "0.14.0",
"coveralls": "^2.11.9",
"es6-promise": "3.1.2",
"exports-loader": "0.6.3",
"express": "^4.13.4",
"express": "4.13.4",
"isomorphic-fetch": "2.2.1",
"jsdom": "^8.4.0",
"sinon": "^1.17.3",
"jsdom": "8.4.0",
"nyc": "^6.4.0",
"sinon": "1.17.3",
"ts-loader": "0.8.2",
"tslint": "3.8.0",
"tslint-loader": "2.1.3",
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as analytics from './analytics';
import * as SimpleAnalytics from './simpleanalytics';
import * as history from './history';

import * as donottrack from './donottrack';
export {
analytics,
donottrack,
history,
SimpleAnalytics
}
29 changes: 14 additions & 15 deletions test/analytics_test.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
import test from 'ava';
import * as analytics from '../src/analytics';

import * as express from 'express';
import * as http from 'http';

var app:express.Application = express();
const server: http.Server = (<any>http).createServer(app).listen()
var app: express.Application = express();
const server: http.Server = (<any>http).createServer(app).listen();
app.set('port', server.address().port);

test('Analytics: can post a view event', t => {

const response : analytics.ViewEventResponse = {
raw:undefined,
const response: analytics.ViewEventResponse = {
raw: undefined,
visitId : '123',
visitorId: '213'
}
};

app.post('/analytics/view',(req,res) => {
app.post('/analytics/view', (req, res) => {
res.status(200).send(JSON.stringify(response));
});

const client = new analytics.Client({
token: 'token',
endpoint:`http://localhost:${server.address().port}`
endpoint: `http://localhost:${server.address().port}`
});
return client.sendViewEvent({location:'here'}).then((res: analytics.ViewEventResponse)=> {
t.not(res.raw,undefined);
t.is(res.visitId,response.visitId);
t.is(res.visitorId,response.visitorId);

return client.sendViewEvent({location: 'here'}).then((res: analytics.ViewEventResponse) => {
t.not(res.raw, undefined);
t.is(res.visitId, response.visitId);
t.is(res.visitorId, response.visitorId);
});
});
});
6 changes: 6 additions & 0 deletions test/coverage_check_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import test from 'ava';
import * as coveoanalytics from '../src/index';

test('coverage', t => {
const _ = coveoanalytics;
});
2 changes: 1 addition & 1 deletion test/lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ interface Iterator<T> {
next(value?: any): IteratorResult<T>;
return?(value?: any): IteratorResult<T>;
throw?(e?: any): IteratorResult<T>;
}
}
34 changes: 19 additions & 15 deletions test/simpleanalytics_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,33 @@ import simpleanalytics from '../src/simpleanalytics';
import * as express from 'express';
import * as http from 'http';

var app:express.Application = express();
const responder = (req: express.Request,res: express.Response) => {
res.status(200).send("{}")
}
app.post('/analytics/view',responder);
const server: http.Server = (<any>http).createServer(app).listen()
var app: express.Application = express();
app.post('/analytics/view', (req: express.Request, res: express.Response) => {
res.status(200).send('{}');
});
const server: http.Server = (<any>http).createServer(app).listen();
app.set('port', server.address().port);


test('SimpleAnalytics: can\'t call without initiating', t => {
t.throws(()=>{ simpleanalytics('send') }, /init/)
t.throws(() => { simpleanalytics('send'); }, /init/);
});

test('SimpleAnalytics: can\'t init without token', t => {
t.throws(()=>{ simpleanalytics('init') }, /token/);
t.throws(() => { simpleanalytics('init'); }, /token/);
});

test('SimpleAnalytics: can send pageview', t => {
simpleanalytics('init','MYTOKEN', `http://localhost:${server.address().port}`)
simpleanalytics('send','pageview')
simpleanalytics('init', 'MYTOKEN', `http://localhost:${server.address().port}`);
simpleanalytics('send', 'pageview');
});

test('SimpleAnalytics: can send pageview with customdata', t => {
simpleanalytics('init', 'MYTOKEN', `http://localhost:${server.address().port}`);
simpleanalytics('send', 'pageview', {somedata: 'asd'});
});


test('SimpleAnalytics: can send pageview with customdata', t => {
simpleanalytics('init','MYTOKEN', `http://localhost:${server.address().port}`)
simpleanalytics('send','pageview', {somedata:'asd'});
});
test('SimpleAnalytics: can\'t send and unknown event', t => {
simpleanalytics('init', 'MYTOKEN', `http://localhost:${server.address().port}`);
t.throws(() => { simpleanalytics('send', 'kawabunga'); }, /not implemented/);
});
14 changes: 8 additions & 6 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
"declaration": false,
"noImplicitAny": true,
"removeComments": true,
"sourceMap": true
// Inline source map are required for coverage (nyc) to map correctly to good files.
"inlineSourceMap": true
},
"files": [
"test/lib.d.ts",
"test/simpleanalytics_test.ts",
"test/analytics_test.ts",
"typings/main.d.ts"
]
"test/coverage_check_test.ts",
"test/simpleanalytics_test.ts",
"test/analytics_test.ts",
"test/lib.d.ts",
"typings/main.d.ts"
]
}

0 comments on commit 4ef7beb

Please sign in to comment.