Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed Oct 1, 2019
1 parent 6509e54 commit 497d816
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/baselines/reference/promiseType.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,26 @@ const pc6 = p.then(() => Promise.reject("1"), () => {});
const pc7 = p.then(() => Promise.reject("1"), () => {throw 1});
const pc8 = p.then(() => Promise.reject("1"), () => Promise.resolve(1));
const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1));

// #27711

const p2: Promise<number> = new Promise<Promise<number>>(() => {});

declare const x2: Promise<number> | string;

// #28427

Promise.all([x2]);

Promise.resolve(x2);

declare function f1(resolve: (value: Promise<number> | string) => void);
new Promise(f1);

// #30390

declare function f2(): Promise<number> | string;
p.then(f2);


//// [promiseType.js]
Expand Down Expand Up @@ -440,3 +460,10 @@ const pc6 = p.then(() => Promise.reject("1"), () => { });
const pc7 = p.then(() => Promise.reject("1"), () => { throw 1; });
const pc8 = p.then(() => Promise.reject("1"), () => Promise.resolve(1));
const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1));
// #27711
const p2 = new Promise(() => { });
// #28427
Promise.all([x2]);
Promise.resolve(x2);
new Promise(f1);
p.then(f2);
48 changes: 48 additions & 0 deletions tests/baselines/reference/promiseType.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -1089,3 +1089,51 @@ const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1));
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>reject : Symbol(PromiseConstructor.reject, Decl(lib.es2015.promise.d.ts, --, --))

// #27711

const p2: Promise<number> = new Promise<Promise<number>>(() => {});
>p2 : Symbol(p2, Decl(promiseType.ts, 221, 5))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))

declare const x2: Promise<number> | string;
>x2 : Symbol(x2, Decl(promiseType.ts, 223, 13))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))

// #28427

Promise.all([x2]);
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 6 more)
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 6 more)
>x2 : Symbol(x2, Decl(promiseType.ts, 223, 13))

Promise.resolve(x2);
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>x2 : Symbol(x2, Decl(promiseType.ts, 223, 13))

declare function f1(resolve: (value: Promise<number> | string) => void);
>f1 : Symbol(f1, Decl(promiseType.ts, 229, 20))
>resolve : Symbol(resolve, Decl(promiseType.ts, 231, 20))
>value : Symbol(value, Decl(promiseType.ts, 231, 30))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))

new Promise(f1);
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>f1 : Symbol(f1, Decl(promiseType.ts, 229, 20))

// #30390

declare function f2(): Promise<number> | string;
>f2 : Symbol(f2, Decl(promiseType.ts, 232, 16))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))

p.then(f2);
>p.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>p : Symbol(p, Decl(promiseType.ts, 0, 11))
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>f2 : Symbol(f2, Decl(promiseType.ts, 232, 16))

50 changes: 50 additions & 0 deletions tests/baselines/reference/promiseType.types
Original file line number Diff line number Diff line change
Expand Up @@ -1583,3 +1583,53 @@ const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1));
>reject : <T = never>(reason?: any) => Promise<T>
>1 : 1

// #27711

const p2: Promise<number> = new Promise<Promise<number>>(() => {});
>p2 : Promise<number>
>new Promise<Promise<number>>(() => {}) : Promise<number>
>Promise : PromiseConstructor
>() => {} : () => void

declare const x2: Promise<number> | string;
>x2 : string | Promise<number>

// #28427

Promise.all([x2]);
>Promise.all([x2]) : Promise<(string | number)[]>
>Promise.all : { <TAll>(values: Iterable<TAll>): Promise<(TAll extends PromiseLike<infer UAll> ? UAll : TAll)[]>; <T extends readonly [any, any, any, any, any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly any[]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>Promise : PromiseConstructor
>all : { <TAll>(values: Iterable<TAll>): Promise<(TAll extends PromiseLike<infer UAll> ? UAll : TAll)[]>; <T extends readonly [any, any, any, any, any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly any[]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>[x2] : (string | Promise<number>)[]
>x2 : string | Promise<number>

Promise.resolve(x2);
>Promise.resolve(x2) : Promise<string | number>
>Promise.resolve : { <T>(value: T): Promise<Awaited<T>>; (): Promise<void>; }
>Promise : PromiseConstructor
>resolve : { <T>(value: T): Promise<Awaited<T>>; (): Promise<void>; }
>x2 : string | Promise<number>

declare function f1(resolve: (value: Promise<number> | string) => void);
>f1 : (resolve: (value: string | Promise<number>) => void) => any
>resolve : (value: string | Promise<number>) => void
>value : string | Promise<number>

new Promise(f1);
>new Promise(f1) : Promise<string | number>
>Promise : PromiseConstructor
>f1 : (resolve: (value: string | Promise<number>) => void) => any

// #30390

declare function f2(): Promise<number> | string;
>f2 : () => string | Promise<number>

p.then(f2);
>p.then(f2) : Promise<string | number>
>p.then : <TResult1 = boolean, TResult2 = never>(onfulfilled?: (value: boolean) => TResult1, onrejected?: (reason: any) => TResult2) => Promise<(TResult1 extends PromiseLike<infer UResult1> ? UResult1 : TResult1) | (TResult2 extends PromiseLike<infer UResult2> ? UResult2 : TResult2)>
>p : Promise<boolean>
>then : <TResult1 = boolean, TResult2 = never>(onfulfilled?: (value: boolean) => TResult1, onrejected?: (reason: any) => TResult2) => Promise<(TResult1 extends PromiseLike<infer UResult1> ? UResult1 : TResult1) | (TResult2 extends PromiseLike<infer UResult2> ? UResult2 : TResult2)>
>f2 : () => string | Promise<number>

20 changes: 20 additions & 0 deletions tests/cases/compiler/promiseType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,23 @@ const pc6 = p.then(() => Promise.reject("1"), () => {});
const pc7 = p.then(() => Promise.reject("1"), () => {throw 1});
const pc8 = p.then(() => Promise.reject("1"), () => Promise.resolve(1));
const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1));

// #27711

const p2: Promise<number> = new Promise<Promise<number>>(() => {});

declare const x2: Promise<number> | string;

// #28427

Promise.all([x2]);

Promise.resolve(x2);

declare function f1(resolve: (value: Promise<number> | string) => void);
new Promise(f1);

// #30390

declare function f2(): Promise<number> | string;
p.then(f2);

0 comments on commit 497d816

Please sign in to comment.