|
1 | | -import { expect } from 'chai'; |
2 | 1 | import { describe, it } from 'mocha'; |
3 | 2 |
|
4 | 3 | import { expectPromise } from '../../__testUtils__/expectPromise.js'; |
@@ -70,62 +69,6 @@ describe('PromiseCanceller', () => { |
70 | 69 |
|
71 | 70 | await expectPromise(withCancellation).toRejectWith('Cancelled!'); |
72 | 71 | }); |
73 | | - |
74 | | - it('works to trigger onCancel when cancelling a hanging promise', async () => { |
75 | | - const abortController = new AbortController(); |
76 | | - const abortSignal = abortController.signal; |
77 | | - |
78 | | - const promiseCanceller = new PromiseCanceller(abortSignal); |
79 | | - |
80 | | - const promise = new Promise(() => { |
81 | | - /* never resolves */ |
82 | | - }); |
83 | | - |
84 | | - let onCancelCalled = false; |
85 | | - const onCancel = () => { |
86 | | - onCancelCalled = true; |
87 | | - }; |
88 | | - |
89 | | - const withCancellation = promiseCanceller.cancellablePromise( |
90 | | - promise, |
91 | | - onCancel, |
92 | | - ); |
93 | | - |
94 | | - expect(onCancelCalled).to.equal(false); |
95 | | - |
96 | | - abortController.abort(new Error('Cancelled!')); |
97 | | - |
98 | | - expect(onCancelCalled).to.equal(true); |
99 | | - |
100 | | - await expectPromise(withCancellation).toRejectWith('Cancelled!'); |
101 | | - }); |
102 | | - |
103 | | - it('works to trigger onCancel when cancelling a hanging promise created after abort signal triggered', async () => { |
104 | | - const abortController = new AbortController(); |
105 | | - const abortSignal = abortController.signal; |
106 | | - |
107 | | - abortController.abort(new Error('Cancelled!')); |
108 | | - |
109 | | - const promiseCanceller = new PromiseCanceller(abortSignal); |
110 | | - |
111 | | - const promise = new Promise(() => { |
112 | | - /* never resolves */ |
113 | | - }); |
114 | | - |
115 | | - let onCancelCalled = false; |
116 | | - const onCancel = () => { |
117 | | - onCancelCalled = true; |
118 | | - }; |
119 | | - |
120 | | - const withCancellation = promiseCanceller.cancellablePromise( |
121 | | - promise, |
122 | | - onCancel, |
123 | | - ); |
124 | | - |
125 | | - expect(onCancelCalled).to.equal(true); |
126 | | - |
127 | | - await expectPromise(withCancellation).toRejectWith('Cancelled!'); |
128 | | - }); |
129 | 72 | }); |
130 | 73 |
|
131 | 74 | describe('cancellableAsyncIterable', () => { |
@@ -174,69 +117,5 @@ describe('PromiseCanceller', () => { |
174 | 117 |
|
175 | 118 | await expectPromise(nextPromise).toRejectWith('Cancelled!'); |
176 | 119 | }); |
177 | | - |
178 | | - it('works to call return', async () => { |
179 | | - const abortController = new AbortController(); |
180 | | - const abortSignal = abortController.signal; |
181 | | - |
182 | | - const promiseCanceller = new PromiseCanceller(abortSignal); |
183 | | - |
184 | | - let returned = false; |
185 | | - const asyncIterable = { |
186 | | - [Symbol.asyncIterator]: () => ({ |
187 | | - next: () => Promise.resolve({ value: 1, done: false }), |
188 | | - return: () => { |
189 | | - returned = true; |
190 | | - return Promise.resolve({ value: undefined, done: true }); |
191 | | - }, |
192 | | - }), |
193 | | - }; |
194 | | - |
195 | | - const cancellableAsyncIterable = |
196 | | - promiseCanceller.cancellableIterable(asyncIterable); |
197 | | - |
198 | | - abortController.abort(new Error('Cancelled!')); |
199 | | - |
200 | | - expect(returned).to.equal(false); |
201 | | - |
202 | | - const nextPromise = |
203 | | - cancellableAsyncIterable[Symbol.asyncIterator]().next(); |
204 | | - |
205 | | - expect(returned).to.equal(true); |
206 | | - |
207 | | - await expectPromise(nextPromise).toRejectWith('Cancelled!'); |
208 | | - }); |
209 | | - |
210 | | - it('works to call return when already aborted', async () => { |
211 | | - const abortController = new AbortController(); |
212 | | - const abortSignal = abortController.signal; |
213 | | - |
214 | | - abortController.abort(new Error('Cancelled!')); |
215 | | - |
216 | | - const promiseCanceller = new PromiseCanceller(abortSignal); |
217 | | - |
218 | | - let returned = false; |
219 | | - const asyncIterable = { |
220 | | - [Symbol.asyncIterator]: () => ({ |
221 | | - next: () => Promise.resolve({ value: 1, done: false }), |
222 | | - return: () => { |
223 | | - returned = true; |
224 | | - return Promise.resolve({ value: undefined, done: true }); |
225 | | - }, |
226 | | - }), |
227 | | - }; |
228 | | - |
229 | | - const cancellableAsyncIterable = |
230 | | - promiseCanceller.cancellableIterable(asyncIterable); |
231 | | - |
232 | | - expect(returned).to.equal(false); |
233 | | - |
234 | | - const nextPromise = |
235 | | - cancellableAsyncIterable[Symbol.asyncIterator]().next(); |
236 | | - |
237 | | - expect(returned).to.equal(true); |
238 | | - |
239 | | - await expectPromise(nextPromise).toRejectWith('Cancelled!'); |
240 | | - }); |
241 | 120 | }); |
242 | 121 | }); |
0 commit comments