Skip to content

Commit 3dd8063

Browse files
committed
test:ts passes now
1 parent 0493c13 commit 3dd8063

File tree

11 files changed

+139
-28
lines changed

11 files changed

+139
-28
lines changed

.github/workflows/ci-build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
run: 'pnpm add --save-dev ${{ matrix.typescript-scenario}}'
6868
working-directory: ./test-apps/ember-fetch-v8
6969

70-
- run: pnpm --filter "./test-apps/*" exec tsc --noEmit;
70+
- run: pnpm --filter "*" test:ts;
7171

7272

7373
try-scenarios:

addon/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"ember-cli-htmlbars": "^6.3.0",
5353
"ember-cli-inject-live-reload": "^2.1.0",
5454
"ember-cli-uglify": "^3.0.0",
55-
"ember-concurrency": "^2.1.2",
5655
"ember-concurrency-decorators": "^2.0.3",
5756
"ember-concurrency-ts": "^0.3.1",
5857
"ember-decorators-polyfill": "^1.1.5",

addon/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"tests/**/*",
3838
"types/**/*",
3939
"test-support/**/*",
40-
"addon-test-support/**/*"
40+
"addon-test-support/**/*",
41+
"unpublished-development-types/**/*"
4142
]
4243
}

addon/types/index.d.ts

+103-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,103 @@
1-
import 'ember-source/types';
2-
3-
1+
import RSVP from 'rsvp';
2+
/**
3+
* @type WaiterName
4+
*
5+
* A string representing the test waiter name
6+
*/
7+
export type WaiterName = string;
8+
/**
9+
* @type Token
10+
*/
11+
export type Token = Primitive | unknown;
12+
/**
13+
* @type Primitive
14+
*
15+
* Any of the primitive value types
16+
*/
17+
export type Primitive = string | number | boolean | symbol | bigint;
18+
/**
19+
* @public
20+
* @interface Waiter
21+
*/
22+
export interface Waiter {
23+
/**
24+
* A string representing the test waiter name.
25+
*
26+
* @public
27+
* @property name {WaiterName}
28+
*/
29+
name: WaiterName;
30+
/**
31+
* Used to determine if the waiter system should still wait for async
32+
* operations to complete.
33+
*
34+
* @public
35+
* @method waitUntil
36+
* @returns {boolean}
37+
*/
38+
waitUntil(): boolean;
39+
/**
40+
* Returns the `debugInfo` for each item tracking async operations in this waiter.
41+
*
42+
* @public
43+
* @method debugInfo
44+
* @returns {TestWaiterDebugInfo}
45+
*/
46+
debugInfo(): TestWaiterDebugInfo[];
47+
}
48+
/**
49+
* @public
50+
* @interface TestWaiter<T>
51+
*/
52+
export interface TestWaiter<T extends object | Primitive | unknown = Token> extends Waiter {
53+
/**
54+
* Should be used to signal the beginning of an async operation that
55+
* is to be waited for. Invocation of this method should be paired with a subsequent
56+
* `endAsync` call to indicate to the waiter system that the async operation is completed.
57+
*
58+
* @public
59+
* @method beginAsync
60+
* @param item {T} The item to register for waiting
61+
* @param label {string} An optional label to identify the item
62+
*/
63+
beginAsync(token?: T, label?: string): T;
64+
/**
65+
* Should be used to signal the end of an async operation. Invocation of this
66+
* method should be paired with a preceding `beginAsync` call from this instance,
67+
* which would indicate the beginning of an async operation.
68+
*
69+
* @public
70+
* @method endAsync
71+
* @param item {T} The item to that was registered for waiting
72+
*/
73+
endAsync(token: T): void;
74+
/**
75+
* Resets the waiter state, clearing items tracking async operations in this waiter.
76+
*
77+
* @public
78+
* @method reset
79+
*/
80+
reset(): void;
81+
}
82+
/**
83+
* @public
84+
* @interface TestWaiterDebugInfo
85+
*/
86+
export interface TestWaiterDebugInfo {
87+
stack: string | undefined;
88+
label: string | undefined;
89+
}
90+
/**
91+
* @public
92+
* @interface PendingWaiterState
93+
*/
94+
export interface PendingWaiterState {
95+
pending: number;
96+
waiters: {
97+
[waiterName: string]: TestWaiterDebugInfo[] | true;
98+
};
99+
}
100+
export type PromiseType<T> = Promise<T> | RSVP.Promise<T>;
101+
export interface Thenable<T, Return extends PromiseType<T>> {
102+
then(resolve: (value: T) => T, reject?: (error: Error) => T): Return;
103+
}

pnpm-lock.yaml

+6-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-apps/base-tests/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
"lint:js:fix": "eslint . --fix",
2323
"lint:types": "tsc --noEmit",
2424
"start": "ember serve",
25-
"test": "concurrently \"npm:lint\" \"npm:test:*\" --names \"lint,test:\"",
2625
"test:ember": "ember test",
26+
"test:ts": "tsc --noEmit",
2727
"test:ember-compatibility": "ember try:each",
2828
"test:prod": "ember test --environment=production"
2929
},
@@ -36,6 +36,7 @@
3636
"@ember/string": "^3.1.1",
3737
"@ember/test-helpers": "^3.2.0",
3838
"@glimmer/component": "^1.1.2",
39+
"@glimmer/env": "^0.1.7",
3940
"@glimmer/tracking": "^1.1.2",
4041
"@glint/environment-ember-loose": "^1.1.0",
4142
"@glint/template": "^1.1.0",

test-apps/base-tests/tests/unit/wait-for-test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ if (DEBUG) {
9898
{
9999
name: 'class function',
100100
createPromise(...args: any[]) {
101+
// @ts-expect-error classic object model is hard to type correctly
101102
return EmberObjectThing.create().doAsyncStuff(...args);
102103
},
103104
createThrowingPromise() {
105+
// @ts-expect-error classic object model is hard to type correctly
104106
return EmberObjectThing.create().asyncThrow();
105107
},
106108
},

test-apps/base-tests/tests/unit/waiter-manager-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import MockStableError, {
22
overrideError,
33
resetError,
44
} from './utils/mock-stable-error';
5-
import {
5+
import type {
66
TestWaiterDebugInfo,
77
Waiter,
88
WaiterName,
99
} from '@ember/test-waiters/types';
10+
import type { Token } from '@ember/test-waiters';
1011
import {
11-
Token,
1212
_reset,
1313
_resetWaiterNames,
1414
buildWaiter,

test-apps/ember-concurrency-v2/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@ember/string": "^3.1.1",
3535
"@ember/test-helpers": "^3.2.0",
3636
"@glimmer/component": "^1.1.2",
37+
"@glimmer/env": "^0.1.7",
3738
"@glimmer/tracking": "^1.1.2",
3839
"@glint/environment-ember-loose": "^1.1.0",
3940
"@glint/template": "^1.1.0",

test-apps/ember-concurrency-v2/tests/unit/wait-for-test.ts

+19-15
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import { module, test } from 'qunit';
1111
import EmberObject, { get } from '@ember/object';
1212
import { DEBUG } from '@glimmer/env';
1313

14-
import { task as taskFn, TaskGenerator, didCancel } from 'ember-concurrency';
14+
import { task as taskFn, didCancel } from 'ember-concurrency';
15+
import type { TaskGenerator } from 'ember-concurrency';
1516
// type resolution is not working correctly due to usage of forked
1617
// (non-published) ember-concurrency-decorators remove this ts-ignore when
1718
// migrating back to mainline off the fork
@@ -33,13 +34,13 @@ interface ModeDef {
3334
}
3435

3536
if (DEBUG) {
36-
module('wait-for', function (hooks) {
37-
hooks.afterEach(function () {
37+
module('wait-for', function(hooks) {
38+
hooks.afterEach(function() {
3839
_reset();
3940
resetError();
4041
});
4142
const generatorTestModules = [
42-
(function () {
43+
(function() {
4344
const EmberObjectThing = EmberObject.extend({
4445
doStuffTask: taskFn(
4546
waitFor(function* doTaskStuff(...args: any) {
@@ -90,6 +91,7 @@ if (DEBUG) {
9091
throw new Error('doh!');
9192
}
9293
asyncThrow(...args: any) {
94+
// @ts-expect-error throwingTask missing, due to `this` not having its type changed
9395
return perform(this.throwingTask, ...args);
9496
}
9597
}
@@ -106,14 +108,16 @@ if (DEBUG) {
106108

107109
testModules.forEach(
108110
({ name, waiterName, EmberObjectThing, NativeThing }) => {
109-
module(name, function () {
111+
module(name, function() {
110112
const invocationType = [
111113
{
112114
name: 'class function',
113115
createPromise(...args: any[]) {
116+
// @ts-expect-error - doAsyncStuff missing due to TS being hard to use with the old (pre)class model
114117
return EmberObjectThing.create().doAsyncStuff(...args);
115118
},
116119
createThrowingPromise() {
120+
// @ts-expect-error - asyncThrow missing due to TS being hard to use with the old (pre)class model
117121
return EmberObjectThing.create().asyncThrow();
118122
},
119123
},
@@ -130,8 +134,8 @@ if (DEBUG) {
130134

131135
invocationType.forEach(
132136
({ name, createPromise, createThrowingPromise }: ModeDef) => {
133-
module(name, function () {
134-
test('waitFor wraps and registers a waiter', async function (assert) {
137+
module(name, function() {
138+
test('waitFor wraps and registers a waiter', async function(assert) {
135139
overrideError(MockStableError);
136140

137141
const promise = createPromise();
@@ -158,14 +162,14 @@ if (DEBUG) {
158162
});
159163
});
160164

161-
test('waitFor handles arguments and return value', async function (assert) {
165+
test('waitFor handles arguments and return value', async function(assert) {
162166
overrideError(MockStableError);
163167

164168
const ret = await createPromise(1, 'foo');
165169
assert.deepEqual(ret, ['foo', 1]);
166170
});
167171

168-
test('waitFor transitions waiter to not pending even if promise throws when thenable wrapped', async function (assert) {
172+
test('waitFor transitions waiter to not pending even if promise throws when thenable wrapped', async function(assert) {
169173
const promise = createThrowingPromise();
170174

171175
try {
@@ -184,7 +188,7 @@ if (DEBUG) {
184188
},
185189
);
186190

187-
module('waitFor ember-concurrency interop', function () {
191+
module('waitFor ember-concurrency interop', function() {
188192
class Deferred {
189193
promise: Promise<any>;
190194
resolve: Function = () => null;
@@ -262,7 +266,7 @@ if (DEBUG) {
262266
}
263267
}
264268

265-
test('tasks with multiple yields work', async function (assert) {
269+
test('tasks with multiple yields work', async function(assert) {
266270
const thing = new NativeThing();
267271
const task = perform(thing.doStuffTask);
268272

@@ -295,7 +299,7 @@ if (DEBUG) {
295299
];
296300

297301
cancellationCases.forEach(({ desc, taskName }) => {
298-
test(`${desc} task cancellation works`, async function (assert) {
302+
test(`${desc} task cancellation works`, async function(assert) {
299303
const thing = new NativeThing();
300304

301305
const instance = perform(get(thing, taskName));
@@ -317,7 +321,7 @@ if (DEBUG) {
317321
});
318322
});
319323

320-
module('waitFor co interop', function () {
324+
module('waitFor co interop', function() {
321325
function coDec(
322326
_target: object,
323327
_key: string,
@@ -391,7 +395,7 @@ if (DEBUG) {
391395
}
392396
}
393397

394-
test('it works', async function (assert) {
398+
test('it works', async function(assert) {
395399
const thing = new NativeThing();
396400

397401
thing.doStuffCo();
@@ -412,7 +416,7 @@ if (DEBUG) {
412416
});
413417
});
414418

415-
test('types', async function (assert) {
419+
test('types', async function(assert) {
416420
assert.expect(0);
417421

418422
async function asyncFn(a: string, b: string) {

test-apps/ember-fetch-v8/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"lint:js:fix": "eslint . --fix",
2323
"lint:types": "tsc --noEmit",
2424
"start": "ember serve",
25-
"test": "concurrently \"npm:lint\" \"npm:test:*\" --names \"lint,test:\"",
25+
"test:ts": "tsc --noEmit",
2626
"test:ember": "ember test"
2727
},
2828
"devDependencies": {

0 commit comments

Comments
 (0)