1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/144c0473003e/ Changeset: 144c0473003e User: carlfeberhard Date: 2014-04-11 19:34:06 Summary: QA: allow grunt watch on qunit tests, add stubs for metrics-logger and hda-base Affected #: 9 files diff -r b7e3e7d7a62a724a3ffb0f04a05ceb0459630004 -r 144c0473003e87d747087b2f04814a7fb6282264 static/scripts/utils/metrics-logger.js --- a/static/scripts/utils/metrics-logger.js +++ b/static/scripts/utils/metrics-logger.js @@ -125,9 +125,11 @@ MetricsLogger.prototype._parseLevel = function _parseLevel( level ){ var type = typeof level; if( type === 'number' ){ return level; } - var upper = level.toUpperCase(); - if( type === 'string' && MetricsLogger.hasOwnProperty( upper ) ){ - return MetricsLogger[ upper ]; + if( type === 'string' ){ + var upper = level.toUpperCase(); + if( MetricsLogger.hasOwnProperty( upper ) ){ + return MetricsLogger[ upper ]; + } } throw new Error( 'Unknown log level: ' + level ); }; @@ -381,6 +383,7 @@ //============================================================================= return { - MetricsLogger : MetricsLogger + MetricsLogger : MetricsLogger, + LoggingCache : LoggingCache }; }); diff -r b7e3e7d7a62a724a3ffb0f04a05ceb0459630004 -r 144c0473003e87d747087b2f04814a7fb6282264 test/qunit/Gruntfile.js --- a/test/qunit/Gruntfile.js +++ b/test/qunit/Gruntfile.js @@ -1,17 +1,33 @@ -module.exports = function(grunt) { - grunt.initConfig({ - pkg: grunt.file.readJSON('package.json'), - - qunit: { - all: ['tests/**/*.html'], - options: { - } - }, +module.exports = function( grunt ){ + grunt.initConfig({ + pkg: grunt.file.readJSON( 'package.json' ), - }); + qunit: { + all: [ 'tests/**/*.html' ], + options: { + } + }, - grunt.loadNpmTasks('grunt-contrib-qunit'); - // register one or more task lists (you should ALWAYS have a "default" task list) - grunt.registerTask('default', ['qunit']); + watch: { + // watch for changes in the src dir + files: [ 'tests/**.js', '../../static/scripts/**/**.js' ], + tasks: [ 'default' ] + } + }); + + // use 'grunt --test=my-tests.html' or 'grunt watch --test=my-tests.html' + // to only run the tests in tests/my-tests.html + if( grunt.option( 'test' ) ){ + grunt.config.set( 'qunit.all', 'tests/' + grunt.option( 'test' ) ); + grunt.log.writeln( '(only testing ' + grunt.config.get( 'qunit.all' ) + ')' ); + } + + grunt.loadNpmTasks( 'grunt-contrib-qunit' ); + + // use 'grunt watch' to have the qunit tests run when scripts or tests are changed + grunt.loadNpmTasks( 'grunt-contrib-watch' ); + + // register one or more task lists (you should ALWAYS have a "default" task list) + grunt.registerTask( 'default', [ 'qunit' ] ); }; diff -r b7e3e7d7a62a724a3ffb0f04a05ceb0459630004 -r 144c0473003e87d747087b2f04814a7fb6282264 test/qunit/README.txt --- a/test/qunit/README.txt +++ b/test/qunit/README.txt @@ -6,6 +6,19 @@ % npm install % grunt +To watch for changes to scripts and tests and automatically re-run tests: + + % grunt watch + +You can limit the tests run to a single file using the test option (note: +that 'tests/' is prepended to the path): + + % grunt --test=metrics-logger.html + (only testing tests/metrics-logger.html) + + % grunt watch --test=metrics-logger.html + (only testing tests/metrics-logger.html) + From Web Browser (no additional dependencies): Just open test HTML file in Web Browser. diff -r b7e3e7d7a62a724a3ffb0f04a05ceb0459630004 -r 144c0473003e87d747087b2f04814a7fb6282264 test/qunit/package.json --- a/test/qunit/package.json +++ b/test/qunit/package.json @@ -2,6 +2,7 @@ "name": "galaxy-qunit-tests", "devDependencies": { "grunt": "^0.4.4", - "grunt-contrib-qunit": "^0.4.0" + "grunt-contrib-qunit": "^0.4.0", + "grunt-contrib-watch": "~0.5.3" } } diff -r b7e3e7d7a62a724a3ffb0f04a05ceb0459630004 -r 144c0473003e87d747087b2f04814a7fb6282264 test/qunit/test-common.js --- a/test/qunit/test-common.js +++ b/test/qunit/test-common.js @@ -13,7 +13,7 @@ // Custom paths for qunit testing dependencies... "QUnit": qunit_absolute_directory + "test-libs/qunit-1.14.0", // .. because baseUrl is scripts to match Galaxy. "sinon": qunit_absolute_directory + "test-libs/sinon-1.9.1", - "sinon-qunit": qunit_absolute_directory + "test-libs/sinon-qunit-1.0.0", + "sinon-qunit": qunit_absolute_directory + "test-libs/sinon-qunit-1.0.0" }, shim: { // Ensure correct Qunit order in light of requirejs loading... @@ -32,12 +32,12 @@ deps: [ 'sinon', "QUnit" ], exports: "sinon" // Odd but seems to work }, - "underscore": { - exports: "_" + "underscore": { + exports: "_" }, "backbone": { deps: [ 'underscore', 'jquery' ], - exports: "Backbone" + exports: "Backbone" } } } ); @@ -48,10 +48,10 @@ root: '/' }; - require( [ "jquery", "QUnit" ], function( $, QUnit ) { // Bootstrap HTML for displaying Qunit results. - $('head').append( $('<link rel="stylesheet" type="text/css" />').attr( "href", qunit_absolute_directory + "test-libs/qunit-1.14.0.css") ); + $('head').append( $('<link rel="stylesheet" type="text/css" />') + .attr( "href", qunit_absolute_directory + "test-libs/qunit-1.14.0.css") ); $('body').append( $('<div id="qunit">') ); $('body').append( $('<div id="qunit-fixture">') ); @@ -60,7 +60,6 @@ // underscore + backbone loaded here because they are assumed globals by // much of the Galaxy client code. require( [ "underscore", "backbone" ], function( _, Backbone ) { - require( [ test_module_path ], function( ) { QUnit.load(); QUnit.start(); diff -r b7e3e7d7a62a724a3ffb0f04a05ceb0459630004 -r 144c0473003e87d747087b2f04814a7fb6282264 test/qunit/tests/hda-base.html --- /dev/null +++ b/test/qunit/tests/hda-base.html @@ -0,0 +1,10 @@ +<!doctype html> +<!-- Minimal outline test page for a requirejs+qunit testing setup, + test environment is bootstrapped in test-common.js --> +<html> + <head> + <script data-main="../test-common" src="../scripts/libs/require.js"></script> + </head> + <body> + </body> +</html> diff -r b7e3e7d7a62a724a3ffb0f04a05ceb0459630004 -r 144c0473003e87d747087b2f04814a7fb6282264 test/qunit/tests/hda-base.js --- /dev/null +++ b/test/qunit/tests/hda-base.js @@ -0,0 +1,35 @@ +// This file isn't really testing anything useful yet, it is just testing +// (or demonstrating) qunit+backbone interactions. +define([ + "mvc/dataset/hda-model", + "mvc/dataset/hda-base", + "jquery", + "sinon-qunit", + "utils/localization" +], function( + hdaModel, + hdaBase, + $, + sinon +){ + /*globals equal test module expect deepEqual strictEqual */ + "use strict"; + + module( "HDA base backbone view tests" ); + + test( "Base HDA view default construction, initialize", function() { + var hda = new hdaModel.HistoryDatasetAssociation({ + id : '123' + }), + view = new hdaBase.HDABaseView({ model: hda }); + + strictEqual( view.model, hda ); + + equal( view.linkTarget, '_blank' ); + equal( view.selectable, false ); + equal( view.selected, false ); + equal( view.expanded, false ); + equal( view.draggable, false ); + equal( view.id(), 'hda-123' ); + }); +}); diff -r b7e3e7d7a62a724a3ffb0f04a05ceb0459630004 -r 144c0473003e87d747087b2f04814a7fb6282264 test/qunit/tests/metrics-logger.html --- /dev/null +++ b/test/qunit/tests/metrics-logger.html @@ -0,0 +1,10 @@ +<!doctype html> +<!-- Minimal outline test page for a requirejs+qunit testing setup, + test environment is bootstrapped in test-common.js --> +<html> + <head> + <script data-main="../test-common" src="../scripts/libs/require.js"></script> + </head> + <body> + </body> +</html> diff -r b7e3e7d7a62a724a3ffb0f04a05ceb0459630004 -r 144c0473003e87d747087b2f04814a7fb6282264 test/qunit/tests/metrics-logger.js --- /dev/null +++ b/test/qunit/tests/metrics-logger.js @@ -0,0 +1,56 @@ +// This file isn't really testing anything useful yet, it is just testing +// (or demonstrating) qunit+backbone interactions. +define([ + "utils/metrics-logger", + "jquery", + "sinon-qunit" +], function( + metrics, + $, + sinon +){ + /*globals equal test module expect deepEqual strictEqual throws */ + "use strict"; + + module( "Metrics logger tests" ); + + test( "logger construction/initializiation defaults", function() { + var logger = new metrics.MetricsLogger({}); + equal( logger.consoleLogger, null ); + equal( logger.options.logLevel, metrics.MetricsLogger.INFO ); + equal( logger.options.consoleLevel, metrics.MetricsLogger.NONE ); + equal( logger.options.defaultNamespace, 'Galaxy' ); + equal( logger.options.clientPrefix, 'client.' ); + equal( logger.options.postSize, 1000 ); + equal( logger.options.maxCacheSize, 3000 ); + equal( logger.options.addTime, true ); + + equal( logger._postSize, 1000 ); + equal( logger.cache.constructor, metrics.LoggingCache ); + }); + + test( "_parseLevel", function() { + var logger = new metrics.MetricsLogger({}); + equal( logger._parseLevel( 'all' ), metrics.MetricsLogger.ALL ); + equal( logger._parseLevel( 'debug' ), metrics.MetricsLogger.DEBUG ); + equal( logger._parseLevel( 'info' ), metrics.MetricsLogger.INFO ); + equal( logger._parseLevel( 'warn' ), metrics.MetricsLogger.WARN ); + equal( logger._parseLevel( 'error' ), metrics.MetricsLogger.ERROR ); + equal( logger._parseLevel( 'metric' ), metrics.MetricsLogger.METRIC ); + equal( logger._parseLevel( 'none' ), metrics.MetricsLogger.NONE ); + equal( logger._parseLevel( 15 ), 15 ); + + throws( function(){ + logger._parseLevel( undefined ); + }, /Unknown log level/, 'Unknown log level throws error' ); + throws( function(){ + logger._parseLevel( 'nope' ); + }, /Unknown log level/, 'Unknown log level throws error' ); + }); + + test( "cache construction/initializiation defaults", function() { + var cache = new metrics.LoggingCache(); + equal( cache.maxSize, 5000 ); + equal( $.type( cache._cache ), 'array' ); + }); +}); Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.