From c57d3b5e5088b950ba724d9209b3e66fa68a469e Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Tue, 11 Sep 2012 22:32:46 -0700 Subject: [PATCH] switch over to using Testacular for E2E tests --- README.md | 11 +- config/jsTestDriver-scenario.conf | 10 -- config/jstd-scenario-adapter-config.js | 6 - config/testacular-e2e.conf.js | 18 +++ scripts/e2e-test-server.bat | 18 --- scripts/e2e-test-server.sh | 14 -- scripts/e2e-test.bat | 5 +- scripts/e2e-test.sh | 9 +- test/lib/angular/jstd-scenario-adapter.js | 185 ---------------------- 9 files changed, 33 insertions(+), 243 deletions(-) delete mode 100644 config/jsTestDriver-scenario.conf delete mode 100644 config/jstd-scenario-adapter-config.js create mode 100644 config/testacular-e2e.conf.js delete mode 100644 scripts/e2e-test-server.bat delete mode 100755 scripts/e2e-test-server.sh delete mode 100644 test/lib/angular/jstd-scenario-adapter.js diff --git a/README.md b/README.md index 1c98a2c..b3b50ab 100644 --- a/README.md +++ b/README.md @@ -85,11 +85,16 @@ you to write your tests with jasmine-like BDD syntax. Requires a webserver, node.js or your backend server that hosts the angular static files. -Check out the [end-to-end runner's documentation](http://goo.gl/e8n06) for more info. +Check out the +[end-to-end runner's documentation](http://docs.angularjs.org/guide/dev_guide.e2e-testing) for more +info. * create your end-to-end tests in `test/e2e/scenarios.js` * serve your project directory with your http/backend server or node.js + `scripts/web-server.js` -* open `http://localhost:port/test/e2e/runner.html` in your browser +* to run do one of: + * open `http://localhost:port/test/e2e/runner.html` in your browser + * run the tests from console with [Testacular](vojtajina.github.com/testacular) via + `scripts/e2e-test.sh` or `script/e2e-test.bat` ### Receiving updates from upstream @@ -125,6 +130,8 @@ fetch the changes and merge them into your project with git. logs/ --> JSTD and other logs go here (git-ignored) scripts/ --> handy shell/js/ruby scripts + e2e-test.sh --> runs end-to-end tests with Testacular (*nix) + e2e-test.bat --> runs end-to-end tests with Testacular (windows) test-server.bat --> starts JSTD server (windows) test-server.sh --> starts JSTD server (*nix) test.bat --> runs all unit tests (windows) diff --git a/config/jsTestDriver-scenario.conf b/config/jsTestDriver-scenario.conf deleted file mode 100644 index 3ebe650..0000000 --- a/config/jsTestDriver-scenario.conf +++ /dev/null @@ -1,10 +0,0 @@ -server: http://localhost:9877 - -load: - - test/lib/angular/angular-scenario.js - - config/jstd-scenario-adapter-config.js - - test/lib/angular/jstd-scenario-adapter.js - - test/e2e/scenarios.js - -proxy: - - {matcher: "*", server: "http://localhost:8000"} diff --git a/config/jstd-scenario-adapter-config.js b/config/jstd-scenario-adapter-config.js deleted file mode 100644 index 21eebc4..0000000 --- a/config/jstd-scenario-adapter-config.js +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Configuration for jstd scenario adapter - */ -var jstdScenarioAdapter = { - relativeUrlPrefix: '/test/e2e/' -}; diff --git a/config/testacular-e2e.conf.js b/config/testacular-e2e.conf.js new file mode 100644 index 0000000..a9d2cc3 --- /dev/null +++ b/config/testacular-e2e.conf.js @@ -0,0 +1,18 @@ +basePath = '../'; + +files = [ + ANGULAR_SCENARIO, + ANGULAR_SCENARIO_ADAPTER, + 'test/e2e/scenarios.js' +]; + +autoWatch = false; + +browsers = ['Chrome']; + +singleRun = true; + +proxies = { + '/': 'http://localhost:8000/' +}; + diff --git a/scripts/e2e-test-server.bat b/scripts/e2e-test-server.bat deleted file mode 100644 index f857b0d..0000000 --- a/scripts/e2e-test-server.bat +++ /dev/null @@ -1,18 +0,0 @@ -@echo off - -REM Windows script for starting JSTD server -REM -REM Requirements: -REM - Java (http://www.java.com) - -set BASE_DIR=%~dp0 -set PORT=9877 - -echo "Starting JsTestDriver Server (http://code.google.com/p/js-test-driver/)" -echo "Please open the following url and capture one or more browsers:" -echo "http://localhost:%PORT%" -java -jar "%BASE_DIR%\..\test\lib\jstestdriver\JsTestDriver.jar" ^ - --port %PORT% ^ - --browserTimeout 20000 ^ - --config "%BASE_DIR%\..\config\jsTestDriver-scenario.conf" ^ - --basePath "%BASE_DIR%\.." diff --git a/scripts/e2e-test-server.sh b/scripts/e2e-test-server.sh deleted file mode 100755 index 5a4e04c..0000000 --- a/scripts/e2e-test-server.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -BASE_DIR=`dirname $0` -PORT=9877 - -echo "Starting JsTestDriver Server (http://code.google.com/p/js-test-driver/)" -echo "Please open the following url and capture one or more browsers:" -echo "http://localhost:$PORT" - -java -jar "$BASE_DIR/../test/lib/jstestdriver/JsTestDriver.jar" \ - --port $PORT \ - --browserTimeout 20000 \ - --config "$BASE_DIR/../config/jsTestDriver-scenario.conf" \ - --basePath "$BASE_DIR/.." diff --git a/scripts/e2e-test.bat b/scripts/e2e-test.bat index f630363..c12943c 100644 --- a/scripts/e2e-test.bat +++ b/scripts/e2e-test.bat @@ -7,7 +7,4 @@ REM Requirements: REM - Java (http://www.java.com) set BASE_DIR=%~dp0 -java -jar "%BASE_DIR%\..\test\lib\jstestdriver\JsTestDriver.jar" ^ - --config "%BASE_DIR%\..\config\jsTestDriver-scenario.conf" ^ - --basePath "%BASE_DIR%\.." ^ - --tests all --reset +testacular start "%BASE_DIR%\..\config\testacular-e2e.conf.js" diff --git a/scripts/e2e-test.sh b/scripts/e2e-test.sh index 41211f7..e1c603b 100755 --- a/scripts/e2e-test.sh +++ b/scripts/e2e-test.sh @@ -2,7 +2,8 @@ BASE_DIR=`dirname $0` -java -jar "$BASE_DIR/../test/lib/jstestdriver/JsTestDriver.jar" \ - --config "$BASE_DIR/../config/jsTestDriver-scenario.conf" \ - --basePath "$BASE_DIR/.." \ - --tests all --reset +echo "" +echo "Starting Testacular Server (http://vojtajina.github.com/testacular)" +echo "-------------------------------------------------------------------" + +testacular start $BASE_DIR/../config/testacular-e2e.conf.js diff --git a/test/lib/angular/jstd-scenario-adapter.js b/test/lib/angular/jstd-scenario-adapter.js deleted file mode 100644 index 19d86ac..0000000 --- a/test/lib/angular/jstd-scenario-adapter.js +++ /dev/null @@ -1,185 +0,0 @@ -/** - * @license AngularJS v1.0.0rc1 - * (c) 2010-2011 AngularJS http://angularjs.org - * License: MIT - */ -(function(window) { -'use strict'; - -/** - * JSTestDriver adapter for angular scenario tests - * - * Example of jsTestDriver.conf for running scenario tests with JSTD: -
-    server: http://localhost:9877
-
-    load:
-      - lib/angular-scenario.js
-      - lib/jstd-scenario-adapter-config.js
-      - lib/jstd-scenario-adapter.js
-      # your test files go here #
-
-    proxy:
-     - {matcher: "/your-prefix/*", server: "http://localhost:8000/"}
-  
- * - * For more information on how to configure jstd proxy, see {@link http://code.google.com/p/js-test-driver/wiki/Proxy} - * Note the order of files - it's important ! - * - * Example of jstd-scenario-adapter-config.js -
-    var jstdScenarioAdapter = {
-      relativeUrlPrefix: '/your-prefix/'
-    };
-  
- * - * Whenever you use browser().navigateTo('relativeUrl') in your scenario test, the relativeUrlPrefix will be prepended. - * You have to configure this to work together with JSTD proxy. - * - * Let's assume you are using the above configuration (jsTestDriver.conf and jstd-scenario-adapter-config.js): - * Now, when you call browser().navigateTo('index.html') in your scenario test, the browser will open /your-prefix/index.html. - * That matches the proxy, so JSTD will proxy this request to http://localhost:8000/index.html. - */ - -/** - * Custom type of test case - * - * @const - * @see jstestdriver.TestCaseInfo - */ -var SCENARIO_TYPE = 'scenario'; - -/** - * Plugin for JSTestDriver - * Connection point between scenario's jstd output and jstestdriver. - * - * @see jstestdriver.PluginRegistrar - */ -function JstdPlugin() { - var nop = function() {}; - - this.reportResult = nop; - this.reportEnd = nop; - this.runScenario = nop; - - this.name = 'Angular Scenario Adapter'; - - /** - * Called for each JSTD TestCase - * - * Handles only SCENARIO_TYPE test cases. There should be only one fake TestCase. - * Runs all scenario tests (under one fake TestCase) and report all results to JSTD. - * - * @param {jstestdriver.TestRunConfiguration} configuration - * @param {Function} onTestDone - * @param {Function} onAllTestsComplete - * @returns {boolean} True if this type of test is handled by this plugin, false otherwise - */ - this.runTestConfiguration = function(configuration, onTestDone, onAllTestsComplete) { - if (configuration.getTestCaseInfo().getType() != SCENARIO_TYPE) return false; - - this.reportResult = onTestDone; - this.reportEnd = onAllTestsComplete; - this.runScenario(); - - return true; - }; - - this.getTestRunsConfigurationFor = function(testCaseInfos, expressions, testRunsConfiguration) { - testRunsConfiguration.push( - new jstestdriver.TestRunConfiguration( - new jstestdriver.TestCaseInfo( - 'Angular Scenario Tests', function() {}, SCENARIO_TYPE), [])); - - return true; - }; -} - -/** - * Singleton instance of the plugin - * Accessed using closure by: - * - jstd output (reports to this plugin) - * - initScenarioAdapter (register the plugin to jstd) - */ -var plugin = new JstdPlugin(); - -/** - * Initialise scenario jstd-adapter - * (only if jstestdriver is defined) - * - * @param {Object} jstestdriver Undefined when run from browser (without jstd) - * @param {Function} initScenarioAndRun Function that inits scenario and runs all the tests - * @param {Object=} config Configuration object, supported properties: - * - relativeUrlPrefix: prefix for all relative links when navigateTo() - */ -function initScenarioAdapter(jstestdriver, initScenarioAndRun, config) { - if (jstestdriver) { - // create and register ScenarioPlugin - jstestdriver.pluginRegistrar.register(plugin); - plugin.runScenario = initScenarioAndRun; - - /** - * HACK (angular.scenario.Application.navigateTo) - * - * We need to navigate to relative urls when running from browser (without JSTD), - * because we want to allow running scenario tests without creating its own virtual host. - * For example: http://angular.local/build/docs/docs-scenario.html - * - * On the other hand, when running with JSTD, we need to navigate to absolute urls, - * because of JSTD proxy. (proxy, because of same domain policy) - * - * So this hack is applied only if running with JSTD and change all relative urls to absolute. - */ - var appProto = angular.scenario.Application.prototype, - navigateTo = appProto.navigateTo, - relativeUrlPrefix = config && config.relativeUrlPrefix || '/'; - - appProto.navigateTo = function(url, loadFn, errorFn) { - if (url.charAt(0) != '/' && url.charAt(0) != '#' && - url != 'about:blank' && !url.match(/^https?/)) { - url = relativeUrlPrefix + url; - } - - return navigateTo.call(this, url, loadFn, errorFn); - }; - } -} - -/** - * Builds proper TestResult object from given model spec - * - * TODO(vojta) report error details - * - * @param {angular.scenario.ObjectModel.Spec} spec - * @returns {jstestdriver.TestResult} - */ -function createTestResultFromSpec(spec) { - var map = { - success: 'PASSED', - error: 'ERROR', - failure: 'FAILED' - }; - - return new jstestdriver.TestResult( - spec.fullDefinitionName, - spec.name, - jstestdriver.TestResult.RESULT[map[spec.status]], - spec.error || '', - spec.line || '', - spec.duration); -} - -/** - * Generates JSTD output (jstestdriver.TestResult) - */ -angular.scenario.output('jstd', function(context, runner, model) { - model.on('SpecEnd', function(spec) { - plugin.reportResult(createTestResultFromSpec(spec)); - }); - - model.on('RunnerEnd', function() { - plugin.reportEnd(); - }); -}); -initScenarioAdapter(window.jstestdriver, angular.scenario.setUpAndRun, window.jstdScenarioAdapter); -})(window); -- 2.20.1