Skip to content

Commit

Permalink
update test suit
Browse files Browse the repository at this point in the history
  • Loading branch information
Stereobit committed Mar 17, 2014
1 parent 6668311 commit 2566f7a
Show file tree
Hide file tree
Showing 17 changed files with 4,299 additions and 262 deletions.
6 changes: 3 additions & 3 deletions dist/dragend-0.2.0_rc3.js
Expand Up @@ -927,9 +927,9 @@
}

if ( typeof define == 'function' && typeof define.amd == 'object' && define.amd ) {
define( ["jquery", "hammer"], function( jquery, hammer ) {
return init( jquery, hammer );
} );
define(function() {
return init( window.jQuery || window.Zepto, window.Hammer );
});
} else {
window.Dragend = init( window.jQuery || window.Zepto, window.Hammer );
}
Expand Down
36 changes: 18 additions & 18 deletions dist/dragend-0.2.0_rc3.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dragend.js
Expand Up @@ -927,9 +927,9 @@
}

if ( typeof define == 'function' && typeof define.amd == 'object' && define.amd ) {
define( ["jquery", "hammer"], function( jquery, hammer ) {
return init( jquery, hammer );
} );
define(function() {
return init( window.jQuery || window.Zepto, window.Hammer );
});
} else {
window.Dragend = init( window.jQuery || window.Zepto, window.Hammer );
}
Expand Down
134 changes: 134 additions & 0 deletions gruntfile.js
@@ -0,0 +1,134 @@
module.exports = function (grunt) {

var istanbul = require('istanbul');

grunt.loadNpmTasks('grunt-mocha');

grunt.initConfig({

mocha: {
test: {
src: 'test/index.html',
options: {
reporter: 'Spec',
run: false,
log: true
}
}
},

test: {
options: {
template: 'test/index.template.html',
runner: 'test/index.html',
files: 'test/spec/**/*'
}
},

coverage: {

// when the coverage object is received
// from grunt-mocha it will be saved here
coverage: null,

instrument: {

// files to NOT instrument eg. libs
// these files will be copied "as is"
ignore: [
'src/js/lib/**/*'
],

// files to instrument
files: [
{
src: '**/*.js',
expand: true,
cwd: 'dist',
dest: 'test/src'
}
]
},

// task for generating reports
report: {
reports: ['html', 'text-summary'],
dest: 'test/reports'
}
}

});

grunt.event.on('coverage', function (coverage) {
grunt.config('coverage.coverage', coverage);
});

grunt.registerMultiTask('coverage', 'Generates coverage reports for JS using Istanbul', function () {

if (this.target === 'instrument') {

var ignore = this.data.ignore || [];
var instrumenter = new istanbul.Instrumenter();

this.files.forEach(function (file) {

var src = file.src[0],
instrumented = grunt.file.read(src);

// only instrument this file if it is not in ignored list
if (!grunt.file.isMatch(ignore, src)) {
instrumented = instrumenter.instrumentSync(instrumented, src);
}

// write
grunt.file.write(file.dest, instrumented);
});

return;
}

if (this.target === 'report') {

this.requiresConfig('coverage.coverage');

var Report = istanbul.Report;
var Collector = istanbul.Collector;
var reporters = this.data.reports;
var dest = this.data.dest;
var collector = new Collector();

// fetch the coverage object we saved earlier
collector.add(grunt.config('coverage.coverage'));

reporters.forEach(function (reporter) {

Report.create(reporter, {
dir: dest + '/' + reporter
}).writeReport(collector, true);

});

return;
}

grunt.warn('Unknown target - valid targets are "instrument" and "report"');
});

grunt.registerTask('test', 'Run JS Unit tests', function () {

var options = this.options();

var tests = grunt.file.expand(options.files).map(function(file) {
return '../' + file;
});

// build the template
var template = grunt.file.read(options.template)
.replace('{{ tests }}', JSON.stringify(tests));

// write template to tests directory and run tests
grunt.file.write(options.runner, template);
grunt.task.run('coverage:instrument', 'mocha', 'coverage:report');
});

};
12 changes: 7 additions & 5 deletions package.json
Expand Up @@ -41,10 +41,12 @@
"hammerjs": "~1.0.5",
"js-beautify": "~1.4.2",
"mocha": "~1.17.1",
"istanbul": "~0.2.4"
"istanbul": "~0.2.4",
"sinon": "~1.8.2",
"grunt-mocha": "git://github.com/jonbretman/grunt-mocha",
"requirejs": "~2.1.11"
},
"scripts": {
"test": "mocha"
},
"license": "MIT"
}
"test": "grunt test"
}
}
33 changes: 33 additions & 0 deletions test/index.html
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Mocha</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/expect.js/index.js"></script>
<script src="../node_modules/sinon/pkg/sinon.js"></script>
<script src="../node_modules/requirejs/require.js"></script>
</head>
<body>

<div id="mocha"></div>

<script>

mocha.setup('bdd');

require.config({

baseUrl: 'src',

deps: ["../test/spec/test.js"],

callback: mocha.run

});

</script>

</body>
</html>
33 changes: 33 additions & 0 deletions test/index.template.html
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Mocha</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/expect.js/index.js"></script>
<script src="../node_modules/sinon/pkg/sinon.js"></script>
<script src="../node_modules/requirejs/require.js"></script>
</head>
<body>

<div id="mocha"></div>

<script>

mocha.setup('bdd');

require.config({

baseUrl: 'src',

deps: {{ tests }},

callback: mocha.run

});

</script>

</body>
</html>

0 comments on commit 2566f7a

Please sign in to comment.