From 6eaa0295bd74f4df034392028a620bd4323e69d1 Mon Sep 17 00:00:00 2001 From: Nelson Omuto Date: Fri, 3 Oct 2014 15:15:31 -0400 Subject: [PATCH] adding unit testing hooks, connect server, jshint, watch tasks and livereload --- Gruntfile.js | 108 ++++++++++++++++++++++++++++++++++++++++++- package.json | 5 ++ test/.jshintrc | 44 ++++++++++++++++++ test/SpecRunner.html | 26 +++++++++++ test/materialSpec.js | 8 ++++ test/ripplesSpec.js | 0 6 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 test/.jshintrc create mode 100644 test/SpecRunner.html create mode 100644 test/materialSpec.js create mode 100644 test/ripplesSpec.js diff --git a/Gruntfile.js b/Gruntfile.js index ea89eadc..520689a8 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,8 +1,7 @@ module.exports = function(grunt) { - "use strict"; - require('load-grunt-tasks')(grunt); + require("load-grunt-tasks")(grunt); grunt.initConfig({ @@ -62,10 +61,115 @@ module.exports = function(grunt) { dest: "template/material/" } + }, + + connect: { + options: { + port: 8040, + hostname: "localhost", + livereload: 35740, + keepalive: true + + }, + livereload: { + options: { + open: true, + base: "." + } + }, + test: { + options: { + port: 8041, + open: 'http://localhost:8041/SpecRunner.html', + base: [ + "scripts", + "test" + ] + } + } + }, + + jasmine: { + src: 'scripts/**/*.js', + options: { + specs: 'test/*Spec.js', + helpers: 'test/*Helper.js', + vendor: [ + 'https://code.jquery.com/jquery-1.10.2.min.js', + 'https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js' + ] + } + }, + + jshint: { + options: { + jshintrc: ".jshintrc", + reporter: require("jshint-stylish") + }, + all: [ + "Gruntfile.js", + "scripts/**/*.js", + "template/**/*.js", + "test/**/*.js" + ], + test: { + options: { + jshintrc: "test/.jshintrc", + src: ["test/**/*.js"] + } + } + }, + + watch: { + js: { + files: ["Gruntfile.js", "scripts/**/*.js", "template/**/*.js"], + tasks: ["newer:jshint:all"] + }, + jsTest: { + files: ["test/**/*.js"], + tasks: ["newer:jshint:test", "jasmine"] + }, + livereload: { + options: { + livereload: "<%= connect.options.livereload %>" + }, + files: [ + 'index.html', + 'css-compiled/**/*.css', + '**/*.{png,jpg,jpeg,gif,webp,svg}' + ] + } } }); grunt.registerTask("default", ["less", "autoprefixer", "cssmin", "copy"]); + grunt.registerTask("scss", ["sass", "autoprefixer", "cssmin", "copy"]); + + grunt.registerTask("build", function(target) { + var buildType = "default"; + if (target && target === "scss") { + buildType = "scss"; + } + + grunt.task.run(["newer:jshint", "test", buildType]); + }); + + grunt.registerTask("test", [ + "connect:test", + "jasmine" + ]); + + grunt.registerTask("serve", function(target){ + var buildTarget = "default"; + if(target && target === "scss") { + buildTarget = "scss"; + } + grunt.task.run([ + "build:"+ buildTarget, + "connect:livereload", + "watch" + ]) + }); }; diff --git a/package.json b/package.json index 5e1cf315..f5f6cd74 100644 --- a/package.json +++ b/package.json @@ -19,10 +19,15 @@ "devDependencies": { "grunt": "^0.4.5", "grunt-autoprefixer": "^1.0.1", + "grunt-contrib-connect": "^0.8.0", "grunt-contrib-copy": "^0.6.0", "grunt-contrib-cssmin": "^0.10.0", + "grunt-contrib-jasmine": "^0.8.0", + "grunt-contrib-jshint": "^0.10.0", "grunt-contrib-less": "^0.11.4", "grunt-contrib-sass": "^0.8.1", + "grunt-contrib-watch": "^0.6.1", + "jshint-stylish": "^1.0.0", "load-grunt-tasks": "^0.6.0" } } diff --git a/test/.jshintrc b/test/.jshintrc new file mode 100644 index 00000000..ed5c1950 --- /dev/null +++ b/test/.jshintrc @@ -0,0 +1,44 @@ +{ + "bitwise": true, + "camelcase": true, + "curly": true, + "eqeqeq": false, + "es3": false, + "forin": true, + "freeze": false, + "immed": true, + "indent": 4, + "latedef": true, + "newcap": true, + "noarg": true, + "noempty": true, + "nonbsp": true, + "nonew": true, + "plusplus": false, + "quotmark": "double", + "undef": true, + "unused": true, + "strict": false, + "trailing": true, + "maxparams": 5, + "maxdepth": 5, + "maxstatements": 50, + "maxlen": 150, + + "eqnull": true, + + "browser": false, + "devel": false, + "node": true, + + "white": true, + + "globals": { + "$": true, + "document": true, + "brackets": true, + "define": true, + "Mustache": true, + "window": true + } +} diff --git a/test/SpecRunner.html b/test/SpecRunner.html new file mode 100644 index 00000000..a5ff35bd --- /dev/null +++ b/test/SpecRunner.html @@ -0,0 +1,26 @@ + + + + + Unit Tests Bootstrap Material Design + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/materialSpec.js b/test/materialSpec.js new file mode 100644 index 00000000..79cc45ec --- /dev/null +++ b/test/materialSpec.js @@ -0,0 +1,8 @@ +'use strict'; + +describe('Material', function (){ + + it('jquery should be loaded', function () { + expect($).toBeDefined(); + }); +}); \ No newline at end of file diff --git a/test/ripplesSpec.js b/test/ripplesSpec.js new file mode 100644 index 00000000..e69de29b