Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed Oct 19, 2019
1 parent c58f235 commit e35ba5c
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 8 deletions.
8 changes: 7 additions & 1 deletion tests/baselines/reference/correctOrderOfPromiseMethod.js
Expand Up @@ -15,7 +15,7 @@ async function countEverything(): Promise<number> {
const [resultA, resultB] = await Promise.all([
providerA(),
providerB(),
] as const);
]);

const dataA: A[] = resultA;
const dataB: B[] = resultB;
Expand All @@ -24,6 +24,10 @@ async function countEverything(): Promise<number> {
}
return 0;
}

// #31179

const result: Promise<[0, 1, '']> = Promise.all(undefined as readonly [0, 1, '']);


//// [correctOrderOfPromiseMethod.js]
Expand Down Expand Up @@ -92,3 +96,5 @@ function countEverything() {
});
});
}
// #31179
var result = Promise.all(undefined);
12 changes: 11 additions & 1 deletion tests/baselines/reference/correctOrderOfPromiseMethod.symbols
Expand Up @@ -43,7 +43,7 @@ async function countEverything(): Promise<number> {
providerB(),
>providerB : Symbol(providerB, Decl(correctOrderOfPromiseMethod.ts, 11, 9))

] as const);
]);

const dataA: A[] = resultA;
>dataA : Symbol(dataA, Decl(correctOrderOfPromiseMethod.ts, 18, 9))
Expand All @@ -70,3 +70,13 @@ async function countEverything(): Promise<number> {
return 0;
}

// #31179

const result: Promise<[0, 1, '']> = Promise.all(undefined as readonly [0, 1, '']);
>result : Symbol(result, Decl(correctOrderOfPromiseMethod.ts, 28, 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.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --))
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>undefined : Symbol(undefined)

20 changes: 15 additions & 5 deletions tests/baselines/reference/correctOrderOfPromiseMethod.types
Expand Up @@ -28,13 +28,12 @@ async function countEverything(): Promise<number> {
const [resultA, resultB] = await Promise.all([
>resultA : A[]
>resultB : B[]
>await Promise.all([ providerA(), providerB(), ] as const) : [A[], B[]]
>Promise.all([ providerA(), providerB(), ] as const) : Promise<[A[], B[]]>
>await Promise.all([ providerA(), providerB(), ]) : [A[], B[]]
>Promise.all([ providerA(), providerB(), ]) : Promise<[A[], B[]]>
>Promise.all : { <TAll>(values: Iterable<TAll>): Promise<(TAll extends undefined ? TAll : TAll extends PromiseLike<infer UAll> ? UAll : TAll)[]>; <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 undefined ? TAll : TAll extends PromiseLike<infer UAll> ? UAll : TAll)[]>; <T extends readonly any[]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>[ providerA(), providerB(), ] as const : readonly [Promise<A[]>, Promise<B[]>]
>[ providerA(), providerB(), ] : readonly [Promise<A[]>, Promise<B[]>]
>[ providerA(), providerB(), ] : [Promise<A[]>, Promise<B[]>]

providerA(),
>providerA() : Promise<A[]>
Expand All @@ -44,7 +43,7 @@ async function countEverything(): Promise<number> {
>providerB() : Promise<B[]>
>providerB : () => Promise<B[]>

] as const);
]);

const dataA: A[] = resultA;
>dataA : A[]
Expand Down Expand Up @@ -72,3 +71,14 @@ async function countEverything(): Promise<number> {
>0 : 0
}

// #31179

const result: Promise<[0, 1, '']> = Promise.all(undefined as readonly [0, 1, '']);
>result : Promise<[0, 1, ""]>
>Promise.all(undefined as readonly [0, 1, '']) : Promise<[0, 1, ""]>
>Promise.all : { <TAll>(values: Iterable<TAll>): Promise<(TAll extends undefined ? TAll : TAll extends PromiseLike<infer UAll> ? UAll : TAll)[]>; <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 undefined ? TAll : TAll extends PromiseLike<infer UAll> ? UAll : TAll)[]>; <T extends readonly any[]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>undefined as readonly [0, 1, ''] : readonly [0, 1, ""]
>undefined : undefined

18 changes: 18 additions & 0 deletions tests/baselines/reference/promiseType.js
Expand Up @@ -217,6 +217,18 @@ 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));

const result: undefined = undefined as Awaited<undefined>;

// #28427

Promise.all([undefined as Promise<number> | string]);

Promise.resolve(undefined as Promise<number> | string);

// #30390

(undefined as Promise<any>).then(undefined as () => Promise<number> | string);


//// [promiseType.js]
Expand Down Expand Up @@ -440,3 +452,9 @@ 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));
const result = undefined;
// #28427
Promise.all([undefined]);
Promise.resolve(undefined);
// #30390
undefined.then(undefined);
31 changes: 31 additions & 0 deletions tests/baselines/reference/promiseType.symbols
Expand Up @@ -1089,3 +1089,34 @@ 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, --, --))

const result: undefined = undefined as Awaited<undefined>;
>result : Symbol(result, Decl(promiseType.ts, 219, 5))
>undefined : Symbol(undefined)
>Awaited : Symbol(Awaited, Decl(lib.es2015.promise.d.ts, --, --))

// #28427

Promise.all([undefined as Promise<number> | string]);
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --))
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>undefined : Symbol(undefined)
>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.resolve(undefined as Promise<number> | string);
>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, --, --))
>undefined : Symbol(undefined)
>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, --, --))

// #30390

(undefined as Promise<any>).then(undefined as () => Promise<number> | string);
>(undefined as Promise<any>).then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>undefined : Symbol(undefined)
>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, --, --))
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>undefined : Symbol(undefined)
>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, --, --))

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

const result: undefined = undefined as Awaited<undefined>;
>result : undefined
>undefined as Awaited<undefined> : undefined
>undefined : undefined

// #28427

Promise.all([undefined as Promise<number> | string]);
>Promise.all([undefined as Promise<number> | string]) : Promise<(string | number)[]>
>Promise.all : { <TAll>(values: Iterable<TAll>): Promise<(TAll extends undefined ? TAll : TAll extends PromiseLike<infer UAll> ? UAll : TAll)[]>; <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 undefined ? TAll : TAll extends PromiseLike<infer UAll> ? UAll : TAll)[]>; <T extends readonly any[]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>[undefined as Promise<number> | string] : (string | Promise<number>)[]
>undefined as Promise<number> | string : string | Promise<number>
>undefined : undefined

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

// #30390

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

6 changes: 5 additions & 1 deletion tests/cases/compiler/correctOrderOfPromiseMethod.ts
Expand Up @@ -17,7 +17,7 @@ async function countEverything(): Promise<number> {
const [resultA, resultB] = await Promise.all([
providerA(),
providerB(),
] as const);
]);

const dataA: A[] = resultA;
const dataB: B[] = resultB;
Expand All @@ -26,3 +26,7 @@ async function countEverything(): Promise<number> {
}
return 0;
}

// #31179

const result: Promise<[0, 1, '']> = Promise.all(undefined as readonly [0, 1, '']);
12 changes: 12 additions & 0 deletions tests/cases/compiler/promiseType.ts
Expand Up @@ -217,3 +217,15 @@ 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));

const result: undefined = undefined as Awaited<undefined>;

// #28427

Promise.all([undefined as Promise<number> | string]);

Promise.resolve(undefined as Promise<number> | string);

// #30390

(undefined as Promise<any>).then(undefined as () => Promise<number> | string);

0 comments on commit e35ba5c

Please sign in to comment.