diff --git a/docs/DEBUG.md b/docs/DEBUG.md index af98cafb78..db7c6d0e31 100644 --- a/docs/DEBUG.md +++ b/docs/DEBUG.md @@ -5,55 +5,20 @@ The core packages are tested both in the browser (via Karma) and on the server ( ## Debugging in Karma -Run the unit tests as normal using via the `./test.sh` script. For example: - -```bash -./test.sh browserNoRouter -``` - -Once the initial build has completed and the Karma server has started up, you can go to the -Chrome browser that is automatically opened, usually pointing to `http://localhost:9876`. -The script will sit watching for code changes, recompiling the changed files and triggering -further runs of the unit tests in the browser. - -In this browser there is a "DEBUG" link (in the top right corner). Clicking this link will -open up a new tab that will run the unit tests and will not timeout, giving you time to -step through the code. - -Open up this tab's developer console to access the source code viewer where you can set -breakpoints and interrogate the current stack and variables. - It is useful to focus your debugging on one test at a time by changing that test to be defined using the `fit(...)` function, rather than `it(...)`. Moreover it can be helpful to place a `debugger` statement in this `fit` clause to cause the debugger to stop when it hits this test. +Read more about starting the debugger for Karma with Bazel in the [BAZEL.md](./BAZEL.md) +document. + ## Debugging in Node -Run the unit tests as normal using the `./test.sh` script, but add the `--debug` flag to -the command. For example: - -```bash -./test.sh node --debug -``` - -Once the initial building has completed, the script will watch for code changes, recompiling -and running the unit tests via a tool call `cjs-jasmine`. Due to the `--debug` flag, each -test run will create a debugging server listening on a port (such as 9229), which can be -connected to by a debugger. - -You can use Chrome as the debugger by navigating to `chrome://inspect` then clicking the -"Open dedicated DevTools for Node" link. This will open up a Developer console, which will -automatically connect to the debugging server. - It is useful to focus your debugging on one test at a time by changing that test to be defined using the `fit(...)` function, rather than `it(...)`. Moreover it can be helpful to place a `debugger` statement in this `fit` clause to cause the debugger to stop when it hits this test. -**Problem with node 6:** at the time of writing, the node process does not tell the Chrome -debugger when it has completed, and so the debugger is not able to automatically disconnect -from listening to the debugging server. To solve this, just close the developer tools window -after each run of the unit tests, before making changes to the code. This is fixed in node 8 -and may be backported to node 6. This issue is tracked in -https://github.com/nodejs/node/pull/12814#issuecomment-309908579. +Read more about starting the debugger for NodeJS tests with Bazel in the [BAZEL.md](./BAZEL.md) +document. \ No newline at end of file diff --git a/docs/DEVELOPER.md b/docs/DEVELOPER.md index 4ff45de528..12b7197ec9 100644 --- a/docs/DEVELOPER.md +++ b/docs/DEVELOPER.md @@ -82,33 +82,22 @@ Before submitting a PR, do not forget to remove them: To build Angular run: ```shell -./build.sh +./scripts/build-packages-dist.sh ``` -* Results are put in the dist folder. +* Results are put in the `dist/packages-dist` folder. ## Running Tests Locally -To run tests: +Bazel is used as the primary tool for building and testing Angular. Building and testing is +incremental with Bazel, and it's possible to only run tests for an individual package instead +of for all packages. -```shell -$ ./test.sh node # Run all angular tests on node +Read more about this in the [BAZEL.md](./BAZEL.md) document. You should execute all test suites +before submitting a PR to Github. -$ ./test.sh browser # Run all angular tests in browser - -$ ./test.sh browserNoRouter # Optionally run all angular tests without router in browser - -$ ./test.sh router # Optionally run only the router tests in browser -``` - -You should execute the 3 test suites before submitting a PR to github. - -See [DEBUG.md](DEBUG.md) for information on debugging the code while running the unit tests. - -All the tests are executed on our Continuous Integration infrastructure and a PR could only be merged once the tests pass. - -- CircleCI fails if your code is not formatted properly, -- Travis CI fails if any of the test suites described above fails. +All the tests are executed on our Continuous Integration infrastructure and a PR could only be +merged if the code is formatted properly and all tests are passing. ## Formatting your source code diff --git a/packages/compiler-cli/tsconfig-tools.json b/packages/compiler-cli/tsconfig-tools.json deleted file mode 100644 index 752f6bf1ed..0000000000 --- a/packages/compiler-cli/tsconfig-tools.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "./tsconfig-build.json", - - "compilerOptions": { - "outDir": "../../dist/tools/@angular/compiler-cli", - "paths": { - "@angular/compiler": ["../../dist/tools/@angular/compiler"] - } - } -} \ No newline at end of file diff --git a/packages/compiler/tsconfig-tools.json b/packages/compiler/tsconfig-tools.json deleted file mode 100644 index e45b55988d..0000000000 --- a/packages/compiler/tsconfig-tools.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "./tsconfig-build.json", - - "compilerOptions": { - "module": "commonjs", - "target": "es5", - "outDir": "../../dist/tools/@angular/compiler" - } -} \ No newline at end of file diff --git a/packages/tsconfig-metadata.json b/packages/tsconfig-metadata.json deleted file mode 100644 index 0aeb1e3545..0000000000 --- a/packages/tsconfig-metadata.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "extends": "./tsconfig.json", - - "compilerOptions": { - "paths": { - "@angular/*": ["./*"] - } - }, - - "exclude": [ - "bazel", - "compiler/test", - "compiler-cli/integrationtest", - "platform-server/integrationtest", - "router/test/aot_ngsummary_test", - "common/locales", - "examples", - "**/*_spec.ts", - "**/*.spec.ts" - ], - - "angularCompilerOptions": { - "skipTemplateCodegen": true, - "annotateForClosureCompiler": false, - "annotationsAs": "decorators" - } -} diff --git a/test.sh b/test.sh deleted file mode 100755 index 812448f086..0000000000 --- a/test.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -set -e -o pipefail - -if [ $# -eq 0 ] - then - echo "Angular test runner. (No platform specified)" - echo - echo "./test.sh [node|browser|browserNoRouter|router] [--debug]" - echo "(--debug flag only relevant to 'node' testing - see https://github.com/angular/angular/blob/master/docs/DEBUG.md)" - echo -else - cd `dirname $0` - rm -rf dist/tools - if [ -z ${NODE_PATH+x} ]; then - export NODE_PATH=$(pwd)/dist/all:$(pwd)/dist/tools - else - export NODE_PATH=$NODE_PATH:$(pwd)/dist/all/:$(pwd)/dist/tools/ - fi - echo "Compiling tools..." - $(npm bin)/tsc -p tools - if [[ $1 == 'node' ]]; then - # Note: .metadata.json files are needed for the language service tests! - echo "Building compiler..." - $(npm bin)/tsc -p packages/compiler/tsconfig-tools.json - $(npm bin)/tsc -p packages/compiler-cli/tsconfig-tools.json - echo "Creating packages .metadata.json files..." - node --max-old-space-size=3000 dist/tools/@angular/compiler-cli/src/main -p packages/tsconfig-metadata.json - fi - node --harmony dist/tools/tsc-watch/ $1 watch $2 -fi diff --git a/tools/tsc-watch/index.ts b/tools/tsc-watch/index.ts deleted file mode 100644 index 0400b3ce45..0000000000 --- a/tools/tsc-watch/index.ts +++ /dev/null @@ -1,114 +0,0 @@ -/** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -/* tslint:disable:no-console */ -import {existsSync, mkdirSync} from 'fs'; - -import {TscWatch} from './tsc_watch'; - -export * from './tsc_watch'; -import 'reflect-metadata'; - -function md(dir: string, folders: string[]) { - if (folders.length) { - const next = folders.shift(); - const path = dir + '/' + next; - if (!existsSync(path)) { - mkdirSync(path); - } - md(path, folders); - } -} - -let tscWatch: TscWatch = null; -const platform = process.argv.length >= 3 ? process.argv[2] : null; -const runMode: string = process.argv.length >= 4 ? process.argv[3] : null; -const debugMode = process.argv.some(arg => arg === '--debug'); -const BaseConfig = { - start: 'File change detected. Starting incremental compilation...', - // This regex uses a negative lookbehind group (? Promise; - -export class TscWatch { - private tsconfig: string[]; - private start: string|RegExp; - private error: string|RegExp; - private complete: string|RegExp; - private onStartCmds: Array; - private onChangeCmds: Array; - private state: State; - private triggered: Promise = null; - private runOnce: boolean = false; - - constructor({tsconfig, start, error, complete, onStartCmds = null, onChangeCmds = null}: { - tsconfig: string | string[], - error: string|RegExp, - start: string, - complete: string, onStartCmds?: Array, onChangeCmds?: Array - }) { - console.log('Watching:', tsconfig, 'in', process.cwd()); - this.tsconfig = Array.isArray(tsconfig) ? tsconfig : [tsconfig]; - this.start = start; - this.error = error; - this.complete = complete; - this.onStartCmds = onStartCmds || []; - this.onChangeCmds = onChangeCmds || []; - } - - watch() { - const tsc = - Promise - .all(this.tsconfig.map(tsconfig => { - const args = [TSC, '--emitDecoratorMetadata', '--project', tsconfig]; - if (!this.runOnce) args.push('--watch'); - return this.runCmd( - args, {}, (d) => this.consumeLine(d, false), (d) => this.consumeLine(d, true)); - })) - .then( - exitCodes => - exitCodes.reduce((prevValue, currValue) => Math.max(prevValue, currValue), 0)); - if (this.runOnce) { - tsc.then(() => this.triggerCmds(), code => process.exit(code)); - } - this.state = State.waiting; - this.onStartCmds.forEach((cmd) => this.runCmd(cmd, null, () => null, () => null)); - } - - private runCmd( - argsOrCmd: string[]|Command, env?: {[k: string]: string}, stdOut = pipeStdOut, - stdErr = pipeStdErr): Promise { - if (typeof argsOrCmd == 'function') { - return (argsOrCmd as Command)(stdErr, stdOut); - } else if (argsOrCmd instanceof Array) { - const args = argsOrCmd as Array; - return new Promise((resolve, reject) => { - const [cmd, ...options] = args; - console.log('=====>', cmd, options.join(' ')); - const childProcess = spawn(cmd, options, {stdio: 'pipe'}); - childProcess.stdout.on('data', stdOut); - childProcess.stderr.on('data', stdErr); - const onExit = () => childProcess.kill(); - childProcess.on('close', (code: number) => { - process.removeListener('exit', onExit); - console.log('EXIT:', code, '<=====', args.join(' ')); - code ? reject(code) : resolve(code); - }); - process.on('exit', onExit); - }) - .catch(reportError); - } else { - throw new Error('Expecting function or an array of strings...'); - } - } - - run() { - this.runOnce = true; - this.watch(); - } - - runCmdsOnly() { - this.runOnce = true; - this.triggerCmds(); - } - - consumeLine(buffer: Buffer, isStdError: boolean) { - const line = '' + buffer; - if (contains(line, this.start)) { - console.log('=============================================================================='); - stdOut(buffer, isStdError); - this.state = State.waiting; - } else if (contains(line, this.error)) { - stdOut(buffer, isStdError); - this.state = State.error; - } else if (contains(line, this.complete)) { - stdOut(buffer, isStdError); - console.log('------------------------------------------------------------------------------'); - if (this.state == State.error) { - console.log('Errors found.... (response not triggered)'); - if (this.runOnce) process.exit(1); - this.state = State.idle; - } else { - if (this.triggered) { - this.triggered.then( - () => this.triggerCmds(), (e) => console.log('Error while running commands....', e)); - } else { - this.triggerCmds(); - } - } - } else { - stdOut(buffer, isStdError); - } - } - - triggerCmds() { - let cmdPromise: Promise = Promise.resolve(0); - this.onChangeCmds.forEach( - (cmd: string[] | Command) => cmdPromise = - cmdPromise.then(() => this.runCmd(cmd))); - cmdPromise.then(() => this.triggered = null, (code) => { - if (this.runOnce) { - if (typeof code != 'number') { - console.error('Error occurred while executing commands', code); - process.exit(1); - } - process.exit(code); - } else { - this.triggered = null; - } - }); - this.triggered = cmdPromise; - } -} - -function stdOut(data: Buffer, isStdError: boolean) { - if (isStdError) { - process.stderr.write(data); - } else { - process.stdout.write(data); - } -} - -function contains(line: string, text: string | RegExp): boolean { - if (typeof text == 'string') { - return line.indexOf(text as string) != -1; - } else if (text instanceof RegExp) { - return (text as RegExp).test(line); - } else { - throw new Error('Unknown: ' + text); - } -} - -export function reportError(e: any) { - if (e.message && e.stack) { - console.error(e.message); - console.error(e.stack); - } else { - console.error(e); - } - // process.exit(1); - return Promise.reject(e); -} - -function pipeStdOut(d: any) { - process.stdout.write(d); -} -function pipeStdErr(d: any) { - process.stderr.write(d); -}