From 7b6c1e33ed6515f3d723056d5bde498d0bdffa46 Mon Sep 17 00:00:00 2001 From: Thomas Puttkamer Date: Mon, 13 Nov 2017 18:48:47 +0100 Subject: [PATCH 1/8] added type definitions for mochaccino --- types/mochaccino/index.d.ts | 71 +++++++++++++++++++++++++ types/mochaccino/mochaccino-tests.ts | 77 ++++++++++++++++++++++++++++ types/mochaccino/tsconfig.json | 22 ++++++++ types/mochaccino/tslint.json | 1 + 4 files changed, 171 insertions(+) create mode 100644 types/mochaccino/index.d.ts create mode 100644 types/mochaccino/mochaccino-tests.ts create mode 100644 types/mochaccino/tsconfig.json create mode 100644 types/mochaccino/tslint.json diff --git a/types/mochaccino/index.d.ts b/types/mochaccino/index.d.ts new file mode 100644 index 0000000000..9e40c8ef8a --- /dev/null +++ b/types/mochaccino/index.d.ts @@ -0,0 +1,71 @@ +// Type definitions for mochaccino 1.2 +// Project: https://github.com/pawelgalazka/mochaccino#readme +// Definitions by: Thomas-P +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + + +declare module 'mochaccino' { + + import * as Sinon from "sinon"; + + interface Expect { + not: Expect; + + toBe(arg: T): void; + + toContain(arg: T): void; + + toEqual(arg: T): void; + + toHaveBeenCalled(): void; + + toHaveBeenCalledWith(...arg: any[]): void; + + toHaveBeenCalledTimes(callCount: number): void; + + toBeDefined(): void; + + toBeUndefined(): void; + + toBeNull(): void; + + toBeTruthy(): void; + + toBeFalsy(): void; + + toBeLessThan(other: number): void; + + toBeGreaterThan(other: number): void; + + toThrow(): void; + + toThrowError(errType: T): void; + + toMatch(matchExpression: T): void; + } + + + interface SpyProxy { + and: SpyProxy; + spyProxy: true; + getSubject: () => Sinon.SinonStub; + callThrough: () => void; + returnValue: (obj: any) => void; + callFake: (fake: Function) => void; + } + + interface Dom { + exposedProperties: ['window', 'navigator', 'document']; + create: () => void; + destroy: () => void; + clear: () => void; + } + + export function expect(value: T): Expect; + + export function spy(...config: any[]): (...args: any[]) => SpyProxy; + + export const dom: Dom; +} diff --git a/types/mochaccino/mochaccino-tests.ts b/types/mochaccino/mochaccino-tests.ts new file mode 100644 index 0000000000..0ff4aa6023 --- /dev/null +++ b/types/mochaccino/mochaccino-tests.ts @@ -0,0 +1,77 @@ +import {dom, expect, spy} from 'mochaccino'; + + +/** + * spy test + * + */ +const obj = { + funcName: () => { + } +}; + +let s = spy(); +s(1, 2); +expect(s).toHaveBeenCalledWith(1, 2); +spy(obj, 'funcName'); +obj.funcName(); +expect(obj.funcName).toHaveBeenCalled(); +/***********************/ +s = spy(); +s(); +expect(s).toHaveBeenCalled(); +/***********************/ +s(obj, 'funcName').and.callFake(() => { + return 123; +}); +expect(obj.funcName()).toEqual(123); +spy(obj, 'funcName'); + +expect(obj.funcName).toHaveBeenCalled(); +/***********************/ +s(obj, 'funcName').and.callThrough(); +/***********************/ +s(obj, 'funcName').and.returnValue(5); +/***********************/ + + +/** + * dom test + */ +dom.create(); +dom.destroy(); +dom.clear(); + + +/** + * expect test + * + */ + +const a: number = 1; +const b: boolean = true; +const c: number = 2; +const f = () => { +}; +const ErrorType = new Error(); +const regexp = /123/; + +expect(true).toBeTruthy(); +expect(a).toBe(b); +expect(a).toEqual(b); +expect(a).toBeTruthy(); +expect(a).toBeFalsy(); +expect(a).toBeDefined(); +expect(a).toBeUndefined(); +expect(a).toBeNull(); +expect(a).toBeLessThan(c); +expect(a).toBeGreaterThan(c); +expect([1, 2]).toContain(1); +expect(f).toThrow(); +expect(f).toThrowError(ErrorType); +expect(s).toMatch(regexp); + + +expect(s).toHaveBeenCalled(); +expect(s).toHaveBeenCalledWith(1, '23'); +expect(s).toHaveBeenCalledTimes(55); diff --git a/types/mochaccino/tsconfig.json b/types/mochaccino/tsconfig.json new file mode 100644 index 0000000000..78893fab7d --- /dev/null +++ b/types/mochaccino/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": ["sinon"], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "mochaccino-tests.ts" + ] +} diff --git a/types/mochaccino/tslint.json b/types/mochaccino/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/mochaccino/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 79380b7a46b15498cd7fe8608c0f33bb996f9336 Mon Sep 17 00:00:00 2001 From: Thomas Puttkamer Date: Mon, 13 Nov 2017 18:58:24 +0100 Subject: [PATCH 2/8] fix import of sinon types --- types/mochaccino/index.d.ts | 2 +- types/mochaccino/tsconfig.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/types/mochaccino/index.d.ts b/types/mochaccino/index.d.ts index 9e40c8ef8a..83cb9378f0 100644 --- a/types/mochaccino/index.d.ts +++ b/types/mochaccino/index.d.ts @@ -3,7 +3,7 @@ // Definitions by: Thomas-P // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// +/// declare module 'mochaccino' { diff --git a/types/mochaccino/tsconfig.json b/types/mochaccino/tsconfig.json index 78893fab7d..2e819aca80 100644 --- a/types/mochaccino/tsconfig.json +++ b/types/mochaccino/tsconfig.json @@ -11,7 +11,7 @@ "typeRoots": [ "../" ], - "types": ["sinon"], + "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true }, From 1534066e5497f8bacd057a36858515988242e770 Mon Sep 17 00:00:00 2001 From: Thomas Puttkamer Date: Mon, 13 Nov 2017 19:05:34 +0100 Subject: [PATCH 3/8] added TypeScript version to remove error on test --- types/mochaccino/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/mochaccino/index.d.ts b/types/mochaccino/index.d.ts index 83cb9378f0..7f1819a739 100644 --- a/types/mochaccino/index.d.ts +++ b/types/mochaccino/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/pawelgalazka/mochaccino#readme // Definitions by: Thomas-P // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 /// From 1a32e823724220bbba071356b3fe65fda37b8bfb Mon Sep 17 00:00:00 2001 From: Thomas Puttkamer Date: Mon, 13 Nov 2017 19:13:26 +0100 Subject: [PATCH 4/8] added strictFunctionTypes --- types/mochaccino/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/types/mochaccino/tsconfig.json b/types/mochaccino/tsconfig.json index 2e819aca80..166b3f4203 100644 --- a/types/mochaccino/tsconfig.json +++ b/types/mochaccino/tsconfig.json @@ -7,6 +7,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" From f0c9f7b5fed6870712528457817202044757fe95 Mon Sep 17 00:00:00 2001 From: Thomas Puttkamer Date: Mon, 13 Nov 2017 19:21:52 +0100 Subject: [PATCH 5/8] fixed errors on travis test #1 --- types/mochaccino/index.d.ts | 105 +++++++++++++++--------------------- 1 file changed, 43 insertions(+), 62 deletions(-) diff --git a/types/mochaccino/index.d.ts b/types/mochaccino/index.d.ts index 7f1819a739..8ad9e86018 100644 --- a/types/mochaccino/index.d.ts +++ b/types/mochaccino/index.d.ts @@ -6,67 +6,48 @@ /// +import * as Sinon from "sinon"; -declare module 'mochaccino' { - - import * as Sinon from "sinon"; - - interface Expect { - not: Expect; - - toBe(arg: T): void; - - toContain(arg: T): void; - - toEqual(arg: T): void; - - toHaveBeenCalled(): void; - - toHaveBeenCalledWith(...arg: any[]): void; - - toHaveBeenCalledTimes(callCount: number): void; - - toBeDefined(): void; - - toBeUndefined(): void; - - toBeNull(): void; - - toBeTruthy(): void; - - toBeFalsy(): void; - - toBeLessThan(other: number): void; - - toBeGreaterThan(other: number): void; - - toThrow(): void; - - toThrowError(errType: T): void; - - toMatch(matchExpression: T): void; - } - - - interface SpyProxy { - and: SpyProxy; - spyProxy: true; - getSubject: () => Sinon.SinonStub; - callThrough: () => void; - returnValue: (obj: any) => void; - callFake: (fake: Function) => void; - } - - interface Dom { - exposedProperties: ['window', 'navigator', 'document']; - create: () => void; - destroy: () => void; - clear: () => void; - } - - export function expect(value: T): Expect; - - export function spy(...config: any[]): (...args: any[]) => SpyProxy; - - export const dom: Dom; +interface Expect { + not: Expect; + toBe(arg: any): void; + toContain(arg: any): void; + toEqual(arg: any): void; + toHaveBeenCalled(): void; + toHaveBeenCalledWith(...arg: any[]): void; + toHaveBeenCalledTimes(callCount: number): void; + toBeDefined(): void; + toBeUndefined(): void; + toBeNull(): void; + toBeTruthy(): void; + toBeFalsy(): void; + toBeLessThan(other: number): void; + toBeGreaterThan(other: number): void; + toThrow(): void; + toThrowError(errType: any): void; + toMatch(matchExpression: any): void; } + + +interface SpyProxy { + and: SpyProxy; + spyProxy: true; + getSubject: () => Sinon.SinonStub; + callThrough: () => void; + returnValue: (obj: any) => void; + callFake: (fake: Function) => void; +} + +interface Dom { + exposedProperties: ['window', 'navigator', 'document']; + create: () => void; + destroy: () => void; + clear: () => void; +} + +export function expect(value: any): Expect; + +export function spy(...config: any[]): (...args: any[]) => SpyProxy; + +export const dom: Dom; + From 5a5924a43775ac2ba0125f0831514a4499d47442 Mon Sep 17 00:00:00 2001 From: Thomas Puttkamer Date: Mon, 13 Nov 2017 19:23:58 +0100 Subject: [PATCH 6/8] travis fix #2 --- types/mochaccino/mochaccino-tests.ts | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/types/mochaccino/mochaccino-tests.ts b/types/mochaccino/mochaccino-tests.ts index 0ff4aa6023..744c20652c 100644 --- a/types/mochaccino/mochaccino-tests.ts +++ b/types/mochaccino/mochaccino-tests.ts @@ -1,6 +1,4 @@ -import {dom, expect, spy} from 'mochaccino'; - - +import { dom, expect, spy } from 'mochaccino'; /** * spy test * @@ -9,7 +7,6 @@ const obj = { funcName: () => { } }; - let s = spy(); s(1, 2); expect(s).toHaveBeenCalledWith(1, 2); @@ -33,29 +30,23 @@ s(obj, 'funcName').and.callThrough(); /***********************/ s(obj, 'funcName').and.returnValue(5); /***********************/ - - /** * dom test */ dom.create(); dom.destroy(); dom.clear(); - - /** * expect test * */ - -const a: number = 1; -const b: boolean = true; -const c: number = 2; +const a = 1; +const b = true; +const c = 2; const f = () => { }; const ErrorType = new Error(); const regexp = /123/; - expect(true).toBeTruthy(); expect(a).toBe(b); expect(a).toEqual(b); @@ -70,8 +61,6 @@ expect([1, 2]).toContain(1); expect(f).toThrow(); expect(f).toThrowError(ErrorType); expect(s).toMatch(regexp); - - expect(s).toHaveBeenCalled(); expect(s).toHaveBeenCalledWith(1, '23'); expect(s).toHaveBeenCalledTimes(55); From d3e3ccce3e8aa23aac6994129b13c84f3f996134 Mon Sep 17 00:00:00 2001 From: Thomas Puttkamer Date: Mon, 13 Nov 2017 20:06:58 +0100 Subject: [PATCH 7/8] fixed issues #3 --- types/mochaccino/index.d.ts | 19 ++++--------------- types/mochaccino/mochaccino-tests.ts | 1 - 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/types/mochaccino/index.d.ts b/types/mochaccino/index.d.ts index 8ad9e86018..b230218ee9 100644 --- a/types/mochaccino/index.d.ts +++ b/types/mochaccino/index.d.ts @@ -3,12 +3,8 @@ // Definitions by: Thomas-P // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 - -/// - import * as Sinon from "sinon"; - -interface Expect { +export interface Expect { not: Expect; toBe(arg: any): void; toContain(arg: any): void; @@ -27,27 +23,20 @@ interface Expect { toThrowError(errType: any): void; toMatch(matchExpression: any): void; } - - -interface SpyProxy { +export interface SpyProxy { and: SpyProxy; spyProxy: true; getSubject: () => Sinon.SinonStub; callThrough: () => void; returnValue: (obj: any) => void; - callFake: (fake: Function) => void; + callFake: (fake: (...args: any[]) => any) => void; } - -interface Dom { +export interface Dom { exposedProperties: ['window', 'navigator', 'document']; create: () => void; destroy: () => void; clear: () => void; } - export function expect(value: any): Expect; - export function spy(...config: any[]): (...args: any[]) => SpyProxy; - export const dom: Dom; - diff --git a/types/mochaccino/mochaccino-tests.ts b/types/mochaccino/mochaccino-tests.ts index 744c20652c..26fb5c483b 100644 --- a/types/mochaccino/mochaccino-tests.ts +++ b/types/mochaccino/mochaccino-tests.ts @@ -4,7 +4,6 @@ import { dom, expect, spy } from 'mochaccino'; * */ const obj = { - funcName: () => { } }; let s = spy(); From 9c9d56b92ada871e4e5bc9bccaafe9f30dc02fe6 Mon Sep 17 00:00:00 2001 From: Thomas Puttkamer Date: Mon, 13 Nov 2017 20:07:31 +0100 Subject: [PATCH 8/8] fixed issues #4 --- types/mochaccino/mochaccino-tests.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/mochaccino/mochaccino-tests.ts b/types/mochaccino/mochaccino-tests.ts index 26fb5c483b..c63634e64c 100644 --- a/types/mochaccino/mochaccino-tests.ts +++ b/types/mochaccino/mochaccino-tests.ts @@ -4,6 +4,7 @@ import { dom, expect, spy } from 'mochaccino'; * */ const obj = { + funcName: (): any => { } }; let s = spy();