From 9471b4e09b18deced1a2d2979ab4a2a635a845e8 Mon Sep 17 00:00:00 2001 From: Outsider Date: Wed, 15 Jan 2014 21:26:57 +0900 Subject: [PATCH] add karma test --- Gruntfile.js | 9 +++- bower.json | 5 +- karma.conf.js | 68 ++++++++++++++++++++++++++ package.json | 17 +++++-- test/angular-summernote.test.js | 42 ++++++++++++++++ test/chai.conf.js | 6 +++ test/karma.conf.js | 86 +++++++++++++++++++++++++++++++++ test/mocha.conf.js | 3 ++ 8 files changed, 230 insertions(+), 6 deletions(-) create mode 100644 karma.conf.js create mode 100644 test/angular-summernote.test.js create mode 100644 test/chai.conf.js create mode 100644 test/karma.conf.js create mode 100644 test/mocha.conf.js diff --git a/Gruntfile.js b/Gruntfile.js index 5da379b..6219c72 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -21,7 +21,12 @@ module.exports = function(grunt) { } } }, - watch: {} + watch: {}, + karma: { + 'summernote': { + configFile: './test/karma.conf.js' + } + } }); // These plugins provide necessary tasks. @@ -31,6 +36,6 @@ module.exports = function(grunt) { // Default task. grunt.registerTask('default', []); - grunt.registerTask('test', []); + grunt.registerTask('test', ['karma:summernote']); grunt.registerTask('lint', ['jshint']); }; diff --git a/bower.json b/bower.json index cb08d97..2889bc2 100644 --- a/bower.json +++ b/bower.json @@ -10,5 +10,8 @@ "summernote": "~0.5.0", "angular": "~1.2.8" }, - "devDependencies": {} + "devDependencies": { + "chai": "~1.8.1", + "angular-mocks": "~1.2.8" + } } diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..ec5bbe8 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,68 @@ +// Karma configuration +// Generated on Wed Jan 15 2014 20:50:47 GMT+0900 (KST) + +module.exports = function(config) { + config.set({ + + // base path, that will be used to resolve files and exclude + basePath: '', + + + // frameworks to use + frameworks: ['mocha'], + + + // list of files / patterns to load in the browser + files: [ + '"test/**/*.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 (has to be installed with `npm install karma-opera-launcher`) + // - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`) + // - PhantomJS + // - IE (only Windows; has to be installed with `npm install karma-ie-launcher`) + browsers: ['Chrome'], + + + // 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 + }); +}; diff --git a/package.json b/package.json index 21689f1..a0d33fd 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,19 @@ "grunt": "~0.4.1", "grunt-contrib-jshint": "~0.7.2", "grunt-contrib-connect": "~0.5.0", - "grunt-contrib-watch": "~0.5.3" + "grunt-contrib-watch": "~0.5.3", + "mocha": "~1.17.0", + "karma-script-launcher": "~0.1.0", + "karma-chrome-launcher": "~0.1.2", + "karma-firefox-launcher": "~0.1.3", + "karma-html2js-preprocessor": "~0.1.0", + "requirejs": "~2.1.10", + "karma-requirejs": "~0.2.1", + "karma-coffee-preprocessor": "~0.1.2", + "karma-phantomjs-launcher": "~0.1.1", + "karma": "~0.10.9", + "karma-mocha": "~0.1.1", + "grunt-karma": "~0.6.2" }, - "dependencies": { - } + "dependencies": {} } diff --git a/test/angular-summernote.test.js b/test/angular-summernote.test.js new file mode 100644 index 0000000..8c13297 --- /dev/null +++ b/test/angular-summernote.test.js @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2013 JeongHoon Byun aka "Outsider", + * Licensed under the MIT license. + * + */ +describe('Summernote directive', function() { + 'use strict'; + + var $rootScope, $compile, element; + + beforeEach(module('summernote')); + beforeEach(inject(function(_$compile_, _$rootScope_) { + $compile = _$compile_; + $rootScope = _$rootScope_; + })); + + describe('initialization', function() { + + it('has "summernote" class', function () { + element = $compile('')($rootScope); + $rootScope.$digest(); + + expect($(element.get(0)).hasClass('summernote')).to.be.true; + }); + + it('works with "summernote" element', function () { + element = $compile('')($rootScope); + $rootScope.$digest(); + + expect(element.next().hasClass('note-editor')).to.be.true; + }); + + it('works with "summernote" attribute', function () { + element = $compile('
')($rootScope); + $rootScope.$digest(); + + expect(element.next().hasClass('note-editor')).to.be.true; + }); + + }); + +}); \ No newline at end of file diff --git a/test/chai.conf.js b/test/chai.conf.js new file mode 100644 index 0000000..2c21a7e --- /dev/null +++ b/test/chai.conf.js @@ -0,0 +1,6 @@ +/** + * Copyright (c) 2013 JeongHoon Byun aka "Outsider", + * Licensed under the MIT license. + * + */ +var expect = chai.expect; diff --git a/test/karma.conf.js b/test/karma.conf.js new file mode 100644 index 0000000..2b7bee8 --- /dev/null +++ b/test/karma.conf.js @@ -0,0 +1,86 @@ +// Karma configuration +// Generated on Sat Jan 04 2014 16:46:43 GMT+0900 (KST) + +module.exports = function(config) { + 'use strict'; + + config.set({ + + // base path, that will be used to resolve files and exclude + basePath: '', + + + // frameworks to use + frameworks: ['mocha'], + + + // list of files / patterns to load in the browser + files: [ + // dependencies + '../examples/components/jquery/jquery.js', + '../examples/components/angular/angular.js', + '../examples/components/bootstrap/dist/js/bootstrap.min.js', + '../examples/components/summernote/dist/summernote.min.js', + + // application code + '../src/**/*.js', + + // test dependencies + '../examples/components/angular-mocks/angular-mocks.js', + '../examples/components/chai/chai.js', + 'mocha.conf.js', + 'chai.conf.js', + + // test code + '*.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 (has to be installed with `npm install karma-opera-launcher`) + // - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`) + // - PhantomJS + // - IE (only Windows; has to be installed with `npm install karma-ie-launcher`) + browsers: ['Chrome'], + + + // 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 + }); +}; diff --git a/test/mocha.conf.js b/test/mocha.conf.js new file mode 100644 index 0000000..8e54912 --- /dev/null +++ b/test/mocha.conf.js @@ -0,0 +1,3 @@ +window.mocha.setup({ + timeout: 5000 +});