Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed Oct 7, 2019
1 parent 0c21d01 commit 7224336
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 8 deletions.
10 changes: 9 additions & 1 deletion tests/baselines/reference/correctOrderOfPromiseMethod.js
Original file line number Diff line number Diff line change
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,11 @@ async function countEverything(): Promise<number> {
}
return 0;
}

// #31179

const values = [1, 'a'] as const;
const result: Promise<[1, 'a']> = Promise.all(values);


//// [correctOrderOfPromiseMethod.js]
Expand Down Expand Up @@ -92,3 +97,6 @@ function countEverything() {
});
});
}
// #31179
var values = [1, 'a'];
var result = Promise.all(values);
15 changes: 14 additions & 1 deletion tests/baselines/reference/correctOrderOfPromiseMethod.symbols
Original file line number Diff line number Diff line change
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,16 @@ async function countEverything(): Promise<number> {
return 0;
}

// #31179

const values = [1, 'a'] as const;
>values : Symbol(values, Decl(correctOrderOfPromiseMethod.ts, 28, 5))

const result: Promise<[1, 'a']> = Promise.all(values);
>result : Symbol(result, Decl(correctOrderOfPromiseMethod.ts, 29, 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, --, --))
>values : Symbol(values, Decl(correctOrderOfPromiseMethod.ts, 28, 5))

26 changes: 21 additions & 5 deletions tests/baselines/reference/correctOrderOfPromiseMethod.types
Original file line number Diff line number Diff line change
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 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 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,20 @@ async function countEverything(): Promise<number> {
>0 : 0
}

// #31179

const values = [1, 'a'] as const;
>values : readonly [1, "a"]
>[1, 'a'] as const : readonly [1, "a"]
>[1, 'a'] : readonly [1, "a"]
>1 : 1
>'a' : "a"

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

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, --, --))
>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, --, --))
>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[]>(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[]>(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>

7 changes: 6 additions & 1 deletion tests/cases/compiler/correctOrderOfPromiseMethod.ts
Original file line number Diff line number Diff line change
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,8 @@ async function countEverything(): Promise<number> {
}
return 0;
}

// #31179

const values = [1, 'a'] as const;
const result: Promise<[1, 'a']> = Promise.all(values);
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 7224336

Please sign in to comment.