Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
Merge pull request #140 from kate2753/jasmine
Browse files Browse the repository at this point in the history
Use Jasmine for testing and istanbul template  for test coverage report
  • Loading branch information
timlindvall committed Jan 13, 2015
2 parents 728f4a0 + d42ef65 commit 143e9e9
Show file tree
Hide file tree
Showing 8 changed files with 319 additions and 521 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -2,3 +2,5 @@ node_modules
tmp
.idea
*.iml
_SpecRunner.html
.grunt
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -26,6 +26,6 @@ Hopscotch uses Grunt for build and testing. You need to have [`npm`](https://npm

Testing
=======
Hopscotch tests are written using the [Mocha testing framework](http://visionmedia.github.io/mocha/).
Hopscotch tests are written using the [Jasmine testing framework](http://jasmine.github.io/edge/introduction.html).
The tests can be run either in the browser or via the command line.
To run the tests in the browser, simply open up test/index.html. To run the tests in the command line, you can run `grunt test`.
107 changes: 95 additions & 12 deletions Gruntfile.js
Expand Up @@ -176,12 +176,66 @@ module.exports = function(grunt) {
]
}
},
mocha : {
test : {
src:['<%=paths.test%>/index.html'],
jasmine : {
testProd: {
src: '<%=paths.build%>/js/hopscotch.min.js',
options: {
log: true,
logErrors: true
keepRunner: false,
specs: ['<%=paths.test%>/js/*.js'],
vendor: [
'node_modules/jquery/dist/jquery.min.js',
'node_modules/sinon/pkg/sinon-1.9.1.js'
],
styles: [
'<%=paths.build%>/css/hopscotch.min.css'
]
}
},
testDev: {
src: '<%=paths.build%>/js/hopscotch.js',
options: {
keepRunner: false,
specs: ['<%=paths.test%>/js/*.js'],
vendor: [
'node_modules/jquery/dist/jquery.min.js',
'node_modules/sinon/pkg/sinon-1.9.1.js'
],
styles: [
'<%=paths.build%>/css/hopscotch.css'
]
}
},
coverage: {
src: '<%=paths.build%>/js/hopscotch.js',
options: {
keepRunner: false,
specs: ['<%=paths.test%>/js/*.js'],
vendor: [
'node_modules/jquery/dist/jquery.min.js',
'node_modules/sinon/pkg/sinon-1.9.1.js'
],
styles: [
'<%=paths.build%>/css/hopscotch.css'
],
template: require('grunt-template-jasmine-istanbul'),
templateOptions: {
coverage: '<%=paths.build%>/coverage/coverage.json',
report: '<%=paths.build%>/coverage',
thresholds: {
lines: 75,
statements: 75,
branches: 60,
functions: 80
}
}
}
}
},
connect: {
testServer: {
options: {
port: 3000,
keepalive: true
}
}
},
Expand All @@ -202,35 +256,64 @@ module.exports = function(grunt) {
commitFiles: ['-a'],
createTag: true
}
},
log: {
dev: {
options: {
message: "Open http://localhost:<%= connect.testServer.options.port %>/_SpecRunner.html in a browser\nCtrl + C to stop the server."
}
},
coverage: {
options: {
message: 'Open <%=jasmine.coverage.options.templateOptions.report%>/index.html in a browser to view the coverage.'
}
}
}
});

//external tasks
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-bump');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-jst');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-include-replace');
grunt.loadNpmTasks('grunt-mocha');
grunt.loadNpmTasks('grunt-bump');
grunt.loadNpmTasks('grunt-shell');

grunt.registerMultiTask('log', 'Print some messages', function() {
grunt.log.ok(this.data.options.message);
});

//grunt task aliases
grunt.registerTask(
'build',
'Build hopscotch for testing (jshint, minify js, process less to css)',
['jshint:lib', 'clean:build', 'copy:build', 'jst:compile', 'includereplace:jsSource', 'uglify:build', 'less']
);

grunt.registerTask(
'test',
'Build hopscotch and run unit tests',
['build','mocha']
['build','jasmine:testProd', 'jasmine:coverage']
);

grunt.registerTask (
'dev',
'Start test server to allow debugging unminified hopscotch code in a browser',
['build', 'jasmine:testDev:build', 'log:dev', 'connect:testServer']
);

grunt.registerTask(
'coverage',
'log:coverage',
['build', 'jasmine:coverage', 'log:coverage']);

//release tasks
grunt.registerTask(
'buildRelease',
Expand Down
19 changes: 10 additions & 9 deletions package.json
Expand Up @@ -21,20 +21,21 @@
},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-jshint": "~0.6.0",
"grunt-bump": "~0.0.13",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-compress": "~0.6.0",
"grunt-contrib-connect": "^0.9.0",
"grunt-contrib-copy": "~0.5.0",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-jasmine": "^0.8.1",
"grunt-contrib-jshint": "~0.6.0",
"grunt-contrib-jst": "~0.6.0",
"grunt-contrib-less": "~0.9.0",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-watch": "~0.5.1",
"grunt-contrib-compress": "~0.6.0",
"grunt-mocha": "~0.4.11",
"expect.js": "~0.2.0",
"jquery": "~2.1.0",
"grunt-bump": "~0.0.13",
"grunt-shell": "~0.3.1",
"grunt-contrib-jst": "~0.6.0",
"grunt-include-replace": "~1.2.0",
"grunt-shell": "~0.3.1",
"grunt-template-jasmine-istanbul": "^0.3.0",
"jquery": "~2.1.0",
"sinon": "~1.9.0"
}
}

0 comments on commit 143e9e9

Please sign in to comment.