From 97fe898d8e3fdce3d3901370a5099c10d4ad1f56 Mon Sep 17 00:00:00 2001 From: Yolanda Robla Date: Mon, 16 Feb 2015 14:47:48 +0100 Subject: [PATCH] Initial proposal for integration tests Change-Id: I512b5c9474f80fd690fdea9d926d15b8146144e4 --- Gruntfile.js | 23 ++-- karma-integration.conf.js | 71 ------------ protractor-integration.conf.js | 107 +++++++++++++++++++ test/integration/services/module.js | 40 ------- test/integration/services/projects/module.js | 34 ++++++ 5 files changed, 154 insertions(+), 121 deletions(-) delete mode 100644 karma-integration.conf.js create mode 100644 protractor-integration.conf.js delete mode 100644 test/integration/services/module.js create mode 100644 test/integration/services/projects/module.js diff --git a/Gruntfile.js b/Gruntfile.js index 914e7b33..22769c3f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -389,6 +389,7 @@ module.exports = function (grunt) { server: { url: 'http://localhost:9000' } + }, /** @@ -508,9 +509,6 @@ module.exports = function (grunt) { karma: { unit: { configFile: './karma-unit.conf.js' - }, - integration: { - configFile: './karma-integration.conf.js' } }, @@ -543,8 +541,14 @@ module.exports = function (grunt) { args: { } }, - dist: {} + dist: {}, + integration: { + options: { + configFile: './protractor-integration.conf.js' + } + } } + }); /** @@ -617,7 +621,7 @@ module.exports = function (grunt) { ]); /** - * grunt test:integration + * grunt test:unit * * This command will create a clean build against which our unit * tests will be run. For more information, please see @@ -635,15 +639,14 @@ module.exports = function (grunt) { * grunt test:integration * * This command will create a clean build against which our integration - * tests will be run. For more information, please see - * karma-integration.conf.js + * tests will be run. */ grunt.registerTask('test:integration', [ 'clean', 'compile', - 'useminPrepare', - 'concat', - 'karma:integration' + 'configureProxies:test', + 'connect:test', + 'protractor:integration' ]); /** diff --git a/karma-integration.conf.js b/karma-integration.conf.js deleted file mode 100644 index e6b5f926..00000000 --- a/karma-integration.conf.js +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2013 Hewlett-Packard Development Company, L.P. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -module.exports = function (config) { - 'use strict'; - - config.set({ - - port: 9877, - - basePath: '', - - frameworks: ['jasmine'], - - plugins: [ - 'karma-coverage', - 'karma-jasmine', - 'karma-html-reporter', - 'karma-phantomjs-launcher', - 'karma-chrome-launcher', - 'karma-firefox-launcher' - ], - - files: [ - './dist/js/libs.js', - './bower_components/angular-mocks/angular-mocks.js', - './dist/js/storyboard.js', - './dist/js/templates.js', - './test/unit/**/*.js' - ], - - exclude: [ - ], - - singleRun: true, - - reporters: ['dots', 'progress', 'coverage', 'html'], - - colors: false, - - browsers: [ 'PhantomJS', 'Firefox' ], - - preprocessors: { - './dist/js/storyboard.js': ['coverage'] - }, - - coverageReporter: { - type: 'html', - dir: './cover/integration/' - }, - - htmlReporter: { - outputDir: './reports/integration', - templatePath: './node_modules' + - '/karma-html-reporter/jasmine_template.html' - } - }); -}; diff --git a/protractor-integration.conf.js b/protractor-integration.conf.js new file mode 100644 index 00000000..62a32dad --- /dev/null +++ b/protractor-integration.conf.js @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2013 Hewlett-Packard Development Company, L.P. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +// A reference configuration file. +exports.config = { + seleniumServerJar: './node_modules/selenium-standalone/' + + '.selenium/2.43.1/server.jar', + chromeDriver: './node_modules/selenium-standalone/' + + '.selenium/2.43.1/chromedriver', + + chromeOnly: false, + // Additional command line options to pass to selenium. For example, + // if you need to change the browser timeout, use + // seleniumArgs: ['-browserTimeout=60'], + seleniumArgs: [], + + // The timeout for each script run on the browser. This should be longer + // than the maximum time your application needs to stabilize between tasks. + allScriptsTimeout: 11000, + + // ----- What tests to run ----- + // + // Spec patterns are relative to the location of this config. + specs: [ + './test/integration/**/*.js' + ], + + // ----- Capabilities to be passed to the webdriver instance ---- + // + // For a full list of available capabilities, see + // https://code.google.com/p/selenium/wiki/DesiredCapabilities + capabilities: { + 'browserName': 'chrome', + 'chromeOptions': { + args: ['--test-type'] + } + }, + + // ----- More information for your tests ---- + // + // A base URL for your application under test. Calls to protractor.get() + // with relative paths will be prepended with this. + baseUrl: 'http://localhost:9005', + + // Selector for the element housing the angular app - this defaults to + // body, but is necessary if ng-app is on a descendant of + rootElement: 'html', + + // A callback function called once protractor is ready and available, and + // before the specs are executed + // You can specify a file containing code to run by setting onPrepare to + // the filename string. + onPrepare: function () { + 'use strict'; + // At this point, global 'protractor' object will be set up, and jasmine + // will be available. For example, you can add a Jasmine reporter with: + // jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter( + // 'outputdir/', true, true)); + }, + + // The params object will be passed directly to the protractor instance, + // and can be accessed from your test. It is an arbitrary object and can + // contain anything you may need in your test. + // This can be changed via the command line as: + // --params.login.user 'Joe' + params: { + hostname: 'http://localhost:9005/', + login: { + user: 'Jane', + password: '1234' + }, + buildUrl: function (fragment) { + 'use strict'; + + return this.hostname + '#!' + fragment; + } + }, + + // ----- Options to be passed to minijasminenode ----- + // + // See the full list at https://github.com/juliemr/minijasminenode + jasmineNodeOpts: { + // onComplete will be called just before the driver quits. + onComplete: null, + // If true, display spec names. + isVerbose: false, + // If true, print colors to the terminal. + showColors: false, + // If true, include stack traces in failures. + includeStackTrace: true, + // Default time to wait in ms before a test fails. + defaultTimeoutInterval: 30000 + } +}; diff --git a/test/integration/services/module.js b/test/integration/services/module.js deleted file mode 100644 index 4e2bcc22..00000000 --- a/test/integration/services/module.js +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2013 Hewlett-Packard Development Company, L.P. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -describe('sb.services', function () { - 'use strict'; - - var module; - var dependencies = []; - - var hasModule = function (moduleName) { - return dependencies.indexOf(moduleName) >= 0; - }; - - beforeEach(function () { - // Get module - module = angular.module('sb.services'); - dependencies = module.requires; - }); - - it('should exist', function () { - expect(module).toBeTruthy(); - }); - - it('should load cookies module', function () { - expect(hasModule('ngCookies')).toBeTruthy(); - }); -}); diff --git a/test/integration/services/projects/module.js b/test/integration/services/projects/module.js new file mode 100644 index 00000000..8535534a --- /dev/null +++ b/test/integration/services/projects/module.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015 Hewlett-Packard Development Company, L.P. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +var request = require('request'); +var protractor = require('protractor'); + +describe('projects integration tests', function () { + 'use strict'; + + it('should return empty projects list', function () { + browser.execute(function() { + var deferred = protractor.promise.defer(); + request.get('http://localhost:9005/api/v1/projects', + function(e, c, body) { + deferred.fulfill(body); + }); + return deferred.promise; + }).then(function(results) { + expect(results).toEqual('[]'); + }); + }); +});