Skip to content

Commit

Permalink
Sample project
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanbanken committed Aug 4, 2017
0 parents commit 17fab50
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Demo ts-lint recompiling TypeScript

````bash
node --inspect --debug-brk node_modules/.bin/jest --verbose --runInBand
````

Sample test output:

````
-> % node node_modules/.bin/jest --verbose --runInBand
PASS src/__tests__/simple-error.ts (5.977s)
ts-jest being slow
✓ throwing 1000 Errors (4693ms)
✓ throwing 1000 Errors, not touching Error.stack (4ms)
PASS src/__tests__/slow.ts
ts-jest being slow
✓ creates many Timeout errors (2227ms)
Test Suites: 2 passed, 2 total
Tests: 3 passed, 3 total
Snapshots: 0 total
Time: 9.163s
Ran all test suites.
````
37 changes: 37 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "ts-jest-slow",
"version": "0.0.1",
"engines": {
"node": ">=6.10"
},
"scripts": {
"start": "npm run compile && node build/app.js",
"build": "npm run compile && cp config.json build",
"compile": "rm -rf ./build && tsc -p tsconfig-prod.json --diagnostics --pretty",
"compile:watch": "rm -rf ./build && tsc -p tsconfig.json --watch",
"test": "jest --forceExit --verbose"
},
"devDependencies": {
"jest": "^20.0.4",
"@types/jest": "^20.0.5",
"ts-jest": "^20.0.7",
"typescript": "^2.4.1"
},
"jest": {
"moduleFileExtensions": [
"js", "ts"
],
"transform": {
"\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "/__tests__/.*\\.(ts|tsx|js)$",
"testPathIgnorePatterns": [
"/node_modules/",
"<rootDir>/build/"
]
},
"dependencies": {
"@kwonoj/rxjs-testscheduler-compat": "^1.0.2",
"rxjs": "^5.4.2"
}
}
33 changes: 33 additions & 0 deletions src/__tests__/simple-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import "jest";
import "../index";

describe("ts-jest being slow", () => {

let times = 1000;

it(`throwing ${times} Errors`, () => {
const errors: Error[] = [];
for (let i = 0; i < times; i++) {
try {
throw new Error("Doesn't matter");
} catch (e) {
e.stack += "dummy";
// do nothing
errors.push(e);
}
}
})

it(`throwing ${times} Errors, not touching Error.stack`, () => {
const errors: Error[] = [];
for (let i = 0; i < times; i++) {
try {
throw new Error("Doesn't matter");
} catch (e) {
// do nothing
errors.push(e);
}
}
})

})
23 changes: 23 additions & 0 deletions src/__tests__/slow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import "jest";
import { TestScheduler } from "@kwonoj/rxjs-testscheduler-compat";
import { FooBar } from "../index";

describe("ts-jest being slow", () => {

it("creates many Timeout errors", () => {
let scheduler = new TestScheduler()
let foobar = new FooBar(scheduler, 1000);
let results = scheduler.startScheduler(() => foobar.obs, {
created: 0,
subscribed: 0,
unsubscribed: 1000 * 60,
});
expect(results.messages).toHaveLength(60 - 2);
// let sum = 0;
// for (let i = 0; i < 1000 * 1000; i++) {
// sum += eval("1 + { field: 2 }.field");
// }
})

})

50 changes: 50 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Observable } from "rxjs/Observable";
import { Scheduler } from "rxjs/Scheduler";

import "rxjs/add/observable/defer";
import "rxjs/add/observable/from";
import "rxjs/add/observable/timer";
import "rxjs/add/observable/range";
import "rxjs/add/observable/interval";
import "rxjs/add/observable/merge";
import "rxjs/add/observable/of";
import "rxjs/add/operator/bufferCount";
import "rxjs/add/operator/catch";
import "rxjs/add/operator/concat";
import "rxjs/add/operator/concatMap";
import "rxjs/add/operator/debounceTime";
import "rxjs/add/operator/do";
import "rxjs/add/operator/filter";
import "rxjs/add/operator/groupBy";
import "rxjs/add/operator/map";
import "rxjs/add/operator/merge";
import "rxjs/add/operator/mergeMap";
import "rxjs/add/operator/publish";
import "rxjs/add/operator/scan";
import "rxjs/add/operator/share";
import "rxjs/add/operator/startWith";
import "rxjs/add/operator/take";
import "rxjs/add/operator/takeUntil";
import "rxjs/add/operator/timeout";
import "rxjs/add/operator/toPromise";
import "rxjs/add/operator/zip";

export function box<T>(stuff: T) {
return [stuff];
}

export class FooBar {
public obs: Observable<number>
constructor(scheduler: Scheduler, time: number = 1000) {
this.obs = Observable
.interval(time, scheduler)
.flatMap(() => Observable.of(1)
.delay(time * 2, scheduler)
.timeout(time, scheduler)
.ignoreElements()
.catch(e => Observable.of(e))
)
}

}

21 changes: 21 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"allowJs": true,
"module": "commonjs",
"target": "es6",
"moduleResolution": "node",
"strictNullChecks": true,
"lib": [
"es2015"
],
"types": [
"jest"
],
"outDir": "build",
"declaration": false
},
"include": [
"src"
],
"compileOnSave": true
}

0 comments on commit 17fab50

Please sign in to comment.