Skip to content

Commit

Permalink
Merge pull request #24 from juriejan/better-filename-matching
Browse files Browse the repository at this point in the history
Better filename matching
  • Loading branch information
geekdave committed Apr 4, 2014
2 parents 0253133 + 88eae80 commit 253d452
Show file tree
Hide file tree
Showing 29 changed files with 522 additions and 219 deletions.
47 changes: 33 additions & 14 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,45 @@ module.exports = function(grunt) {
files: [
'example/js/**/*.js',
'example/test/spec/**/*.js',
'example-requirejs/js/**/*.js',
'example-requirejs/test/spec/**/*.js',
'phantomjs/*',
'tasks/*',
'Gruntfile.js'
],
tasks: 'test'
}
},
blanket_mocha : {
test: {
src: ['example/test.html'],
options : {
threshold : 50,
globalThreshold : 65,
log : true,
logErrors: true,
moduleThreshold : 60,
modulePattern : "./src/(.*?)/"
}
blanket_mocha : {
test: {
src: ['example/test.html'],
options : {
threshold : 60,
globalThreshold : 65,
log : true,
logErrors: true,
moduleThreshold : 60,
modulePattern : "./src/(.*?)/",
customThreshold: {
'./src/spelling/plurals.js': 50
}

}
},

test_requirejs: {
src: ['example-requirejs/test.html'],
options : {
threshold : 60,
globalThreshold : 65,
log : true,
logErrors: true,
moduleThreshold : 60,
modulePattern : "./src/(.*?)/",
customThreshold: {
'./src/spelling/plurals.js': 50
}
}
}
},
connect: {
testUrls: {
options: {
Expand Down Expand Up @@ -89,5 +106,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-connect');

// By default, lint and run all tests.
grunt.task.registerTask('default', ['jshint', 'blanket_mocha']);
grunt.task.registerTask('default', [
'jshint', 'blanket_mocha:test', 'blanket_mocha:test_requirejs'
]);
};
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ grunt.loadNpmTasks('grunt-blanket-mocha');

## Dependencies

* Blanket.js (tested with v1.1.5)
* Blanket.js (tested with v1.1.5)
* Mocha (tested with v1.14.0)

## The "blanket_mocha" task
Expand All @@ -55,8 +55,7 @@ This plugin is based off of grunt-contrib-mocha. For general config options and

### Demo

See the `example` directory for a fully-working example of the setup, including some of the scaffolding required
to get all the pieces to fit together. The `README` in that directory will walk you through it.
See the `example` and `example-requires` directories for a fully-working examples of the setup, including some of the scaffolding required to get all the pieces to fit together. The `README` in that directory will walk you through it.

### Gruntfile

Expand All @@ -66,10 +65,10 @@ In your project's Gruntfile, add a section named `blanket_mocha` to the data obj
grunt.initConfig({
blanket_mocha: {
test: {
src: ['specs/test.html'],
options : {
src: ['specs/test.html'],
options : {
threshold : 70
}
}
}
}
})
Expand Down
36 changes: 36 additions & 0 deletions example-requirejs/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*global module*/
module.exports = function(grunt) {

"use strict";

grunt.initConfig({

blanket_mocha : {
test: {
src: ['test.html'],
options : {
threshold : 60,
globalThreshold : 65,
log : true,
logErrors: true,
moduleThreshold : 60,
modulePattern : "./src/(.*?)/",
customThreshold: {
'./src/spelling/plurals.js': 50
}
}
}

}
});

// Loading dependencies
for (var key in grunt.file.readJSON("package.json").devDependencies) {
if (key !== "grunt" && key.indexOf("grunt") === 0) {
grunt.loadNpmTasks(key);
}
}

grunt.registerTask('coverage', ['blanket_mocha']);
grunt.registerTask('default', ['blanket_mocha']);
};
6 changes: 6 additions & 0 deletions example-requirejs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Demo

1. First, `cd` to the `examples` directory (this directory)
2. Next, run `npm install`
3. Run `grunt`
4. You should see some tests run, and a coverage report which will demonstrate a failure at the "per-module" level.
8 changes: 8 additions & 0 deletions example-requirejs/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";

define([

], function(
) {

});
22 changes: 22 additions & 0 deletions example-requirejs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "grunt-blanket-mocha-test",
"description": "Test for grunt-blanket-mocha.",
"version": "0.5.1",
"homepage": "https://github.com/ModelN/grunt-blanket-mocha",
"author": {
"name": "Dave Cadwallader",
"email": "[email protected]"
},
"main": "Gruntfile.js",
"engines": {
"node": ">= 0.8.0"
},
"devDependencies": {
"grunt-blanket-mocha": "~0.4.0",
"grunt": "0.4.1",
"mocha": "1.17.1",
"chai": "1.8.1",
"blanket": "1.1.5",
"requirejs": "2.1.10"
}
}
23 changes: 23 additions & 0 deletions example-requirejs/src/math/addition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
define([

], function(){

var addThree = function(addTo) {
return addTo + 3;
};

var addFive = function(addTo) {
return addTo + 5;
};

var addSeven = function(addTo) {
return addTo + 7;
};

return {
addThree: addThree,
addFive: addFive,
addSeven: addSeven
}

});
23 changes: 23 additions & 0 deletions example-requirejs/src/math/subtraction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
define([

], function(){

var subtractThree = function(subtractFrom) {
return subtractFrom - 3;
};

var subtractFive = function(subtractFrom) {
return subtractFrom - 5;
};

var subtractSeven = function(subtractFrom) {
return subtractFrom - 7;
};

return {
subtractThree: subtractThree,
subtractFive: subtractFive,
subtractSeven: subtractSeven
}

});
40 changes: 40 additions & 0 deletions example-requirejs/src/spelling/plurals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
define([

], function(){

var dog = function(howMany) {
var ret;
if (howMany < 0) {
ret = "0 dogs";
} else if (howMany === 1) {
ret = "1 dog";
} else {
ret = "" + howMany + " dogs";
}

return ret;
};

var cat = function(howMany) {
var ret;
if (howMany < 0) {
ret = "0 cats";
} else if (howMany === 1) {
ret = "1 cat";
} else {
ret = "" + howMany + " cats";
}

return ret;
};

var fish = function(howMany) {
return "" + howMany + " fish";
};

return {
cat: cat,
fish: fish
}

});
39 changes: 39 additions & 0 deletions example-requirejs/src/spelling/vowels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
define([

], function(){

var isVowel = function ( theLetter ) {

if ( !theLetter ) {
return false;
} else if ( theLetter.length > 1 ) {
return false;
}

theLetter = theLetter.toUpperCase();

switch(theLetter) {
case "A":
case "E":
case "I":
case "O":
case "U":
return true;
default:
return false;
}

};

var isNotVowel = function(theLetter) {

var isAVowel = isVowel(theLetter);

return ! isAVowel;
};

return {
isVowel: isVowel
}

});
39 changes: 39 additions & 0 deletions example-requirejs/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<html>
<head>
<meta charset="utf-8">
<title>Mocha Tests</title>
<link rel="stylesheet" href="node_modules/mocha/mocha.css" />

<script src="node_modules/mocha/mocha.js"></script>
<script src="node_modules/requirejs/require.js"></script>

<script type="text/javascript" src="node_modules/blanket/dist/qunit/blanket.js"
data-cover-flags="branchTracking"
data-cover-only="//src/"></script>

<script type="text/javascript" src="node_modules/grunt-blanket-mocha/support/mocha-blanket.js"></script>

<script>
mocha.setup('bdd');

if (window.PHANTOMJS) {
blanket.options("reporter", "node_modules/grunt-blanket-mocha/support/grunt-reporter.js"
);
}

//load main js first, this will load all the
//script dependencies
require(["main"], function(main) {
require(["test/test-loader"], function(TestLoader) {
//start running the mocha tests
TestLoader.start();
});
});

</script>
</head>
<body>
<div id="mocha"></div>

</body>
</html>
19 changes: 19 additions & 0 deletions example-requirejs/test/math/addition-specs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
define([
"src/math/addition"
], function(
Math
){

describe("Addition test", function() {

it("should add five to positive numbers", function() {
expect(Math.addFive(2)).to.equal(7);
});

it("should add seven to positive numbers", function() {
expect(Math.addSeven(2)).to.equal(9);
});

});

});
15 changes: 15 additions & 0 deletions example-requirejs/test/math/subtraction-specs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
define([
"src/math/subtraction"
], function(
Math
){

describe("Subtraction test", function() {

it("should subtract five from positive numbers", function() {
expect(Math.subtractFive(8)).to.equal(3);
});

});

});
Loading

0 comments on commit 253d452

Please sign in to comment.