Skip to content

Commit

Permalink
implemented build system, basic unit test support
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Rinck committed Sep 16, 2013
1 parent dd7e310 commit 35ff11b
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 2 deletions.
18 changes: 18 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"author": "Marco Rinck",
"name": "angular-onbeforeunload",
"description": "angular directive to handle window.onbeforeunload event in angularJS forms",
"version": "0.1.0",
"homepage": "https://github.com/marcorinck/angular-onbeforeunload",
"repository": {
"type": "git",
"url": "https://github.com/marcorinck/angular-onbeforeunload"
},
"main": "./build/angular-onbeforeunload",
"dependencies": {
"angular": "1.0.8"
},
"devDependencies": {
"angular-mocks": "1.0.8"
}
}
141 changes: 141 additions & 0 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
module.exports = function (grunt) {
"use strict";

grunt.initConfig({

pkg: grunt.file.readJSON('bower.json'),

language: grunt.option('lang') || 'en',

meta: {
banner: '/**\n * <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
' * <%= pkg.homepage %>\n' +
' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %>\n */\n'
},

build_dir: 'build',

lib_files: {

core: [
'src/onbeforeunload.js',
'src/onbeforeunloadDirective.js'
],

test: ['test/**/*.js']
},

watch: {

scripts: {
files: ['gruntfile.js', '<%= lib_files.core %>', '<%= lib_files.test %>'],
tasks: ['jshint:all', 'karma:unit']
},

livereload: {
options: {
livereload: true
},
files: ['src/**/*.js', 'demo/*'],
tasks: ['jshint', 'karma:unit', 'concat', 'copy:demo']
}
},

jshint: {

options: {
jshintrc: '.jshintrc'
},

all: ['gruntfile.js', '<%= lib_files.core %>', '<%= lib_files.test %>'],

core: {
files: {
src: ['<%= lib_files.core %>']
}
},

test: {
files: {
src: ['<%= lib_files.test %>']
}
}
},

concat: {
banner: {
options: {
banner: '<%= meta.banner %>'
},
src: '<%= concat.core.dest %>',
dest: '<%= concat.core.dest %>'
},

core: {
src: ['<%= lib_files.core %>'],
dest: '<%= build_dir %>/angular-onbeforeunload.js'
}
},

uglify: {
core: {
files: {
'<%= build_dir %>/angular-onbeforeunload.min.js': '<%= concat.core.dest %>'
}
}
},

copy: {
demo: {
files: [
{
src: 'angular-translate.js',
dest: 'demo/js/',
cwd: 'dist/',
expand: true
}
]
}
},

karma: {
unit: {
configFile: 'karma.conf.js',
singleRun: true
}
},

ngmin: {

core: {
src: '<%= concat.core.dest %>',
dest: '<%= concat.core.dest %>'
}
}
});


grunt.registerTask('default', ['jshint:all', 'karma']);
grunt.registerTask('test', ['karma']);

grunt.registerTask('build', [
'jshint:all',
'karma',
'build:core'
]);

grunt.registerTask('build:core', [
'jshint:core',
'concat:core',
'ngmin:core',
'concat:banner',
'uglify:core'
]);

// For development purpose.
grunt.registerTask('dev', ['jshint', 'karma:unit', 'concat', 'copy:demo', 'watch:livereload']);

require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
};
71 changes: 71 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Karma configuration
// Generated on Mon Sep 16 2013 12:55:41 GMT+0200 (W. Europe Daylight Time)

module.exports = function (config) {
config.set({

// base path, that will be used to resolve files and exclude
basePath: '',


// frameworks to use
frameworks: ['jasmine'],


// list of files / patterns to load in the browser
files: [
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'src/**/*.js',
'test/**/*.js'
],


// list of files to exclude
exclude: [

],


// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress'],


// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,


// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['PhantomJS'],


// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,


// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
});
};
28 changes: 28 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "angular-onbeforeunload",
"version": "0.1.0",
"description": "angular directive to handle window.onbeforeunload event in angularJS forms",
"keywords": ["angular", "angularJS", "onbeforeunload", "browser", "event", "window"],
"repository": {
"type": "git",
"url": "https://github.com/marcorinck/angular-growl"
},
"author": {
"name": "Marco Rinck"
},
"license": "MIT",
"devDependencies": {
"karma": "~0.10.x",
"grunt": "~0.4.1",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-concat": "~0.3.x",
"grunt-contrib-jshint": "~0.6.x",
"grunt-contrib-uglify": "~0.2.x",
"grunt-contrib-watch": "~0.5.x",
"grunt-bump": "0.0.2",
"grunt-karma": "~0.7.x",
"grunt-ngmin": "0.0.2",
"matchdep": "0.1.2"
}
}
4 changes: 2 additions & 2 deletions src/onbeforeunloadDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ angular.module("angular-onbeforeunload").directive("onbeforeunload", ["$window",
}
}

return function ($scope, $element, $attrs) {
return function ($scope, $element) {
if ($element[0].localName !== 'form') {
throw new Error("onbeforeunload directive must only be set on a angularjs form!");
}
Expand All @@ -36,7 +36,7 @@ angular.module("angular-onbeforeunload").directive("onbeforeunload", ["$window",
try {
unloadtext = $filter("translate")("onbeforeunload");
} catch (err) {
unloadtext = ""
unloadtext = "";
}
};
}]);
7 changes: 7 additions & 0 deletions test/OnbeforeunloadTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe("onbeforeunload", function() {
"use strict";

it("should be true", function() {
expect(true).toBe(true);
});
});

0 comments on commit 35ff11b

Please sign in to comment.