Skip to content

Commit 465a920

Browse files
committed
fix: remove unused request dependency
1 parent 94561cc commit 465a920

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

src/watch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export class Watch {
2525
callback: (phase: string, apiObj: any, watchObj?: any) => void,
2626
done: (err: any) => void,
2727
): Promise<AbortController> {
28-
const AbortControllerCtor = globalThis.AbortController || (await import('abort-controller')).AbortController;
28+
const AbortControllerCtor =
29+
globalThis.AbortController || (await import('abort-controller')).AbortController;
2930

3031
const cluster = this.config.getCurrentCluster();
3132
if (!cluster) {

src/watch_test.ts

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ describe('Watch', () => {
149149

150150
expect(doneCalled).to.equal(0);
151151

152-
// TODO check after noe-fetch fix
152+
// TODO check after node-fetch fix
153153
// https://github.com/node-fetch/node-fetch/issues/1231
154154
// https://github.com/node-fetch/node-fetch/issues/1721
155155

@@ -229,6 +229,66 @@ describe('Watch', () => {
229229
s.done();
230230
});
231231

232+
// https://github.com/node-fetch/node-fetch/issues/1231
233+
// https://github.com/node-fetch/node-fetch/issues/1721
234+
it.skip('should handle server side close correctly', async () => {
235+
const kc = new KubeConfig();
236+
Object.assign(kc, fakeConfig);
237+
const watch = new Watch(kc);
238+
239+
const obj1 = {
240+
type: 'ADDED',
241+
object: {
242+
foo: 'bar',
243+
},
244+
};
245+
246+
const stream = new PassThrough();
247+
248+
const [scope] = systemUnderTest();
249+
250+
const path = '/some/path/to/object?watch=true';
251+
252+
const s = scope.get(path).reply(200, () => {
253+
stream.push(JSON.stringify(obj1) + '\n');
254+
return stream;
255+
});
256+
257+
const receivedTypes: string[] = [];
258+
const receivedObjects: string[] = [];
259+
const doneErr: any[] = [];
260+
261+
let doneResolve: any;
262+
const donePromise = new Promise((resolve) => {
263+
doneResolve = resolve;
264+
});
265+
266+
await watch.watch(
267+
path,
268+
{},
269+
(phase: string, obj: string) => {
270+
receivedTypes.push(phase);
271+
receivedObjects.push(obj);
272+
},
273+
(err: any) => {
274+
doneErr.push(err);
275+
doneResolve();
276+
},
277+
);
278+
279+
stream.emit('close');
280+
281+
await donePromise;
282+
283+
expect(receivedTypes).to.deep.equal([obj1.type]);
284+
expect(receivedObjects).to.deep.equal([obj1.object]);
285+
286+
expect(doneErr.length).to.equal(1);
287+
expect(doneErr[0]).to.be.null;
288+
289+
s.done();
290+
});
291+
232292
it('should ignore JSON parse errors', async () => {
233293
const kc = new KubeConfig();
234294
Object.assign(kc, fakeConfig);

0 commit comments

Comments
 (0)