X Tutup
Skip to content

Commit 8340293

Browse files
chalinmhevery
authored andcommitted
chore(install+test): single cmd to full install/test & test JS w/o Dart
* `npm install` now does a full install; auxiliary installation steps have been integrated into the `postinstall` script. * Updated developer docs `DEVELOPER.md` accordingly; also added instructions to dev docs for performing full tests (via `npm test`) -- same as those run on Travis. * Reorg in tests so that JS tests can run without a Dart env. Partly fixes angular#945 **under the assumption that when running JS tests locally, `ChromeCanary` is the desired browser to use**. Note that CI tests (Travis) still uses `DartiumWithWebPlatform` across the board (Maybe because ChromeCanary isn't being installed?) Fixes angular#1012. Closes angular#1010
1 parent bd48c92 commit 8340293

File tree

12 files changed

+88
-59
lines changed

12 files changed

+88
-59
lines changed

DEVELOPER.md

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,22 @@ Next, install the modules and packages needed to build Angular and run tests:
9595
```shell
9696
# Install Angular project dependencies (package.json)
9797
npm install
98-
99-
# Ensure protractor has the latest webdriver
100-
$(npm bin)/webdriver-manager update
101-
102-
# Install Dart packages
103-
pub get
10498
```
10599

106100
**Optional**: In this document, we make use of project local `npm` package scripts and binaries
107101
(stored under `./node_modules/.bin`) by prefixing these command invocations with `$(npm bin)`; in
108-
particular `gulp` and `protractor` commands. If you prefer, you can drop this path prefix by
109-
globally installing these two packages as follows:
102+
particular `gulp` and `protractor` commands. If you prefer, you can drop this path prefix by either:
103+
104+
*Option 1*: globally installing these two packages as follows:
110105

111106
* `npm install -g gulp` (you might need to prefix this command with `sudo`)
112107
* `npm install -g protractor` (you might need to prefix this command with `sudo`)
113108

114-
Since global installs can become stale, we avoid their use in these instructions.
109+
Since global installs can become stale, and required versions can vary by project, we avoid their
110+
use in these instructions.
111+
112+
*Option 2*: defining a bash alias like `alias nbin='PATH=$(npm bin):$PATH'` as detailed in this
113+
[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`.
115114

116115
## Build commands
117116

@@ -133,22 +132,35 @@ $(npm bin)/gulp clean
133132

134133
## Running Tests Locally
135134

136-
### Basic tests
135+
### Full test suite
136+
137+
* `npm test`: full test suite for both JS and Dart versions of Angular. These are the same tests as
138+
those run on Travis.
137139

138-
1. `$(npm bin)/gulp test.unit.js`: JS tests in a browser; runs in **watch mode** (i.e. karma
139-
watches the test files for changes and re-runs tests when files are updated).
140-
2. `$(npm bin)/gulp test.unit.cjs`: JS tests in NodeJS; runs in **watch mode**
141-
3. `$(npm bin)/gulp test.unit.dart`: Dart tests in Dartium; runs in **watch mode**.
140+
You can selectively run either the JS or Dart versions as follows:
141+
142+
* `$(npm bin)/gulp test.all.js`
143+
* `$(npm bin)/gulp test.all.dart`
144+
145+
### Unit tests
146+
147+
You can run just the unit tests as follows:
148+
149+
* `$(npm bin)/gulp test.unit.js`: JS tests in a browser; runs in **watch mode** (i.e. karma
150+
watches the test files for changes and re-runs tests when files are updated).
151+
* `$(npm bin)/gulp test.unit.cjs`: JS tests in NodeJS; runs in **watch mode**.
152+
* `$(npm bin)/gulp test.unit.dart`: Dart tests in Dartium; runs in **watch mode**.
142153

143154
If you prefer running tests in "single-run" mode rather than watch mode use
144155

145156
* `$(npm bin)/gulp test.unit.js/ci`
157+
* `$(npm bin)/gulp test.unit.cjs/ci`
146158
* `$(npm bin)/gulp test.unit.dart/ci`
147159

148-
**Note**: If you want to only run a single test you can alter the test you wish
149-
to run by changing `it` to `iit` or `describe` to `ddescribe`. This will only
150-
run that individual test and make it much easier to debug. `xit` and `xdescribe`
151-
can also be useful to exclude a test and a group of tests respectively.
160+
**Note**: If you want to only run a single test you can alter the test you wish to run by changing
161+
`it` to `iit` or `describe` to `ddescribe`. This will only run that individual test and make it
162+
much easier to debug. `xit` and `xdescribe` can also be useful to exclude a test and a group of
163+
tests respectively.
152164

153165
**Note** for transpiler tests: The karma preprocessor is setup in a way so that after every test
154166
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.
232244
You can then step into the code and add watches.
233245
The `debugger;` statement is needed because WebStorm will stop in a transpiled file. Breakpoints in
234246
the original source files are not supported at the moment.
235-

gulpfile.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var gulp = require('gulp');
22
var gulpPlugins = require('gulp-load-plugins')();
3+
var shell = require('gulp-shell');
34
var runSequence = require('run-sequence');
45
var madge = require('madge');
56
var merge = require('merge');
@@ -26,6 +27,7 @@ var runServerDartTests = require('./tools/build/run_server_dart_tests');
2627
var transformCJSTests = require('./tools/build/transformCJSTests');
2728
var util = require('./tools/build/util');
2829

30+
// Note: when DART_SDK is not found, all gulp tasks ending with `.dart` will be skipped.
2931
var DART_SDK = require('./tools/build/dartdetect')(gulp);
3032
// -----------------------
3133
// configuration
@@ -431,7 +433,11 @@ gulp.task('build/multicopy.dart', copy.multicopy(gulp, gulpPlugins, {
431433
// ------------
432434
// pubspec
433435

434-
gulp.task('build/pubspec.dart', pubget(gulp, gulpPlugins, {
436+
// Run a top-level `pub get` for this project.
437+
gulp.task('pubget.dart', pubget.dir(gulp, gulpPlugins, { dir: '.', command: DART_SDK.PUB }));
438+
439+
// Run `pub get` over CONFIG.dest.dart
440+
gulp.task('build/pubspec.dart', pubget.subDir(gulp, gulpPlugins, {
435441
dir: CONFIG.dest.dart,
436442
command: DART_SDK.PUB
437443
}));
@@ -588,6 +594,22 @@ createDocsTasks(true);
588594
createDocsTasks(false);
589595

590596
// ------------------
597+
// CI tests suites
598+
599+
gulp.task('test.js', function(done) {
600+
runSequence('test.transpiler.unittest', 'docs/test', 'test.unit.js/ci',
601+
'test.unit.cjs/ci', done);
602+
});
603+
604+
gulp.task('test.dart', function(done) {
605+
runSequence('test.transpiler.unittest', 'docs/test', 'test.unit.dart/ci', done);
606+
});
607+
608+
// Reuse the Travis scripts
609+
// TODO: rename test_*.sh to test_all_*.sh
610+
gulp.task('test.all.js', shell.task(['./scripts/ci/test_js.sh']))
611+
gulp.task('test.all.dart', shell.task(['./scripts/ci/test_dart.sh']))
612+
591613
// karma tests
592614
// These tests run in the browser and are allowed to access
593615
// HTML DOM APIs.

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
"url": "https://github.com/angular/angular.git"
2121
},
2222
"scripts": {
23-
"test": "npm run test-js && npm run test-dart",
24-
"test-js": "./scripts/ci/test_js.sh",
25-
"test-dart": "./scripts/ci/test_dart.sh",
26-
"postinstall": "./node_modules/.bin/bower install"
23+
"postinstall": "webdriver-manager update && bower install && gulp pubget.dart",
24+
"test": "gulp test.all.js && gulp test.all.dart"
2725
},
2826
"dependencies": {
2927
"es6-module-loader": "^0.9.2",

scripts/ci/env_dart.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/false
1+
#!/bin/bash
22
set -e -o pipefail
33

44
if [[ -z $ENV_SET ]]; then
@@ -95,4 +95,4 @@ if [[ -z $ENV_SET ]]; then
9595
echo NGDART_SCRIPT_DIR=$NGDART_SCRIPT_DIR
9696
$DART --version 2>&1
9797

98-
fi
98+
fi

scripts/ci/test_dart.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ set -e
44
echo =============================================================================
55
# go to project dir
66
SCRIPT_DIR=$(dirname $0)
7+
source $SCRIPT_DIR/env_dart.sh
78
cd $SCRIPT_DIR/../..
89

9-
${SCRIPT_DIR}/test_unit_dart.sh
10+
./node_modules/.bin/gulp test.js --browsers=$KARMA_BROWSERS
1011
${SCRIPT_DIR}/test_server_dart.sh
1112
${SCRIPT_DIR}/test_e2e_dart.sh

scripts/ci/test_e2e_dart.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ set -e
44
echo =============================================================================
55
# go to project dir
66
SCRIPT_DIR=$(dirname $0)
7-
source $SCRIPT_DIR/env_dart.sh
87
cd $SCRIPT_DIR/../..
98

109
./node_modules/.bin/webdriver-manager update

scripts/ci/test_e2e_js.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ set -e
44
echo =============================================================================
55
# go to project dir
66
SCRIPT_DIR=$(dirname $0)
7-
source $SCRIPT_DIR/env_dart.sh
87
cd $SCRIPT_DIR/../..
98

109
./node_modules/.bin/webdriver-manager update
@@ -21,4 +20,10 @@ trap killServer EXIT
2120
# wait for server to come up!
2221
sleep 10
2322

24-
./node_modules/.bin/protractor protractor-js.conf.js --browsers=${E2E_BROWSERS:-Dartium}
23+
# Let protractor use default browser unless one is specified.
24+
OPTIONS="";
25+
if [[ -n "$E2E_BROWSERS" ]]; then
26+
OPTIONS="--browsers=$E2E_BROWSERS";
27+
fi
28+
29+
./node_modules/.bin/protractor protractor-js.conf.js $OPTIONS

scripts/ci/test_js.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ echo ===========================================================================
66
SCRIPT_DIR=$(dirname $0)
77
cd $SCRIPT_DIR/../..
88

9-
${SCRIPT_DIR}/test_unit_js.sh
10-
# ${SCRIPT_DIR}/test_server_js.sh # JS doesn't yet have server tests
9+
# Issue #945 Travis still uses Dartium, and hence needs the env setup.
10+
# For local tests, when a developer doesn't have Dart, don't source env_dart.sh
11+
if ${SCRIPT_DIR}/env_dart.sh 2>&1 > /dev/null ; then
12+
source $SCRIPT_DIR/env_dart.sh
13+
fi
14+
15+
./node_modules/.bin/gulp test.js --browsers=${KARMA_BROWSERS:-ChromeCanary}
1116
${SCRIPT_DIR}/test_e2e_js.sh

scripts/ci/test_server_dart.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ set -e
44
echo =============================================================================
55
# go to project dir
66
SCRIPT_DIR=$(dirname $0)
7-
source $SCRIPT_DIR/env_dart.sh
87
cd $SCRIPT_DIR/../..
98

109
./node_modules/.bin/webdriver-manager update

scripts/ci/test_unit_dart.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)
X Tutup