# API Description

[XPlat VS Telemetry API](https://devdiv.visualstudio.com/NodeRepos/NodeRepos%20Team/_git/vs-telemetry-api?path=%2FREADME.md&version=GBmaster&_a=contents)

# Setup Machine

## Installations
- Install Node.js 5.5.0 or higher. x86 Node is recommended as that is what Willow runs.
### Optional Installations
- These installations are optional since they are included as dev dependencies in the package.json.
- However you may find it useful to have them available globally.
- Install tsd 0.6.5 or higher `npm install -g tsd`.
- Install typescript 1.8.2 or higher `npm install -g typescript`.
- Install tslint 3.6.0 or higher `npm install -g tslint`.
- Install istanbul 0.4.2 or higher `npm install -g istanbul`.

## Authenticate to VSTS NPM Package Registry
 - vs-telemetry consumes several internal NPM packages.
 - In order to authenticate, go to the [NodeRepos pkg site](https://devdiv.visualstudio.com/NodeRepos/_packaging?feedName=NodeRepos&protocolType=Npm) follow the instructions under "Connect to feed -> npm"

## Configure machine for native NPM node_modules
 - Several NPM modules use native C++ files that must be compiled using the node-gyp tool.
 - Follow the instructions for your platform at [node-gyp docs](https://github.com/nodejs/node-gyp)
      - Brief steps for Windows:
        1. `npm install -g node-gyp`
        2. Install VisualStudio 2015 C++ Build Tools.
          a. This can be found in Visual Studio 2017 Installer by going to:
              Individual components -> Compilers, build tools, and runtimes -> VC++ 2015.3 v140 toolset
        3. Install Python 2.7
        4. `npm config set python python2.7`
        5. `npm config set msvs_version 2015`
- Make sure to close and re-open your command prompt to update environment variables.

# Build Process

Commands:
- `npm install` from the repo root to install NPM packages, TypeScript definitions, and compile native modules' source files.
  - If you are having problems with native compilation, it may help to run from a VS Developer command prompt.
- `npm test` to build, test the project and run code coverage.
  - `tsc` to build the project.
  - `npm run tslint` to build and run tslint on the project
- `npm run clean` to remove build artifacts

# Setup VSCode

Press `Ctrl+P` and type `ext install tslint`.

# Preparing a Pull-Request

Follow these steps before merging a new Pull-Request

1. Add a line that describes the changes to [CHANGELOG.md](CHANGELOG.md).
2. Increment a version number in [package.json](package.json).
3. Commit the changes to your branch.
4. Sync the changes.

# Run Perf Tests

These tests aren't part of the regular unit test set which is run for each checkin.

## Perf Tests for Dynamic Telemetry
In order to run these tests you need to run the following command line
from the \vs-telemetry folder after successful building:

`node --expose-gc --max-old-space-size=8192 node_modules\mocha\bin\_mocha test\dynamic-telemetry-perf\*.js`


## Leak Tests
 In order to run this test you need to run the following command line
 from the \vs-telemetry folder after building:

 `node --expose-gc test\leak-testing\telemetry-tests-leak-testing.js`

 After the file has finished running, analyze the heapdumps by following the instructions
 at the [end of this blog post](https://www.alexkras.com/simple-guide-to-finding-a-javascript-memory-leak-in-node-js/)

 ## Native Registry E2E Tests
 This adds, queries, and deletes values from a test location in the real registry using native registry calls.
 You can run it from the \vs-telemetry folder after building:

 `mocha test\native-registry\native-registry-tests-e2e.js`