Skip to content

Commit

Permalink
Added Grunt support for running Jasmine test cases.
Browse files Browse the repository at this point in the history
- Added grunt modules to run jasmine test cases via build process
- Added test server (run npm run start)
  • Loading branch information
purtuga committed Apr 5, 2015
1 parent 1ca74b7 commit de8670d
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 37 deletions.
32 changes: 30 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ module.exports = function(grunt) {
},
test : {
files : '<%= jshint.test.src %>',
tasks : ['jshint:test']
tasks : ['jshint:test', 'test']
},
},

Expand Down Expand Up @@ -578,7 +578,31 @@ module.exports = function(grunt) {

} // end: requirejs:compile

} //end: requirejs
}, //end: requirejs

connect: {
test: {
options: {
port: 8182
}
}
},
jasmine: {
all: {
options: {
specs: "test/specs/**/*.js",
host: "http://127.0.0.1:8182/",
template: require('grunt-template-jasmine-requirejs'),
templateOptions: {
requireConfigFile: "test/setup/requirejs.config.js",
requireConfig: {
baseUrl: "./"
}
}

}
}
}

}); //end: config()

Expand All @@ -590,6 +614,8 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-jsdoc');
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.loadNpmTasks('grunt-contrib-connect');

/**
* Default TASK
Expand All @@ -609,6 +635,7 @@ module.exports = function(grunt) {

grunt.task.run([
"jshint",
"test",
"clean:build",
"copy:build"
]);
Expand All @@ -634,5 +661,6 @@ module.exports = function(grunt) {
*/
grunt.registerTask('deploy', ["copy:deploy"]);

grunt.registerTask('test', ["connect:test", "jasmine"]);

}; //end: module.exports
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "SharePoint widgets and tools for custom client side web solutions",
"main": "dist/jquery.SPWidgets.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"server": "node tools/server.js"
"test": "grunt test",
"start": "node tools/server.js"
},
"repository": {
"type": "git",
Expand All @@ -18,17 +18,19 @@
"license": "MIT",
"devDependencies": {
"amdclean": "https://github.com/purtuga/amdclean/archive/master.tar.gz",
"connect": "^3.3.5",
"csso": "^1.3.11",
"grunt": "~0.4.1",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-connect": "^0.10.1",
"grunt-contrib-copy": "^0.7.0",
"grunt-contrib-jasmine": "^0.8.2",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-requirejs": "^0.4.4",
"grunt-contrib-uglify": "^0.7.0",
"grunt-contrib-watch": "~0.4.0",
"grunt-jsdoc": "~0.5.4",
"grunt-template-jasmine-requirejs": "^0.2.2",
"html-minifier": "^0.6.9",
"less": "^1.7.5",
"open": "0.0.5",
Expand Down
2 changes: 1 addition & 1 deletion src/dateFieldWidget/dateField.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ define([
'../sputils/parseDateString',
'../uiutils/makeSameHeight',
//--------------------------------
'less!./dateField.less'
'less!./dateField'
], function(
$,
dateFieldTemplate,
Expand Down
32 changes: 2 additions & 30 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,10 @@
</head>
<body>
<script type="text/javascript" src="../vendor/requirejs/require.js"></script>
<script type="text/javascript" src="setup/requirejs.config.js"></script>
<script type="text/javascript">

(function(){
var require = requirejs.config({
baseUrl: "../",
urlArgs: '@BUILD',
paths: {
jquery : 'vendor/jquery/dist/jquery',
'jquery-ui' : 'vendor/jquery-ui/jquery-ui',
less : 'vendor/require-less/less',
lessc : 'vendor/require-less/lessc',
normalize : 'vendor/require-less/normalize',
text : 'vendor/requirejs-text/text'
},
shim: {
'jquery-ui': {
deps: ['jquery']
},
'SPWidgets': {
deps: ['jquery', 'jquery-ui']
}
},
less: {
relativeUrls: true
}
});

require([
'require',
Expand All @@ -51,13 +29,7 @@
'jquery-ui',
"src/SPWidgets"
], function(require){
require([
// List all test case files below
"./test/test.SPWidgets"

], function(){
window.runTests();
});
require(["./test/suite"], function(){ window.runTests(); });
});

}());
Expand Down
24 changes: 24 additions & 0 deletions test/setup/requirejs.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require.config({
baseUrl: "../",
urlArgs: '@BUILD',
paths: {
jquery : 'vendor/jquery/dist/jquery',
'jquery-ui' : 'vendor/jquery-ui/jquery-ui',
less : 'vendor/require-less/less',
lessc : 'vendor/require-less/lessc',
normalize : 'vendor/require-less/normalize',
text : 'vendor/requirejs-text/text'
},
shim: {
'jquery-ui': {
deps: ['jquery']
},
'SPWidgets': {
deps: ['jquery', 'jquery-ui']
}
},
less: {
relativeUrls: true,
logLevel : 2
}
});
File renamed without changes.
6 changes: 6 additions & 0 deletions test/suite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
define([
// All test cases should resize in the test/specs folder and be
// referenced below as a dependency.
"./specs/jquery.SPWidgets"

], function(){});
2 changes: 1 addition & 1 deletion tools/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var connect = require('connect');
var connect = require('../node_modules/grunt-contrib-connect/node_modules/connect');
var serveStatic = require('serve-static');
var path = require("path");
var open = require("open");
Expand Down

0 comments on commit de8670d

Please sign in to comment.