diff --git a/DEVELOPER.md b/DEVELOPER.md index 851704fd5e..5c9f3b1574 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -95,23 +95,22 @@ Next, install the modules and packages needed to build Angular and run tests: ```shell # Install Angular project dependencies (package.json) npm install - -# Ensure protractor has the latest webdriver -$(npm bin)/webdriver-manager update - -# Install Dart packages -pub get ``` **Optional**: In this document, we make use of project local `npm` package scripts and binaries (stored under `./node_modules/.bin`) by prefixing these command invocations with `$(npm bin)`; in -particular `gulp` and `protractor` commands. If you prefer, you can drop this path prefix by -globally installing these two packages as follows: +particular `gulp` and `protractor` commands. If you prefer, you can drop this path prefix by either: + +*Option 1*: globally installing these two packages as follows: * `npm install -g gulp` (you might need to prefix this command with `sudo`) * `npm install -g protractor` (you might need to prefix this command with `sudo`) -Since global installs can become stale, we avoid their use in these instructions. +Since global installs can become stale, and required versions can vary by project, we avoid their +use in these instructions. + +*Option 2*: defining a bash alias like `alias nbin='PATH=$(npm bin):$PATH'` as detailed in this +[Stackoverflow answer](http://stackoverflow.com/questions/9679932/how-to-use-package-installed-locally-in-node-modules/15157360#15157360) and used like this: e.g., `nbin gulp build`. ## Build commands @@ -133,22 +132,35 @@ $(npm bin)/gulp clean ## Running Tests Locally -### Basic tests +### Full test suite -1. `$(npm bin)/gulp test.unit.js`: JS tests in a browser; runs in **watch mode** (i.e. karma - watches the test files for changes and re-runs tests when files are updated). -2. `$(npm bin)/gulp test.unit.cjs`: JS tests in NodeJS; runs in **watch mode** -3. `$(npm bin)/gulp test.unit.dart`: Dart tests in Dartium; runs in **watch mode**. +* `npm test`: full test suite for both JS and Dart versions of Angular. These are the same tests as + those run on Travis. + +You can selectively run either the JS or Dart versions as follows: + +* `$(npm bin)/gulp test.all.js` +* `$(npm bin)/gulp test.all.dart` + +### Unit tests + +You can run just the unit tests as follows: + +* `$(npm bin)/gulp test.unit.js`: JS tests in a browser; runs in **watch mode** (i.e. karma + watches the test files for changes and re-runs tests when files are updated). +* `$(npm bin)/gulp test.unit.cjs`: JS tests in NodeJS; runs in **watch mode**. +* `$(npm bin)/gulp test.unit.dart`: Dart tests in Dartium; runs in **watch mode**. If you prefer running tests in "single-run" mode rather than watch mode use * `$(npm bin)/gulp test.unit.js/ci` +* `$(npm bin)/gulp test.unit.cjs/ci` * `$(npm bin)/gulp test.unit.dart/ci` -**Note**: If you want to only run a single test you can alter the test you wish -to run by changing `it` to `iit` or `describe` to `ddescribe`. This will only -run that individual test and make it much easier to debug. `xit` and `xdescribe` -can also be useful to exclude a test and a group of tests respectively. +**Note**: If you want to only run a single test you can alter the test you wish to run by changing +`it` to `iit` or `describe` to `ddescribe`. This will only run that individual test and make it +much easier to debug. `xit` and `xdescribe` can also be useful to exclude a test and a group of +tests respectively. **Note** for transpiler tests: The karma preprocessor is setup in a way so that after every test run the transpiler is reloaded. With that it is possible to make changes to the preprocessor and @@ -232,4 +244,3 @@ on the `debugger;` statement. You can then step into the code and add watches. The `debugger;` statement is needed because WebStorm will stop in a transpiled file. Breakpoints in the original source files are not supported at the moment. - diff --git a/gulpfile.js b/gulpfile.js index 5c1810ca0f..54a452500d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,5 +1,6 @@ var gulp = require('gulp'); var gulpPlugins = require('gulp-load-plugins')(); +var shell = require('gulp-shell'); var runSequence = require('run-sequence'); var madge = require('madge'); var merge = require('merge'); @@ -26,6 +27,7 @@ var runServerDartTests = require('./tools/build/run_server_dart_tests'); var transformCJSTests = require('./tools/build/transformCJSTests'); var util = require('./tools/build/util'); +// Note: when DART_SDK is not found, all gulp tasks ending with `.dart` will be skipped. var DART_SDK = require('./tools/build/dartdetect')(gulp); // ----------------------- // configuration @@ -431,7 +433,11 @@ gulp.task('build/multicopy.dart', copy.multicopy(gulp, gulpPlugins, { // ------------ // pubspec -gulp.task('build/pubspec.dart', pubget(gulp, gulpPlugins, { +// Run a top-level `pub get` for this project. +gulp.task('pubget.dart', pubget.dir(gulp, gulpPlugins, { dir: '.', command: DART_SDK.PUB })); + +// Run `pub get` over CONFIG.dest.dart +gulp.task('build/pubspec.dart', pubget.subDir(gulp, gulpPlugins, { dir: CONFIG.dest.dart, command: DART_SDK.PUB })); @@ -588,6 +594,22 @@ createDocsTasks(true); createDocsTasks(false); // ------------------ +// CI tests suites + +gulp.task('test.js', function(done) { + runSequence('test.transpiler.unittest', 'docs/test', 'test.unit.js/ci', + 'test.unit.cjs/ci', done); +}); + +gulp.task('test.dart', function(done) { + runSequence('test.transpiler.unittest', 'docs/test', 'test.unit.dart/ci', done); +}); + +// Reuse the Travis scripts +// TODO: rename test_*.sh to test_all_*.sh +gulp.task('test.all.js', shell.task(['./scripts/ci/test_js.sh'])) +gulp.task('test.all.dart', shell.task(['./scripts/ci/test_dart.sh'])) + // karma tests // These tests run in the browser and are allowed to access // HTML DOM APIs. diff --git a/package.json b/package.json index 8ff50024c9..c879ede3f4 100644 --- a/package.json +++ b/package.json @@ -20,10 +20,8 @@ "url": "https://github.com/angular/angular.git" }, "scripts": { - "test": "npm run test-js && npm run test-dart", - "test-js": "./scripts/ci/test_js.sh", - "test-dart": "./scripts/ci/test_dart.sh", - "postinstall": "./node_modules/.bin/bower install" + "postinstall": "webdriver-manager update && bower install && gulp pubget.dart", + "test": "gulp test.all.js && gulp test.all.dart" }, "dependencies": { "es6-module-loader": "^0.9.2", diff --git a/scripts/ci/env_dart.sh b/scripts/ci/env_dart.sh index 2e20033502..4b0e69c1a1 100755 --- a/scripts/ci/env_dart.sh +++ b/scripts/ci/env_dart.sh @@ -1,4 +1,4 @@ -#!/bin/false +#!/bin/bash set -e -o pipefail if [[ -z $ENV_SET ]]; then @@ -95,4 +95,4 @@ if [[ -z $ENV_SET ]]; then echo NGDART_SCRIPT_DIR=$NGDART_SCRIPT_DIR $DART --version 2>&1 -fi \ No newline at end of file +fi diff --git a/scripts/ci/test_dart.sh b/scripts/ci/test_dart.sh index bc481d60e6..29a4ced4e3 100755 --- a/scripts/ci/test_dart.sh +++ b/scripts/ci/test_dart.sh @@ -4,8 +4,9 @@ set -e echo ============================================================================= # go to project dir SCRIPT_DIR=$(dirname $0) +source $SCRIPT_DIR/env_dart.sh cd $SCRIPT_DIR/../.. -${SCRIPT_DIR}/test_unit_dart.sh +./node_modules/.bin/gulp test.js --browsers=$KARMA_BROWSERS ${SCRIPT_DIR}/test_server_dart.sh ${SCRIPT_DIR}/test_e2e_dart.sh diff --git a/scripts/ci/test_e2e_dart.sh b/scripts/ci/test_e2e_dart.sh index 4d7e97ef8f..a13edd25cb 100755 --- a/scripts/ci/test_e2e_dart.sh +++ b/scripts/ci/test_e2e_dart.sh @@ -4,7 +4,6 @@ set -e echo ============================================================================= # go to project dir SCRIPT_DIR=$(dirname $0) -source $SCRIPT_DIR/env_dart.sh cd $SCRIPT_DIR/../.. ./node_modules/.bin/webdriver-manager update diff --git a/scripts/ci/test_e2e_js.sh b/scripts/ci/test_e2e_js.sh index 53928a2974..f4cb0a0331 100755 --- a/scripts/ci/test_e2e_js.sh +++ b/scripts/ci/test_e2e_js.sh @@ -4,7 +4,6 @@ set -e echo ============================================================================= # go to project dir SCRIPT_DIR=$(dirname $0) -source $SCRIPT_DIR/env_dart.sh cd $SCRIPT_DIR/../.. ./node_modules/.bin/webdriver-manager update @@ -21,4 +20,10 @@ trap killServer EXIT # wait for server to come up! sleep 10 -./node_modules/.bin/protractor protractor-js.conf.js --browsers=${E2E_BROWSERS:-Dartium} +# Let protractor use default browser unless one is specified. +OPTIONS=""; +if [[ -n "$E2E_BROWSERS" ]]; then + OPTIONS="--browsers=$E2E_BROWSERS"; +fi + +./node_modules/.bin/protractor protractor-js.conf.js $OPTIONS diff --git a/scripts/ci/test_js.sh b/scripts/ci/test_js.sh index 5ec3a5a043..5cd966bfc3 100755 --- a/scripts/ci/test_js.sh +++ b/scripts/ci/test_js.sh @@ -6,6 +6,11 @@ echo =========================================================================== SCRIPT_DIR=$(dirname $0) cd $SCRIPT_DIR/../.. -${SCRIPT_DIR}/test_unit_js.sh -# ${SCRIPT_DIR}/test_server_js.sh # JS doesn't yet have server tests +# Issue #945 Travis still uses Dartium, and hence needs the env setup. +# For local tests, when a developer doesn't have Dart, don't source env_dart.sh +if ${SCRIPT_DIR}/env_dart.sh 2>&1 > /dev/null ; then + source $SCRIPT_DIR/env_dart.sh +fi + +./node_modules/.bin/gulp test.js --browsers=${KARMA_BROWSERS:-ChromeCanary} ${SCRIPT_DIR}/test_e2e_js.sh diff --git a/scripts/ci/test_server_dart.sh b/scripts/ci/test_server_dart.sh index 7d1d2bea28..6bb7e2e028 100755 --- a/scripts/ci/test_server_dart.sh +++ b/scripts/ci/test_server_dart.sh @@ -4,7 +4,6 @@ set -e echo ============================================================================= # go to project dir SCRIPT_DIR=$(dirname $0) -source $SCRIPT_DIR/env_dart.sh cd $SCRIPT_DIR/../.. ./node_modules/.bin/webdriver-manager update diff --git a/scripts/ci/test_unit_dart.sh b/scripts/ci/test_unit_dart.sh deleted file mode 100755 index 1cedbeb980..0000000000 --- a/scripts/ci/test_unit_dart.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -set -e - -echo ============================================================================= -# go to project dir -SCRIPT_DIR=$(dirname $0) -source $SCRIPT_DIR/env_dart.sh -cd $SCRIPT_DIR/../.. - -./node_modules/.bin/gulp test.transpiler.unittest -./node_modules/.bin/gulp test.unit.dart/ci --browsers=$KARMA_BROWSERS diff --git a/scripts/ci/test_unit_js.sh b/scripts/ci/test_unit_js.sh deleted file mode 100755 index 5ea4eee013..0000000000 --- a/scripts/ci/test_unit_js.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -set -e - -echo ============================================================================= -# go to project dir -SCRIPT_DIR=$(dirname $0) -source $SCRIPT_DIR/env_dart.sh -cd $SCRIPT_DIR/../.. - -./node_modules/.bin/gulp test.transpiler.unittest -./node_modules/.bin/gulp docs/test -./node_modules/.bin/gulp test.unit.js/ci --browsers=$KARMA_BROWSERS -./node_modules/.bin/gulp test.unit.cjs/ci diff --git a/tools/build/pubget.js b/tools/build/pubget.js index eb4b272057..d0f1123508 100644 --- a/tools/build/pubget.js +++ b/tools/build/pubget.js @@ -2,7 +2,21 @@ var util = require('./util'); var spawn = require('child_process').spawn; var path = require('path'); -module.exports = function(gulp, plugins, config) { +module.exports = { + dir: pubGetDir, + subDir: pubGetSubDir +}; + +function pubGetDir(gulp, plugins, config) { + return function() { + return util.processToPromise(spawn(config.command, ['get'], { + stdio: 'inherit', + cwd: config.dir + })); + }; +}; + +function pubGetSubDir(gulp, plugins, config) { return function() { // We need to execute pubspec serially as otherwise we can get into trouble // with the pub cache... @@ -14,4 +28,3 @@ module.exports = function(gulp, plugins, config) { }); }; }; -