-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using gulp/mocha/chai. adding code coverage
- Loading branch information
1 parent
e99f076
commit 60bbe53
Showing
15 changed files
with
234 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// adapted from: https://github.com/Khan/style-guides/pull/25 | ||
{ | ||
"plugins": [ | ||
], | ||
"ecmaFeatures": { | ||
"modules": true | ||
}, | ||
"env": { | ||
"browser": true, | ||
"node": true, | ||
"mocha": true | ||
}, | ||
"rules": { | ||
"arrow-parens": [2, "always"], | ||
"arrow-spacing": 2, | ||
"brace-style": 2, | ||
"camelcase": [2, { | ||
"properties": "always" | ||
}], | ||
"comma-dangle": [1, "always-multiline"], | ||
"comma-dangle": [2, "never"], | ||
"comma-spacing": [2, { | ||
"before": false, | ||
"after": true | ||
}], | ||
"eol-last": [0], | ||
"guard-for-in": 2, | ||
//"indent": [2, 4], | ||
"linebreak-style": [2, "unix"], | ||
/* | ||
"max-len": [2, 80, 4, { | ||
"ignoreUrls": true, | ||
"ignorePattern": "^\\s*const\\s.+=\\s*require\\s*\\(" | ||
}], | ||
*/ | ||
"no-alert": 2, | ||
"no-array-constructor": 2, | ||
"no-const-assign": 2, | ||
"no-debugger": 2, | ||
"no-dupe-keys": 2, | ||
"no-new-object": 2, | ||
"no-spaced-func": 2, | ||
"no-this-before-super": 2, | ||
"no-throw-literal": 2, | ||
"no-trailing-spaces": 2, | ||
"no-unreachable": 2, | ||
"no-unused-vars": 1, | ||
"no-var": 0, | ||
//"object-curly-spacing": [2, "always"], | ||
"one-var": [2, "never"], | ||
"prefer-const": 1, | ||
"prefer-template": 2, | ||
"quotes": [2, "single"], | ||
"semi": [2, "always"], | ||
"space-after-keywords": [2, "always"], | ||
"space-before-blocks": 2, | ||
"space-before-function-paren": [2, { | ||
"anonymous": "always", | ||
"named": "never" | ||
}], | ||
"space-infix-ops": 2, | ||
"space-return-throw-case": 2, | ||
"strict": [0, "never"], | ||
"valid-jsdoc": 2 | ||
}, | ||
"extends": "eslint:recommended" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
/node_modules/ | ||
_ignore/ | ||
coverage/ | ||
node_modules/ | ||
.DS_Store | ||
.npm-debug.log | ||
.project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
.git* | ||
_ignore/ | ||
test/ | ||
.DS_Store | ||
.gitignore | ||
.npm-debug.log | ||
.project | ||
.travis.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var random_useragent = require('random-useragent'); | ||
var result = random_useragent.getRandom(); // gets a random user agent string | ||
console.log(result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
language: node_js | ||
node_js: | ||
- "0.10" | ||
before_install: npm install -g grunt-cli | ||
install: npm install | ||
- 'stable' | ||
- '4.2' | ||
- '4.1' | ||
- '4.0' | ||
- '0.12' | ||
- '0.11' | ||
- '0.10' | ||
before_script: | ||
- npm install -g gulp | ||
script: | ||
- gulp test | ||
- cat ./coverage/lcov.info | ./node_modules/.bin/coveralls --verbose |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/*eslint no-console: 0 */ | ||
'use strict'; | ||
var gulp = require('gulp'); | ||
var eslint = require('gulp-eslint'); | ||
var isparta = require('isparta'); | ||
var istanbul = require('gulp-istanbul'); | ||
var mocha = require('gulp-mocha'); | ||
var files = { | ||
lint: ['*.js'], | ||
src: ['index.js'], | ||
test: ['test.js'] | ||
}; | ||
|
||
gulp.task('lint', function () { | ||
return gulp.src(files.lint) | ||
// eslint() attaches the lint output to the eslint property | ||
// of the file object so it can be used by other modules. | ||
.pipe(eslint()) | ||
// eslint.format() outputs the lint results to the console. | ||
// Alternatively use eslint.formatEach() (see Docs). | ||
.pipe(eslint.format('stylish')) | ||
// To have the process exit with an error code (1) on | ||
// lint error, return the stream and pipe to failAfterError last. | ||
.pipe(eslint.failAfterError()); | ||
}); | ||
|
||
gulp.task('test', function () { | ||
return gulp.src(files.src) | ||
.pipe(istanbul({ | ||
instrumenter: isparta.Instrumenter, | ||
includeUntested: true | ||
})) | ||
// Force `require` to return covered files | ||
.pipe(istanbul.hookRequire()) | ||
.on('finish', function () { | ||
gulp.src(files.test, {read: false}) | ||
// gulp-mocha needs filepaths so you can't have any plugins before it | ||
.pipe(mocha({ | ||
reporter: 'spec' | ||
})) | ||
.on('error', function (err) { | ||
console.error(err.toString()); | ||
this.emit('end'); | ||
}) | ||
.pipe(istanbul.writeReports({ | ||
dir: './coverage', | ||
reporters: ['lcov', 'json', 'text-summary'] | ||
})); | ||
}); | ||
}); | ||
|
||
gulp.task('watch', function () { | ||
gulp.watch([files.lint], ['lint', 'test']); | ||
}); | ||
|
||
// setup default task | ||
gulp.task('default', ['lint', 'test', 'watch']); | ||
|
||
// handle errors | ||
process.on('uncaughtException', function (e) { | ||
console.error(e); | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict'; | ||
|
||
var expect = require('chai').expect; | ||
var lib = require('./index.js'); | ||
var iterations = 100; | ||
|
||
describe('random-useragent', function () { | ||
it('don\'t change data', function () { | ||
var d1; | ||
var d2; | ||
var key = 'someNewKey'; | ||
d1 = lib.getAllData(); | ||
d1[0][key] = 'foo'; | ||
d2 = lib.getAllData(); | ||
expect(d1[0].hasOwnProperty(key)).to.equal(true); | ||
expect(d2[0].hasOwnProperty(key)).to.equal(false); | ||
}); | ||
it('return values', function () { | ||
expect(lib.getRandom()).to.be.a.string; | ||
expect(lib.getRandomData()).to.be.an.object; | ||
expect(lib.getAll()).to.be.an.array; | ||
expect(lib.getAllData()).to.be.an.array; | ||
}); | ||
it('randomization works', function (done) { | ||
var i; | ||
for (i = 0; i < iterations; i++) { | ||
expect(lib.getRandom()).to.be.a.string; | ||
expect(lib.getRandomData()).to.be.an.object; | ||
} | ||
done(); | ||
}); | ||
it('valid filters work', function () { | ||
var filter = function (item) { | ||
return item.browserName === 'Chrome'; | ||
}; | ||
expect(lib.getRandom(filter)).to.be.a.string; | ||
expect(lib.getRandomData(filter)).to.be.an.object; | ||
expect(lib.getAll(filter)).to.be.an.array; | ||
expect(lib.getAllData(filter)).to.be.an.array; | ||
expect(lib.getAll(filter)).to.have.length.gt(0); | ||
expect(lib.getAllData(filter)).to.have.length.gt(0); | ||
}); | ||
it('invalid filters work', function () { | ||
var filter = function (item) { | ||
return item.browserName === 'Some Fake Browser'; | ||
}; | ||
expect(lib.getRandom(filter)).to.be.null; | ||
expect(lib.getRandomData(filter)).to.be.null; | ||
expect(lib.getAll(filter)).to.be.an.array; | ||
expect(lib.getAllData(filter)).to.be.an.array; | ||
expect(lib.getAll(filter)).to.have.length(0); | ||
expect(lib.getAllData(filter)).to.have.length(0); | ||
}); | ||
}); |
Oops, something went wrong.