Rework tests to use Node modules consistently.

Also update the README with the simpler commands now available:

Install dev dependencies (and build .ts -> .js) with `npm install`
Test with `npm test`
Package (including building .ts -> .js) with `npm pack`
This commit is contained in:
Luke Hoban 2015-01-09 19:11:49 -08:00
Родитель 0cf4b346bd
Коммит 7ada4d89d1
7 изменённых файлов: 47 добавлений и 48 удалений

Просмотреть файл

@ -10,7 +10,9 @@ obj
# Ignore test files
Tests
# Don't publish .ts files
# Don't publish source files that aren't needed in package
*.ts
!*.d.ts
ai_stub.js
install.js

Просмотреть файл

@ -2,7 +2,7 @@
[![NPM version](https://badge.fury.io/js/applicationinsights.svg)](http://badge.fury.io/js/applicationinsights)
>Node.js® is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
>Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
>-- <cite>[nodejs.org](http://nodejs.org/)</cite>
@ -25,7 +25,7 @@ This project extends the Application Insights API surface to support Node.js. [A
## Usage ##
**Configuration**
```javascript
import aiModule = require("applicationInsights");
var aiModule = require("applicationInsights");
var appInsights = new aiModule.NodeAppInsights({
instrumentationKey: "<guid>" // see "Requirements" section to get a key
@ -61,14 +61,9 @@ appInsights.trackAllUncaughtExceptions();
## Contributing ##
**Development environment**
* Install [Visual Studio](http://www.visualstudio.com/)
* Install [Node.js tools for Visual Studio](http://nodejstools.codeplex.com/)
* Install [git tools for windows](http://git-scm.com/download/win)
* Install [Node.js](http://nodejs.org/)
* Install test dependencies
* Install dev dependencies
```
npm install node-mocks-http
npm install async
npm install
```
* (optional) Set an environment variable to your instrumentation key
```
@ -76,12 +71,7 @@ set APPINSIGHTS_INSTRUMENTATION_KEY=<insert_your_instrumentation_key_here>
```
* Run tests
```
node Tests\TestServer.js
```
> **Note**: the startup file can also be changed to TestServer.js in the *.njsproj so that the IDE runs tests instead of the example server.
```xml
<StartupFile>Tests\TestServer.js</StartupFile>
<!-- <StartupFile>ExampleUsage.js</StartupFile> -->
npm test
```

Просмотреть файл

@ -1,13 +1,13 @@
/// <reference path="../applicationInsights.ts" />
import aiModule = require("../applicationInsights");
import aiModule = require("../applicationInsights");
import http = require("http");
import Sender = require("../Sender")
import TestHelper = require("./TestHelper")
var mock = require("node-mocks-http");
var ai = require("../ai");
var prefix = "E2ETests_";
class E2ETests implements Tests {
class E2ETests implements TestHelper.Tests {
private _testHelper: TestHelper;
constructor(testHelper: TestHelper) {
@ -155,4 +155,4 @@ class E2ETests implements Tests {
}
}
module.exports = E2ETests;
export = E2ETests;

Просмотреть файл

@ -1,12 +1,6 @@
interface TestResult {
type: string;
name: string;
result: boolean;
}
///<reference path="../Scripts/typings/async/async.d.ts" />
interface Tests {
register: () => void;
}
import async = require("async");
class TestHelper {
public results;
@ -52,9 +46,8 @@ class TestHelper {
}
public run(callback: (TestHelper) => void) {
var async = require("async");
var self = this;
async.series(this.tests, (error, results: [TestResult]) => {
async.series(this.tests, (error, results: TestHelper.TestResult[]) => {
for (var i = 0; i < results.length; i++) {
var result = results[i];
this.log(result);
@ -68,7 +61,7 @@ class TestHelper {
return "<html><head></head><body><ol>" + this.results + "</ol></body>";
}
private log(result: TestResult) {
private log(result: TestHelper.TestResult) {
console.log(result.type + ": " + result.name);
var color;
if (result.result) {
@ -84,4 +77,16 @@ class TestHelper {
}
}
module.exports = TestHelper;
module TestHelper {
export interface TestResult {
type: string;
name: string;
result: boolean;
}
export interface Tests {
register: () => void;
}
}
export = TestHelper

Просмотреть файл

@ -4,8 +4,7 @@
/*
* To run these tests:
* - npm install node-mocks-http
* - npm install async
* - npm install
* - set APPINSIGHTS_INSTRUMENTATION_KEY=<insert_your_instrumentation_key_here>
* - node Tests\TestServer.js
*/
@ -13,9 +12,12 @@
import http = require("http");
import url = require("url");
import UnitTests = require("./UnitTests")
import E2ETests = require("./E2ETests")
import TestHelper = require("./TestHelper")
function runTests(server: http.Server, onComplete: (TestHelper) => void) {
// create test helper
var TestHelper = require("./TestHelper");
var testHelper: TestHelper = new TestHelper();
// catch unhandled exceptions and make sure they show up in test results
@ -31,13 +33,11 @@ function runTests(server: http.Server, onComplete: (TestHelper) => void) {
process.on("uncaughtException", onError);
// run unit tests
var UnitTests = require('./UnitTests');
var unitTests: Tests = new UnitTests(testHelper);
var unitTests: TestHelper.Tests = new UnitTests(testHelper);
unitTests.register();
// run e2e tests
var E2ETests = require('./E2ETests');
var e2eTests: Tests = new E2ETests(testHelper);
var e2eTests: TestHelper.Tests = new E2ETests(testHelper);
e2eTests.register();
testHelper.run(onComplete);

Просмотреть файл

@ -1,16 +1,15 @@
/// <reference path="../applicationInsights.ts" />
import aiModule = require("../applicationInsights");
import aiModule = require("../applicationInsights");
import ai = require("../ai");
import TestHelper = require("./TestHelper")
var mock = require("node-mocks-http");
var ai = require("../ai");
class UnitTests implements Tests {
class UnitTests implements TestHelper.Tests {
public appInsights: aiModule.NodeAppInsights;
private testHelper: TestHelper;
constructor(testHelper: TestHelper, appInsights) {
constructor(testHelper: TestHelper) {
// load and configure application insights
this.appInsights = new aiModule.NodeAppInsights({ instrumentationKey: "fakeTestKey" });
@ -135,4 +134,4 @@ class UnitTests implements Tests {
}
}
module.exports = UnitTests;
export = UnitTests;

Просмотреть файл

@ -33,9 +33,12 @@
],
"scripts": {
"prepublish": "tsc --module commonjs --declaration applicationInsights.ts",
"test": "tsc --module commonjs Tests/TestServer.ts && node Tests/TestServer",
"postinstall": "node install.js"
},
"devDependencies": {
"async": "^0.9.0",
"node-mocks-http": "^1.2.3",
"typescript": "^1.0.1"
}
}