From 970010f71362b7a34cb91809a5ce259415e90ed4 Mon Sep 17 00:00:00 2001 From: Dmitriy Schekhovtsov Date: Mon, 1 Feb 2016 23:42:36 +0200 Subject: [PATCH] feat(datepicker): datepicker fixed for 0-beta.2, closes #120, fixes #38 --- components/alert/alert.component.spec.ts | 1 - components/datepicker.ts | 18 + components/datepicker/datepicker-inner.ts | 71 ++- components/datepicker/datepicker-popup.ts | 36 +- components/datepicker/datepicker.ts | 65 ++- components/datepicker/daypicker.ts | 11 +- components/datepicker/index.ts | 29 - .../datepicker/datepicker-demo.html | 2 +- demo/components/datepicker/datepicker-demo.ts | 7 +- karma.conf.js | 2 +- make.js | 1 + ng2-bootstrap.ts | 2 +- package.json | 9 +- tsconfig.json | 2 +- tsd.d.ts | 1 + typings/es6-object.d.ts | 1 + typings/jasmine/jasmine.d.ts | 496 ++++++++++++++++++ typings/tsd.d.ts | 3 + webpack.config.js | 11 +- 19 files changed, 624 insertions(+), 144 deletions(-) create mode 100644 components/datepicker.ts delete mode 100644 components/datepicker/index.ts create mode 100644 typings/jasmine/jasmine.d.ts create mode 100644 typings/tsd.d.ts diff --git a/components/alert/alert.component.spec.ts b/components/alert/alert.component.spec.ts index fc71cbeb17..db77845c32 100644 --- a/components/alert/alert.component.spec.ts +++ b/components/alert/alert.component.spec.ts @@ -16,5 +16,4 @@ describe('Alert', () => { it('should have default type', inject([Alert], (alert:Alert) => { expect(alert.type).toEqual('warning'); })); - }); diff --git a/components/datepicker.ts b/components/datepicker.ts new file mode 100644 index 0000000000..0c07e0e748 --- /dev/null +++ b/components/datepicker.ts @@ -0,0 +1,18 @@ +/* +todo: general: +1. Popup +2. Keyboard support +3. custom-class attribute support +4. date-disabled attribute support +5. template-url attribute support + */ +//import {DatePickerInner} from './datepicker/datepicker-inner'; +import {DatePickerPopup} from './datepicker/datepicker-popup'; +//import {DayPicker} from './datepicker/daypicker'; +//import {MonthPicker} from './datepicker/monthpicker'; +//import {YearPicker} from './datepicker/yearpicker'; +import {DatePicker} from './datepicker/datepicker'; + +export {DatePickerPopup} from './datepicker/datepicker-popup'; +export {DatePicker} from './datepicker/datepicker'; +export const DATEPICKER_DIRECTIVES:Array = [DatePicker, DatePickerPopup]; diff --git a/components/datepicker/datepicker-inner.ts b/components/datepicker/datepicker-inner.ts index e7292939fc..3454650558 100644 --- a/components/datepicker/datepicker-inner.ts +++ b/components/datepicker/datepicker-inner.ts @@ -1,15 +1,8 @@ +import {Component, OnInit, EventEmitter, Input} from 'angular2/core'; import { - Component, View, Host, - OnInit, EventEmitter, - ElementRef, ViewContainerRef, - Self, Renderer, Input -} from 'angular2/core'; -import {CORE_DIRECTIVES, FORM_DIRECTIVES, - DefaultValueAccessor, NgIf, NgClass, NgModel + CORE_DIRECTIVES, FORM_DIRECTIVES, NgClass, NgModel } from 'angular2/common'; -import * as moment from 'moment'; - import {DateFormatter} from './date-formatter'; const FORMAT_DAY:string = 'DD'; @@ -54,9 +47,12 @@ const KEYS = { directives: [FORM_DIRECTIVES, CORE_DIRECTIVES, NgClass, NgModel] }) export class DatePickerInner implements OnInit { - @Input() public datepickerMode:string; - @Input() public startingDay:number; - @Input() public yearRange:number; + @Input() + public datepickerMode:string; + @Input() + public startingDay:number; + @Input() + public yearRange:number; public stepDay:any = {}; public stepMonth:any = {}; public stepYear:any = {}; @@ -67,23 +63,38 @@ export class DatePickerInner implements OnInit { private _activeDate:Date; private _initDate:Date; private activeDateId:string; - @Input() private minDate:Date; - @Input() private maxDate:Date; - @Input() private minMode:string; - @Input() private maxMode:string; - @Input() private showWeeks:boolean; - @Input() private formatDay:string; - @Input() private formatMonth:string; - @Input() private formatYear:string; - @Input() private formatDayHeader:string; - @Input() private formatDayTitle:string; - @Input() private formatMonthTitle:string; - @Input() private shortcutPropagation:boolean; + @Input() + private minDate:Date; + @Input() + private maxDate:Date; + @Input() + private minMode:string; + @Input() + private maxMode:string; + @Input() + private showWeeks:boolean; + @Input() + private formatDay:string; + @Input() + private formatMonth:string; + @Input() + private formatYear:string; + @Input() + private formatDayHeader:string; + @Input() + private formatDayTitle:string; + @Input() + private formatMonthTitle:string; + @Input() + private shortcutPropagation:boolean; // todo: change type during implementation - @Input() private customClass:any; + @Input() + private customClass:any; // todo: change type during implementation - @Input() private dateDisabled:any; - @Input() private templateUrl:string; + @Input() + private dateDisabled:any; + @Input() + private templateUrl:string; private refreshViewHandlerDay:Function; private compareHandlerDay:Function; @@ -93,7 +104,8 @@ export class DatePickerInner implements OnInit { private compareHandlerYear:Function; private update:EventEmitter = new EventEmitter(); - @Input() private get initDate():Date { + @Input() + private get initDate():Date { return this._initDate; } @@ -101,7 +113,8 @@ export class DatePickerInner implements OnInit { this._initDate = value; } - @Input() private get activeDate():Date { + @Input() + private get activeDate():Date { return this._activeDate; } diff --git a/components/datepicker/datepicker-popup.ts b/components/datepicker/datepicker-popup.ts index 5b0d9f2431..cf4b2afcb0 100644 --- a/components/datepicker/datepicker-popup.ts +++ b/components/datepicker/datepicker-popup.ts @@ -1,27 +1,22 @@ import { - Component, View, Host, Directive, + Component, Directive, OnInit, EventEmitter, ComponentRef, ViewEncapsulation, - ElementRef, ViewContainerRef, DynamicComponentLoader, - Self, Renderer + ElementRef, DynamicComponentLoader, + Self, Renderer, bind, Injector } from 'angular2/core'; -import {CORE_DIRECTIVES, FORM_DIRECTIVES, - DefaultValueAccessor, ControlValueAccessor, - NgIf, NgClass, NgModel, NgStyle, NgControl +import { + CORE_DIRECTIVES, FORM_DIRECTIVES, NgClass, NgModel, NgStyle } from 'angular2/common'; -// import {setProperty} from 'angular2/src/forms/directives/shared'; -// import {DOM} from 'angular2/src/dom/dom_adapter'; - -import {bind, Injectable, forwardRef, ResolvedBinding, Injector} from 'angular2/core'; +import {IAttribute} from '../common'; import {positionService} from '../position'; -import * as moment from 'moment'; -import {DatePickerInner} from './datepicker-inner'; -import {DayPicker} from './daypicker'; -import {MonthPicker} from './monthpicker'; -import {YearPicker} from './yearpicker'; +//import {DatePickerInner} from './datepicker-inner'; +//import {DayPicker} from './daypicker'; +//import {MonthPicker} from './monthpicker'; +//import {YearPicker} from './yearpicker'; import {DatePicker} from './datepicker'; class PopupOptions { @@ -34,7 +29,7 @@ class PopupOptions { } } -const datePickerPopupConfig:Object = { +const datePickerPopupConfig:IAttribute = { datepickerPopup: 'YYYY-MM-dd', currentText: 'Today', clearText: 'Clear', @@ -102,13 +97,13 @@ class PopupContainer { this.left = '0px'; let p = positionService .positionElements(hostEl.nativeElement, - this.element.nativeElement.children[0], - this.placement, false); + this.element.nativeElement.children[0], + this.placement, false); this.top = p.top + 'px'; } private getText(key:string):string { - return this[key + 'Text'] || datePickerPopupConfig[key + 'Text']; + return (this)[key + 'Text'] || datePickerPopupConfig[key + 'Text']; } private isDisabled(date:Date):boolean { @@ -128,7 +123,8 @@ export class DatePickerPopup implements OnInit { private _isOpen:boolean = false; private popup:Promise; - constructor(@Self() public cd:NgModel, public element:ElementRef, public renderer:Renderer, public loader:DynamicComponentLoader) { + constructor(@Self() + public cd:NgModel, public element:ElementRef, public renderer:Renderer, public loader:DynamicComponentLoader) { this.activeDate = cd.model; } diff --git a/components/datepicker/datepicker.ts b/components/datepicker/datepicker.ts index a85d762d70..b53e5ea7a2 100644 --- a/components/datepicker/datepicker.ts +++ b/components/datepicker/datepicker.ts @@ -1,19 +1,15 @@ +import {Component, Self, Input} from 'angular2/core'; import { - Component, View, Host, - EventEmitter, - ElementRef, ViewContainerRef, - Self, Renderer, - QueryList, Query, - Input -} from 'angular2/core'; -import {CORE_DIRECTIVES, FORM_DIRECTIVES, - ControlValueAccessor, NgIf, NgClass, NgModel + CORE_DIRECTIVES, + FORM_DIRECTIVES, + ControlValueAccessor, + NgModel } from 'angular2/common'; import * as moment from 'moment'; import {DatePickerInner} from './datepicker-inner'; -import {DatePickerPopup} from './datepicker-popup'; +//import {DatePickerPopup} from './datepicker-popup'; import {DayPicker} from './daypicker'; import {MonthPicker} from './monthpicker'; import {YearPicker} from './yearpicker'; @@ -52,27 +48,26 @@ import {YearPicker} from './yearpicker'; export class DatePicker implements ControlValueAccessor { private _activeDate:Date; - @Input() private datepickerMode:string; - @Input() private initDate:Date; - @Input() private minDate:Date; - @Input() private maxDate:Date; - @Input() private minMode:string; - @Input() private maxMode:string; - @Input() private showWeeks:boolean; - @Input() private formatDay:string; - @Input() private formatMonth:string; - @Input() private formatYear:string; - @Input() private formatDayHeader:string; - @Input() private formatDayTitle:string; - @Input() private formatMonthTitle:string; - @Input() private startingDay:number; - @Input() private yearRange:number; - @Input() private shortcutPropagation:boolean; + @Input() public datepickerMode:string; + @Input() public initDate:Date; + @Input() public minDate:Date; + @Input() public maxDate:Date; + @Input() public minMode:string; + @Input() public maxMode:string; + @Input() public showWeeks:boolean; + @Input() public formatDay:string; + @Input() public formatMonth:string; + @Input() public formatYear:string; + @Input() public formatDayHeader:string; + @Input() public formatDayTitle:string; + @Input() public formatMonthTitle:string; + @Input() public startingDay:number; + @Input() public yearRange:number; + @Input() public shortcutPropagation:boolean; // todo: change type during implementation - private customClass:any; + public customClass:any; // todo: change type during implementation - @Input() private dateDisabled:any; - private templateUrl:string; + @Input() public dateDisabled:any; constructor(@Self() public cd:NgModel) { // hack @@ -86,6 +81,7 @@ export class DatePicker implements ControlValueAccessor { public set activeDate(value:Date) { this._activeDate = value; this.cd.viewToModelUpdate(moment(this.activeDate).toDate()); + //this.cd.viewToModelUpdate(this._activeDate); } private onUpdate(event:any) { @@ -102,19 +98,21 @@ export class DatePicker implements ControlValueAccessor { // // this.activeDate = value; // } - if (value === this.activeDate) { + if (value === this._activeDate) { return; } if (value && value instanceof Date) { this.activeDate = value; return; } - this.activeDate = value ? new Date(value) : null; + this.activeDate = value ? new Date(value) : null; } - onChange = (_:any) => {}; - onTouched = () => {}; + onChange = (_:any) => { + }; + onTouched = () => { + }; registerOnChange(fn:(_:any) => {}):void { this.onChange = fn; @@ -123,5 +121,4 @@ export class DatePicker implements ControlValueAccessor { registerOnTouched(fn:() => {}):void { this.onTouched = fn; } - } diff --git a/components/datepicker/daypicker.ts b/components/datepicker/daypicker.ts index 5c33d0adbe..0e25e816ef 100644 --- a/components/datepicker/daypicker.ts +++ b/components/datepicker/daypicker.ts @@ -1,12 +1,5 @@ -import { - Component, View, Host, Directive, - OnInit, EventEmitter, - ElementRef, ViewContainerRef, - Self, Renderer -} from 'angular2/core'; -import {CORE_DIRECTIVES, FORM_DIRECTIVES, - DefaultValueAccessor, NgIf, NgClass, NgModel -} from 'angular2/common'; +import {Component, OnInit} from 'angular2/core'; +import {CORE_DIRECTIVES, FORM_DIRECTIVES, NgClass} from 'angular2/common'; import {Ng2BootstrapConfig, Ng2BootstrapTheme} from '../ng2-bootstrap-config'; import {DatePickerInner} from './datepicker-inner'; diff --git a/components/datepicker/index.ts b/components/datepicker/index.ts deleted file mode 100644 index 0d1a579b32..0000000000 --- a/components/datepicker/index.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { - Component, View, Host, - EventEmitter, - ElementRef, ViewContainerRef, - Self, Renderer, - QueryList, Query -} from 'angular2/core'; -import {CORE_DIRECTIVES, FORM_DIRECTIVES, - DefaultValueAccessor, NgIf, NgClass, NgModel -} from 'angular2/common'; - -import * as moment from 'moment'; - -/* -todo: general: -1. Popup -2. Keyboard support -3. custom-class attribute support -4. date-disabled attribute support -5. template-url attribute support - */ -import {DatePickerInner} from './datepicker-inner'; -import {DatePickerPopup} from './datepicker-popup'; -import {DayPicker} from './daypicker'; -import {MonthPicker} from './monthpicker'; -import {YearPicker} from './yearpicker'; -import {DatePicker} from './datepicker'; - -export const datepicker:Array = [DatePicker, DatePickerPopup]; diff --git a/demo/components/datepicker/datepicker-demo.html b/demo/components/datepicker/datepicker-demo.html index 0d2a6c2374..3bf1abd388 100644 --- a/demo/components/datepicker/datepicker-demo.html +++ b/demo/components/datepicker/datepicker-demo.html @@ -12,7 +12,7 @@
-
Selected date is: {{getDate() | date:'fullDate'}}
+
Selected date is: {{dt | date:'fullDate'}}

Inline

diff --git a/demo/components/datepicker/datepicker-demo.ts b/demo/components/datepicker/datepicker-demo.ts index aad47d5227..b576a3f905 100644 --- a/demo/components/datepicker/datepicker-demo.ts +++ b/demo/components/datepicker/datepicker-demo.ts @@ -1,10 +1,10 @@ /// -import {Component, View} from 'angular2/core'; +import {Component} from 'angular2/core'; import {CORE_DIRECTIVES, FORM_DIRECTIVES} from 'angular2/common'; import * as moment from 'moment'; -import {datepicker} from '../../../ng2-bootstrap'; +import {DATEPICKER_DIRECTIVES} from '../../../ng2-bootstrap'; // webpack html imports let template = require('./datepicker-demo.html'); @@ -12,9 +12,8 @@ let template = require('./datepicker-demo.html'); @Component({ selector: 'datepicker-demo', template: template, - directives: [datepicker, CORE_DIRECTIVES, FORM_DIRECTIVES] + directives: [DATEPICKER_DIRECTIVES, CORE_DIRECTIVES, FORM_DIRECTIVES] }) - export class DatepickerDemo { public dt:Date = new Date(); private minDate:Date = null; diff --git a/karma.conf.js b/karma.conf.js index 2bdde0470b..0a9d4fa7fa 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -94,5 +94,5 @@ module.exports = function (config) { }; function root(p) { - path.join(__dirname, p); + return path.join(__dirname, p); } diff --git a/make.js b/make.js index eca78c5dfd..da91747fb7 100755 --- a/make.js +++ b/make.js @@ -51,6 +51,7 @@ function getSystemJsBundleConfig(cb) { memo[`${__dirname}/node_modules/${currentValue}/*`] = {build: false}; return memo; }, {}); + config.meta.moment = {build: false}; return cb(null, config); } diff --git a/ng2-bootstrap.ts b/ng2-bootstrap.ts index 4f9c0224c6..4b1ad7d134 100644 --- a/ng2-bootstrap.ts +++ b/ng2-bootstrap.ts @@ -3,7 +3,7 @@ export * from './components/alert'; export * from './components/buttons'; export * from './components/carousel'; export * from './components/collapse'; -export * from './components/datepicker/index'; +export * from './components/datepicker'; export * from './components/dropdown'; export * from './components/pagination'; export * from './components/progressbar'; diff --git a/package.json b/package.json index 279301ef63..3c04f7eefd 100644 --- a/package.json +++ b/package.json @@ -6,10 +6,10 @@ "compile": "node ./node_modules/typescript/bin/tsc", "prepublish": "gulp clean && ./node_modules/.bin/tsc && ./make.js", "build:prod": "NODE_ENV=production webpack --progress --color", - "build:dev": "NODE_ENV=production webpack --progress --color", + "build:dev": "webpack --progress --color", "serve:dev": "webpack-dev-server --hot --inline --colors --display-error-details --display-cached", "serve:prod": "NODE_ENV=production webpack-dev-server --hot --inline --colors --display-error-details --display-cached", - "start": "npm run build:dev", + "start": "npm run serve:dev", "pretest": "gulp lint", "test": "NODE_ENV=test karma start" }, @@ -31,7 +31,9 @@ "url": "https://github.com/valor-software/ng2-bootstrap/issues" }, "homepage": "https://github.com/valor-software/ng2-bootstrap#readme", - "dependencies": {}, + "dependencies": { + "moment": "2.11.1" + }, "peerDependencies": { "angular2": "2.0.0-beta.2" }, @@ -67,7 +69,6 @@ "karma-webpack": "1.7.0", "markdown-loader": "0.1.7", "marked": "0.3.5", - "moment": "2.11.1", "phantomjs-polyfill": "0.0.1", "phantomjs-prebuilt": "2.1.3", "pre-commit": "1.1.2", diff --git a/tsconfig.json b/tsconfig.json index bfc7c2d50a..23c9e222aa 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,6 @@ "emitDecoratorMetadata": true, "experimentalDecorators": true, "noImplicitAny": true, - "suppressImplicitAnyIndexErrors":true, "listFiles": false, "noLib": false }, @@ -17,6 +16,7 @@ "node_modules" ], "files": [ + "./tsd.d.ts", "./ng2-bootstrap.ts" ] } diff --git a/tsd.d.ts b/tsd.d.ts index 897f829a38..cc5f2b1953 100644 --- a/tsd.d.ts +++ b/tsd.d.ts @@ -1,2 +1,3 @@ /// /// +/// diff --git a/typings/es6-object.d.ts b/typings/es6-object.d.ts index 50cd74e89e..c282db0388 100644 --- a/typings/es6-object.d.ts +++ b/typings/es6-object.d.ts @@ -22,3 +22,4 @@ interface ObjectConstructor { */ setPrototypeOf(o: any, proto: any): any; } + diff --git a/typings/jasmine/jasmine.d.ts b/typings/jasmine/jasmine.d.ts new file mode 100644 index 0000000000..b17c68d8b5 --- /dev/null +++ b/typings/jasmine/jasmine.d.ts @@ -0,0 +1,496 @@ +// Type definitions for Jasmine 2.2 +// Project: http://jasmine.github.io/ +// Definitions by: Boris Yankov , Theodore Brown , David Pärsson +// Definitions: https://github.com/borisyankov/DefinitelyTyped + + +// For ddescribe / iit use : https://github.com/borisyankov/DefinitelyTyped/blob/master/karma-jasmine/karma-jasmine.d.ts + +declare function describe(description: string, specDefinitions: () => void): void; +declare function fdescribe(description: string, specDefinitions: () => void): void; +declare function xdescribe(description: string, specDefinitions: () => void): void; + +declare function it(expectation: string, assertion?: () => void, timeout?: number): void; +declare function it(expectation: string, assertion?: (done: () => void) => void, timeout?: number): void; +declare function fit(expectation: string, assertion?: () => void, timeout?: number): void; +declare function fit(expectation: string, assertion?: (done: () => void) => void, timeout?: number): void; +declare function xit(expectation: string, assertion?: () => void, timeout?: number): void; +declare function xit(expectation: string, assertion?: (done: () => void) => void, timeout?: number): void; + +/** If you call the function pending anywhere in the spec body, no matter the expectations, the spec will be marked pending. */ +declare function pending(reason?: string): void; + +declare function beforeEach(action: () => void, timeout?: number): void; +declare function beforeEach(action: (done: () => void) => void, timeout?: number): void; +declare function afterEach(action: () => void, timeout?: number): void; +declare function afterEach(action: (done: () => void) => void, timeout?: number): void; + +declare function beforeAll(action: () => void, timeout?: number): void; +declare function beforeAll(action: (done: () => void) => void, timeout?: number): void; +declare function afterAll(action: () => void, timeout?: number): void; +declare function afterAll(action: (done: () => void) => void, timeout?: number): void; + +declare function expect(spy: Function): jasmine.Matchers; +declare function expect(actual: any): jasmine.Matchers; + +declare function fail(e?: any): void; + +declare function spyOn(object: any, method: string): jasmine.Spy; + +declare function runs(asyncMethod: Function): void; +declare function waitsFor(latchMethod: () => boolean, failureMessage?: string, timeout?: number): void; +declare function waits(timeout?: number): void; + +declare module jasmine { + + var clock: () => Clock; + + function any(aclass: any): Any; + function anything(): Any; + function arrayContaining(sample: any[]): ArrayContaining; + function objectContaining(sample: any): ObjectContaining; + function createSpy(name: string, originalFn?: Function): Spy; + function createSpyObj(baseName: string, methodNames: any[]): any; + function createSpyObj(baseName: string, methodNames: any[]): T; + function pp(value: any): string; + function getEnv(): Env; + function addCustomEqualityTester(equalityTester: CustomEqualityTester): void; + function addMatchers(matchers: CustomMatcherFactories): void; + function stringMatching(str: string): Any; + function stringMatching(str: RegExp): Any; + + interface Any { + + new (expectedClass: any): any; + + jasmineMatches(other: any): boolean; + jasmineToString(): string; + } + + // taken from TypeScript lib.core.es6.d.ts, applicable to CustomMatchers.contains() + interface ArrayLike { + length: number; + [n: number]: T; + } + + interface ArrayContaining { + new (sample: any[]): any; + + asymmetricMatch(other: any): boolean; + jasmineToString(): string; + } + + interface ObjectContaining { + new (sample: any): any; + + jasmineMatches(other: any, mismatchKeys: any[], mismatchValues: any[]): boolean; + jasmineToString(): string; + } + + interface Block { + + new (env: Env, func: SpecFunction, spec: Spec): any; + + execute(onComplete: () => void): void; + } + + interface WaitsBlock extends Block { + new (env: Env, timeout: number, spec: Spec): any; + } + + interface WaitsForBlock extends Block { + new (env: Env, timeout: number, latchFunction: SpecFunction, message: string, spec: Spec): any; + } + + interface Clock { + install(): void; + uninstall(): void; + /** Calls to any registered callback are triggered when the clock is ticked forward via the jasmine.clock().tick function, which takes a number of milliseconds. */ + tick(ms: number): void; + mockDate(date?: Date): void; + } + + interface CustomEqualityTester { + (first: any, second: any): boolean; + } + + interface CustomMatcher { + compare(actual: T, expected: T): CustomMatcherResult; + compare(actual: any, expected: any): CustomMatcherResult; + } + + interface CustomMatcherFactory { + (util: MatchersUtil, customEqualityTesters: Array): CustomMatcher; + } + + interface CustomMatcherFactories { + [index: string]: CustomMatcherFactory; + } + + interface CustomMatcherResult { + pass: boolean; + message?: string; + } + + interface MatchersUtil { + equals(a: any, b: any, customTesters?: Array): boolean; + contains(haystack: ArrayLike | string, needle: any, customTesters?: Array): boolean; + buildFailureMessage(matcherName: string, isNot: boolean, actual: any, ...expected: Array): string; + } + + interface Env { + setTimeout: any; + clearTimeout: void; + setInterval: any; + clearInterval: void; + updateInterval: number; + + currentSpec: Spec; + + matchersClass: Matchers; + + version(): any; + versionString(): string; + nextSpecId(): number; + addReporter(reporter: Reporter): void; + execute(): void; + describe(description: string, specDefinitions: () => void): Suite; + // ddescribe(description: string, specDefinitions: () => void): Suite; Not a part of jasmine. Angular team adds these + beforeEach(beforeEachFunction: () => void): void; + beforeAll(beforeAllFunction: () => void): void; + currentRunner(): Runner; + afterEach(afterEachFunction: () => void): void; + afterAll(afterAllFunction: () => void): void; + xdescribe(desc: string, specDefinitions: () => void): XSuite; + it(description: string, func: () => void): Spec; + // iit(description: string, func: () => void): Spec; Not a part of jasmine. Angular team adds these + xit(desc: string, func: () => void): XSpec; + compareRegExps_(a: RegExp, b: RegExp, mismatchKeys: string[], mismatchValues: string[]): boolean; + compareObjects_(a: any, b: any, mismatchKeys: string[], mismatchValues: string[]): boolean; + equals_(a: any, b: any, mismatchKeys: string[], mismatchValues: string[]): boolean; + contains_(haystack: any, needle: any): boolean; + addCustomEqualityTester(equalityTester: CustomEqualityTester): void; + addMatchers(matchers: CustomMatcherFactories): void; + specFilter(spec: Spec): boolean; + } + + interface FakeTimer { + + new (): any; + + reset(): void; + tick(millis: number): void; + runFunctionsWithinRange(oldMillis: number, nowMillis: number): void; + scheduleFunction(timeoutKey: any, funcToCall: () => void, millis: number, recurring: boolean): void; + } + + interface HtmlReporter { + new (): any; + } + + interface HtmlSpecFilter { + new (): any; + } + + interface Result { + type: string; + } + + interface NestedResults extends Result { + description: string; + + totalCount: number; + passedCount: number; + failedCount: number; + + skipped: boolean; + + rollupCounts(result: NestedResults): void; + log(values: any): void; + getItems(): Result[]; + addResult(result: Result): void; + passed(): boolean; + } + + interface MessageResult extends Result { + values: any; + trace: Trace; + } + + interface ExpectationResult extends Result { + matcherName: string; + passed(): boolean; + expected: any; + actual: any; + message: string; + trace: Trace; + } + + interface Trace { + name: string; + message: string; + stack: any; + } + + interface PrettyPrinter { + + new (): any; + + format(value: any): void; + iterateObject(obj: any, fn: (property: string, isGetter: boolean) => void): void; + emitScalar(value: any): void; + emitString(value: string): void; + emitArray(array: any[]): void; + emitObject(obj: any): void; + append(value: any): void; + } + + interface StringPrettyPrinter extends PrettyPrinter { + } + + interface Queue { + + new (env: any): any; + + env: Env; + ensured: boolean[]; + blocks: Block[]; + running: boolean; + index: number; + offset: number; + abort: boolean; + + addBefore(block: Block, ensure?: boolean): void; + add(block: any, ensure?: boolean): void; + insertNext(block: any, ensure?: boolean): void; + start(onComplete?: () => void): void; + isRunning(): boolean; + next_(): void; + results(): NestedResults; + } + + interface Matchers { + + new (env: Env, actual: any, spec: Env, isNot?: boolean): any; + + env: Env; + actual: any; + spec: Env; + isNot?: boolean; + message(): any; + + toBe(expected: any, expectationFailOutput?: any): boolean; + toEqual(expected: any, expectationFailOutput?: any): boolean; + toMatch(expected: string | RegExp, expectationFailOutput?: any): boolean; + toBeDefined(expectationFailOutput?: any): boolean; + toBeUndefined(expectationFailOutput?: any): boolean; + toBeNull(expectationFailOutput?: any): boolean; + toBeNaN(): boolean; + toBeTruthy(expectationFailOutput?: any): boolean; + toBeFalsy(expectationFailOutput?: any): boolean; + toHaveBeenCalled(): boolean; + toHaveBeenCalledWith(...params: any[]): boolean; + toHaveBeenCalledTimes(expected: number): boolean; + toContain(expected: any, expectationFailOutput?: any): boolean; + toBeLessThan(expected: number, expectationFailOutput?: any): boolean; + toBeGreaterThan(expected: number, expectationFailOutput?: any): boolean; + toBeCloseTo(expected: number, precision: any, expectationFailOutput?: any): boolean; + toThrow(expected?: any): boolean; + toThrowError(message?: string | RegExp): boolean; + toThrowError(expected?: Error, message?: string | RegExp): boolean; + not: Matchers; + + Any: Any; + } + + interface Reporter { + reportRunnerStarting(runner: Runner): void; + reportRunnerResults(runner: Runner): void; + reportSuiteResults(suite: Suite): void; + reportSpecStarting(spec: Spec): void; + reportSpecResults(spec: Spec): void; + log(str: string): void; + } + + interface MultiReporter extends Reporter { + addReporter(reporter: Reporter): void; + } + + interface Runner { + + new (env: Env): any; + + execute(): void; + beforeEach(beforeEachFunction: SpecFunction): void; + afterEach(afterEachFunction: SpecFunction): void; + beforeAll(beforeAllFunction: SpecFunction): void; + afterAll(afterAllFunction: SpecFunction): void; + finishCallback(): void; + addSuite(suite: Suite): void; + add(block: Block): void; + specs(): Spec[]; + suites(): Suite[]; + topLevelSuites(): Suite[]; + results(): NestedResults; + } + + interface SpecFunction { + (spec?: Spec): void; + } + + interface SuiteOrSpec { + id: number; + env: Env; + description: string; + queue: Queue; + } + + interface Spec extends SuiteOrSpec { + + new (env: Env, suite: Suite, description: string): any; + + suite: Suite; + + afterCallbacks: SpecFunction[]; + spies_: Spy[]; + + results_: NestedResults; + matchersClass: Matchers; + + getFullName(): string; + results(): NestedResults; + log(arguments: any): any; + runs(func: SpecFunction): Spec; + addToQueue(block: Block): void; + addMatcherResult(result: Result): void; + expect(actual: any): any; + waits(timeout: number): Spec; + waitsFor(latchFunction: SpecFunction, timeoutMessage?: string, timeout?: number): Spec; + fail(e?: any): void; + getMatchersClass_(): Matchers; + addMatchers(matchersPrototype: CustomMatcherFactories): void; + finishCallback(): void; + finish(onComplete?: () => void): void; + after(doAfter: SpecFunction): void; + execute(onComplete?: () => void): any; + addBeforesAndAftersToQueue(): void; + explodes(): void; + spyOn(obj: any, methodName: string, ignoreMethodDoesntExist: boolean): Spy; + removeAllSpies(): void; + } + + interface XSpec { + id: number; + runs(): void; + } + + interface Suite extends SuiteOrSpec { + + new (env: Env, description: string, specDefinitions: () => void, parentSuite: Suite): any; + + parentSuite: Suite; + + getFullName(): string; + finish(onComplete?: () => void): void; + beforeEach(beforeEachFunction: SpecFunction): void; + afterEach(afterEachFunction: SpecFunction): void; + beforeAll(beforeAllFunction: SpecFunction): void; + afterAll(afterAllFunction: SpecFunction): void; + results(): NestedResults; + add(suiteOrSpec: SuiteOrSpec): void; + specs(): Spec[]; + suites(): Suite[]; + children(): any[]; + execute(onComplete?: () => void): void; + } + + interface XSuite { + execute(): void; + } + + interface Spy { + (...params: any[]): any; + + identity: string; + and: SpyAnd; + calls: Calls; + mostRecentCall: { args: any[]; }; + argsForCall: any[]; + wasCalled: boolean; + } + + interface SpyAnd { + /** By chaining the spy with and.callThrough, the spy will still track all calls to it but in addition it will delegate to the actual implementation. */ + callThrough(): Spy; + /** By chaining the spy with and.returnValue, all calls to the function will return a specific value. */ + returnValue(val: any): void; + /** By chaining the spy with and.callFake, all calls to the spy will delegate to the supplied function. */ + callFake(fn: Function): Spy; + /** By chaining the spy with and.throwError, all calls to the spy will throw the specified value. */ + throwError(msg: string): void; + /** When a calling strategy is used for a spy, the original stubbing behavior can be returned at any time with and.stub. */ + stub(): Spy; + } + + interface Calls { + /** By chaining the spy with calls.any(), will return false if the spy has not been called at all, and then true once at least one call happens. **/ + any(): boolean; + /** By chaining the spy with calls.count(), will return the number of times the spy was called **/ + count(): number; + /** By chaining the spy with calls.argsFor(), will return the arguments passed to call number index **/ + argsFor(index: number): any[]; + /** By chaining the spy with calls.allArgs(), will return the arguments to all calls **/ + allArgs(): any[]; + /** By chaining the spy with calls.all(), will return the context (the this) and arguments passed all calls **/ + all(): CallInfo[]; + /** By chaining the spy with calls.mostRecent(), will return the context (the this) and arguments for the most recent call **/ + mostRecent(): CallInfo; + /** By chaining the spy with calls.first(), will return the context (the this) and arguments for the first call **/ + first(): CallInfo; + /** By chaining the spy with calls.reset(), will clears all tracking for a spy **/ + reset(): void; + } + + interface CallInfo { + /** The context (the this) for the call */ + object: any; + /** All arguments passed to the call */ + args: any[]; + } + + interface Util { + inherit(childClass: Function, parentClass: Function): any; + formatException(e: any): any; + htmlEscape(str: string): string; + argsToArray(args: any): any; + extend(destination: any, source: any): any; + } + + interface JsApiReporter extends Reporter { + + started: boolean; + finished: boolean; + result: any; + messages: any; + + new (): any; + + suites(): Suite[]; + summarize_(suiteOrSpec: SuiteOrSpec): any; + results(): any; + resultsForSpec(specId: any): any; + log(str: any): any; + resultsForSpecs(specIds: any): any; + summarizeResult_(result: any): any; + } + + interface Jasmine { + Spec: Spec; + clock: Clock; + util: Util; + } + + export var HtmlReporter: HtmlReporter; + export var HtmlSpecFilter: HtmlSpecFilter; + export var DEFAULT_TIMEOUT_INTERVAL: number; +} diff --git a/typings/tsd.d.ts b/typings/tsd.d.ts new file mode 100644 index 0000000000..6e07b26b9b --- /dev/null +++ b/typings/tsd.d.ts @@ -0,0 +1,3 @@ +/// +/// +/// diff --git a/webpack.config.js b/webpack.config.js index febff03941..0a01369475 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -87,15 +87,6 @@ var config = { } }, module: { - preLoaders: [ - { - test: /\.js$/, - loader: 'source-map-loader', - exclude: [ - root('node_modules/rxjs') - ] - } - ], loaders: [ // support markdown {test: /\.md$/, loader: 'html?minimize=false!markdown'}, @@ -180,5 +171,5 @@ config.pushPlugins(); module.exports = config; function root(p) { - path.join(__dirname, p); + return path.join(__dirname, p); }