diff --git a/.gitignore b/.gitignore index 0119b5cfe..3ccd17820 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ runtime/release/ runtime/ui_BrowserWindow.h web/config_local.py web/regression/test_config.json +node_modules/ diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 000000000..2f9849044 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,75 @@ +// Karma configuration +// Generated on Wed Mar 01 2017 14:19:28 GMT-0500 (EST) + +module.exports = function(config) { + config.set({ + + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '', + + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['jasmine', 'requirejs'], + + + // list of files / patterns to load in the browser + files: [ + {pattern: 'test/javascript/**/*.js', included: false}, + {pattern: 'web/pgadmin/static/vendor/**/*.js', included: false}, + {pattern: 'web/pgadmin/static/js/**/*.js', included: false}, + 'test/javascript/test-main.js' + ], + + + // list of files to exclude + exclude: [ + 'web/pgadmin/static/js/pgadmin.js', + 'web/pgadmin/static/vendor/**/*[Tt]est.js', + 'web/pgadmin/static/vendor/**/*[Ss]pec.js' + ], + + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + }, + + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + 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: false, + + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: ['PhantomJS'], + + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false, + + // Concurrency level + // how many browser should be started simultaneous + concurrency: Infinity + }) +} diff --git a/package.json b/package.json new file mode 100644 index 000000000..80e4e5ad6 --- /dev/null +++ b/package.json @@ -0,0 +1,10 @@ +{ + "devDependencies": { + "jasmine-core": "^2.5.2", + "karma": "^1.5.0", + "karma-jasmine": "^1.1.0", + "karma-phantomjs-launcher": "^1.0.2", + "karma-requirejs": "^1.1.0", + "requirejs": "^2.3.3" + } +} diff --git a/test/javascript/test-main.js b/test/javascript/test-main.js new file mode 100644 index 000000000..b0726a0d4 --- /dev/null +++ b/test/javascript/test-main.js @@ -0,0 +1,115 @@ +var allTestFiles = []; +var TEST_REGEXP = /(spec|test)\.js$/i; + +// Get a list of all the test files to include +Object.keys(window.__karma__.files).forEach(function (file) { + if (TEST_REGEXP.test(file)) { + // Normalize paths to RequireJS module names. + // If you require sub-dependencies of test files to be loaded as-is (requiring file extension) + // then do not normalize the paths + var normalizedTestModule = file.replace(/^\/base\/|\.js$/g, ''); + allTestFiles.push(normalizedTestModule) + } +}); + +var sourcesDir = '/base/web/pgadmin/static/'; +require.config({ + // Karma serves files under /base, which is the basePath from your config file + baseUrl: '/base', + + paths: { + 'alertify': sourcesDir + 'vendor/alertifyjs/alertify', + 'jquery': sourcesDir + 'vendor/jquery/jquery-1.11.2', + 'jquery.ui': sourcesDir + 'vendor/jquery-ui/jquery-ui-1.11.3', + 'jquery.event.drag': sourcesDir + 'vendor/jquery-ui/jquery.event.drag-2.2', + 'underscore': sourcesDir + 'vendor/underscore/underscore', + 'slickgrid': sourcesDir + 'vendor/slickgrid/slick.core', + 'slickgrid/slick.grid': sourcesDir + 'vendor/slickgrid/slick.grid', + 'slickgrid/slick.rowselectionmodel': sourcesDir + 'vendor/slickgrid/plugins/slick.rowselectionmodel', + 'translations': '/base/test/javascript/fake_translations', + 'sources': sourcesDir + 'js' + }, + + shim: { + 'underscore': { + exports: '_' + }, + "slickgrid": { + "deps": [ + 'jquery', "jquery.ui", "jquery.event.drag" + ], + "exports": 'window.Slick' + }, + "slickgrid/slick.grid": { + "deps": [ + 'jquery', "jquery.ui", "jquery.event.drag", "slickgrid" + ], + "exports": 'window.Slick.Grid' + }, + "slickgrid/slick.rowselectionmodel": { + "deps": [ + "jquery" + ], + "exports": 'window.Slick.RowSelectionModel' + }, + "backbone": { + "deps": ['underscore', 'jquery'], + "exports": 'Backbone' + }, + "backbone.paginator": { + "deps": ['underscore', 'jquery', 'backbone'] + }, + "bootstrap": { + "deps": ['jquery'], + }, + "backgrid": { + "deps": ['backform'], + "exports": 'Backgrid', + }, + "backgrid.select.all": { + "deps": ['backgrid'] + }, + "backgrid.paginator": { + "deps": ['backgrid', 'backbone.paginator'] + }, + "backgrid.filter": { + "deps": ['backgrid'] + }, + "backgrid.sizeable.columns": { + "deps": ['backgrid'] + }, + "bootstrap.switch": { + "deps": ['jquery', 'bootstrap'], + "exports": 'jQuery.fn.bootstrapSwitch' + }, + "select2": { + "deps": ['jquery'], + "exports": 'jQuery.fn.select2' + }, + "bootstrap.datepicker": { + "deps": ['jquery', 'bootstrap'], + "exports": 'jQuery.fn.datepicker' + }, + "bootstrap.datetimepicker": { + "deps": ['jquery', 'bootstrap', 'moment'], + "exports": 'jQuery.fn.datetimepicker' + }, + "pgadmin.backgrid": { + "deps": ["backgrid", "bootstrap.datetimepicker", "bootstrap.switch"], + }, + "pgadmin.backform": { + "deps": ['backform', "pgadmin.backgrid", "select2"], + }, + "jquery.event.drag": { + "deps": ['jquery'], "exports": 'jQuery.fn.drag' + }, + "jquery.ui": {"deps": ['jquery']} + }, + + // dynamically load all test files + deps: allTestFiles, + + // we have to kickoff jasmine, as it is asynchronous + callback: window.__karma__.start +}); + diff --git a/web/regression/README b/web/regression/README index 6a543cdb7..6e3723d5a 100644 --- a/web/regression/README +++ b/web/regression/README @@ -113,6 +113,8 @@ Test Data Details Execution: ----------- +Python Tests + - For feature tests to run as part of the entire test suite, Chrome and chromedriver need to be installed; get chromedriver from https://sites.google.com/a/chromium.org/chromedriver/downloads or a @@ -153,3 +155,17 @@ Execution: Example: exclude multiple packages: run 'python runtests.py --exclude browser.server_groups.servers.databases,browser.server_groups.servers.tablespaces' + +Javascript Tests + brew install nodejs + npm install + + you may wish to install the karma cli, so it is accessible globally: + npm install -g karma-cli + + Otherwise you can use: + ./node_modules/karma/bin/karma + + to run tests: + karma start --single-run +