Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tim/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
30 changes: 30 additions & 0 deletions tim/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var appFiles = ['index.js', 'lib/**/*.js', 'bin/**/*.js' ];
var testFiles = ['test/**/*.js'];

gulp.task('watch', function() {
gulp.watch(['lib/**', 'test/**', 'gulpfile.js'], ['default']);
});

gulp.task('jshint:test', function() {
return gulp.src(testFiles)
.pipe(jshint.reporter('default'));
});

gulp.task('jshint:greet', function() {
return gulp.src(testFiles)
.pipe(jshint.reporter('default'));
});

// To implement mocha test
gulp.task('mocha:test', function() {
return gulp.src('./test/*.js', {read: false})

.pipe(mocha({reporter: 'nyan'}));
});

gulp.task('mocha', ['mocha:test']);
gulp.task('jshint', ['jshint:test', 'jshint:greet']);
gulp.task('default', ['jshint', 'mocha']);
9 changes: 9 additions & 0 deletions tim/lib/greet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

exports.greeting = function(name) {
console.log(arguments);
name = name || process.argv[2];
return 'word ' + name + '!';
};

console.log(exports.greeting("tim"));

4 changes: 4 additions & 0 deletions tim/myPref.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"node": true,
"predef": ["describe", "it", "before", "after"]
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really small file compared to what I'm used to. Check out a ton of the options you can set for jshint: https://github.com/jshint/jshint/blob/master/examples/.jshintrc.

29 changes: 29 additions & 0 deletions tim/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "greet",
"version": "0.1.0",
"description": "A super awesome app used greet people!",
"main": "index.js",
"scripts": {
"test": "./node_modules/gulp/bin/gulp.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/timcmiller/simple-test-and-modular-patterns.git"
},
"keywords": [
"greet"
],
"author": "Tim Miller",
"license": "MIT",
"bugs": {
"url": "https://github.com/timcmiller/simple-test-and-modular-patterns/issues"
},
"homepage": "https://github.com/timcmiller/simple-test-and-modular-patterns#readme",
"devDependencies": {
"chai": "3.4.0",
"gulp": "^3.9.0",
"gulp-jshint": "^1.11.2",
"gulp-mocha": "^2.1.3",
"mocha": "2.3.3"
}
}
28 changes: 28 additions & 0 deletions tim/test/test_greet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env node
var expect = require('chai').expect;
var greet = require(__dirname + '/../lib/greet');

describe('the greet function', function() {

it('should greet someone by name', function() {
expect(greet.greeting('tim')).to.eql('word tim!');
});

describe('calling this funciton through node', function() {

before(function() {
this.backup = process.argv;
process.argv = ['node', 'myfile', 'test name'];

});

after(function() {
process.argv = this.backup;
});

it('should pull from process.argv', function() {
expect(greet.greeting()).eql('word test name!');
});
});

});