Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Building and Testing Angular 2 for JS and Dart
This document describes how to set up your development environment to build and test Angular, both
JS and Dart versions. It also explains the basic mechanics of using
git,node, andnpm.See the contribution guidelines
if you'd like to contribute to Angular.
Prerequisite Software
Before you can build and test Angular, you must install and configure the
following products on your development machine:
>=1.12.0 <2.0.0), specifically the Dart-SDK andDartium (a version of Chromium with native support for Dart through
the Dart VM). One of the simplest ways to get both is to install the Dart Editor bundle,
which includes the editor, SDK and Dartium. See the Dart tools
download page for instructions.
You can also download both stable and dev channel versions from the download
archive. In that case, on Windows, Dart must be added
to the
Path(e.g.path-to-dart-sdk-folder\bin) and a newDARTIUM_BINenvironment variable must becreated, pointing to the executable (e.g.
path-to-dartium-folder\chrome.exe).Windows); GitHub's Guide to Installing
Git is a good source of information.
>=4.2.1 <5) which is used to run a development web server,run tests, and generate distributable files. We also use Node's Package Manager,
npm(version
>=2.14.7 <3.0), which comes with Node. Depending on your system, you can install Node either fromsource or as a pre-packaged bundle.
bleeding edge functionality, built especially for developers (and early adopters).
Getting the Sources
Fork and clone the Angular repository:
here.
repository.
upstreamremote pointing back tothe Angular repository that you forked in the first place.
Environment Variable Setup
Define the environment variables listed below. These are mainly needed for the testing. The
notation shown here is for
bash; adapt as appropriate foryour favorite shell.
Examples given below of possible values for initializing the environment variables assume Mac OS
X and that you have installed the Dart Editor in the directory named by
DART_EDITOR_DIR=/Applications/dart. This is only for illustrative purposes.Add the Dart SDK
bindirectory to your path and/or defineDART_SDK(this is also detailedhere):
And specify where the pub’s dependencies are downloaded. By default, this directory is located under .pub_cache
in your home directory (on Mac and Linux), or in AppData\Roaming\Pub\Cache (on Windows).
Installing NPM Modules and Dart Packages
Next, install the JavaScript modules and Dart packages needed to build and test Angular:
# Install Angular project dependencies (package.json) npm installOptional: In this document, we make use of project local
npmpackage scripts and binaries(stored under
./node_modules/.bin) by prefixing these command invocations with$(npm bin); inparticular
gulpandprotractorcommands. 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 withsudo)npm install -g protractor(you might need to prefix this command withsudo)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 thisStackoverflow answer and used like this: e.g.,
nbin gulp build.Build commands
To build Angular and prepare tests, run:
$(npm bin)/gulp buildNotes:
distfolder.pub getfor the subfolders inmodulesand rundartanalyzerforevery file that matches
<module>/src/<module>.dart, e.g.di/src/di.dart.You can selectively build either the JS or Dart versions as follows:
$(npm bin)/gulp build.js$(npm bin)/gulp build.dartTo clean out the
distfolder, run:$(npm bin)/gulp cleanRunning Tests Locally
Full test suite
npm test: full test suite for both JS and Dart versions of Angular. These are the same teststhat 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.dartUnit 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.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/ciThe task updates the dist folder with transpiled code whenever a source or test file changes, and
Karma is run against the new output.
Note: If you want to only run a single test you can alter the test you wish to run by changing
ittoiitordescribetoddescribe. This will only run that individual test and make itmuch easier to debug.
xitandxdescribecan also be useful to exclude a test and a group oftests respectively.
Note: watch mode needs symlinks to work, so if you're using windows, ensure you have the
rights to built them in your operating system.
Unit tests with Sauce Labs or Browser Stack
First, in a terminal, create a tunnel with Sauce Connect or Browser Stack Local, and valid credentials.
Then, in another terminal:
gulp test.unit.js.(saucelabs|browserstack) --browsers=option1,option2,..,optionNThe options are any mix of browsers and aliases which are defined in the browser-providers.conf.js file.
They are case insensitive, and the
SL_orBS_prefix must not be added for browsers.Some examples of commands:
E2E tests
$(npm bin)/gulp build.js.cjs(builds benchpress and tests intodist/js/cjsfolder).$(npm bin)/gulp serve.js.prod serve.dart(runs a local webserver).$(npm bin)/protractor protractor-js.conf.js: JS e2e tests.$(npm bin)/protractor protractor-dart2js.conf.js: dart2js e2e tests.Angular specific command line options when running protractor:
$(npm bin)/protractor protractor-{js|dart2js}-conf.js --ng-helpPerformance tests
$(npm bin)/gulp build.js.cjs(builds benchpress and tests intodist/js/cjsfolder)$(npm bin)/gulp serve.js.prod serve.dart(runs a local webserver)$(npm bin)/protractor protractor-js.conf.js --benchmark: JS performance tests$(npm bin)/protractor protractor-dart2js.conf.js --benchmark: dart2js performance testsAngular specific command line options when running protractor (e.g. force gc, ...):
$(npm bin)/protractor protractor-{js|dart2js}-conf.js --ng-helpFormatting with clang-format
We use clang-format to automatically enforce code
style for our TypeScript code. This allows us to focus our code reviews more on the content, and
less on style nit-picking. It also lets us encode our style guide in the
.clang-formatfile in therepository, allowing many tools and editors to share our settings.
To check the formatting of your code, run
Note that the continuous build on Travis runs
gulp enforce-format. Unlike thecheck-formattask,this will actually fail the build if files aren't formatted according to the style guide.
Your life will be easier if you include the formatter in your standard workflow. Otherwise, you'll
likely forget to check the formatting, and waste time waiting for a build on Travis that fails due
to some whitespace difference.
$(npm bin)/clang-format -i [file name]to format a file (or multiple).gulp enforce-formatto check if your code isclang-formatclean. This also givesyou a command line to format your code.
clang-formatalso includes a git hook, rungit clang-formatto format all files youtouched.
commit a change. In the angular repo, run
$ProjectFileDir$/node_modules/.bin/clang-format-i -style=file $FilePath$$ProjectFileDir$clang-formatintegrations are also available for many popular editors (vim,emacs,Sublime Text, etc.).Generating the API documentation
The following gulp task will generate the API docs in the
dist/angular.io/partials/api/angular2:$(npm bin)/gulp docs/angular.ioYou can serve the generated documentation to check how it would render on angular.io:
angular/dist/angular.io/partials/api/angular2to your local angular.io repo atangular.io/public/docs/js/latest/api,harp compileat the root of the angular.io repo to check the generated documentation for errors,harp serverand open a browser athttp://localhost:9000/docs/js/latest/api/to check the rendered documentation.Project Information
Folder structure
modules/*: modules that will be loaded in the browsertools/*: tools that are needed to build Angulardist/*: build files are placed here.File suffixes
*.ts: TypeScript files that get transpiled to Dart and EcmaScript 5/6*.dart: Dart files that don't get transpiledCI using Travis
For instructions on setting up Continuous Integration using Travis, see the instructions given
here.
Transforming Dart code
See the wiki.
Debugging
Debug the transpiler
If you need to debug the transpiler:
debugger;statement in the transpiler code,node debug $(npm bin)/gulp buildto enter the nodedebugger
debugger;statement,See the Node.js manual for more information.
Notes:
node $(npm bin)/karma start karma-dart.conf.jsdepending on whichcode you want to debug (the former will process the "modules" folder while the later processes
the transpiler specs).
debugger;statements in the specs (JavaScript). The execution will halt whenthe developer tools are opened in the browser running Karma.
Debug the tests
If you need to debug the tests:
debugger;statement to the test you want to debug (or the source code),$(npm bin)/gulp test.js,debugger;statementNote (WebStorm users):
code on the
debugger;statement.The
debugger;statement is needed because WebStorm will stop in a transpiled file. Breakpoints inthe original source files are not supported at the moment.