@hydranium/protocol 1.0.0-next.381 → 1.0.0-next.384
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -9
- package/lib/client/data-session.d.ts +77 -9
- package/lib/client/data-session.d.ts.map +1 -1
- package/lib/client/data-session.js +112 -17
- package/lib/client/data-session.js.map +1 -1
- package/lib/client/index.d.ts +1 -0
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/index.js +1 -0
- package/lib/client/index.js.map +1 -1
- package/lib/client/working-copy.d.ts +417 -0
- package/lib/client/working-copy.d.ts.map +1 -0
- package/lib/client/working-copy.js +943 -0
- package/lib/client/working-copy.js.map +1 -0
- package/lib/pending-work-tracker.d.ts +4 -1
- package/lib/pending-work-tracker.d.ts.map +1 -1
- package/lib/pending-work-tracker.js +6 -5
- package/lib/pending-work-tracker.js.map +1 -1
- package/lib/testing/harness.d.ts +9 -0
- package/lib/testing/harness.d.ts.map +1 -1
- package/lib/testing/node/index.d.ts +1 -0
- package/lib/testing/node/index.d.ts.map +1 -1
- package/lib/testing/node/index.js +2 -1
- package/lib/testing/node/index.js.map +1 -1
- package/lib/testing/node/unhandled-rejections.d.ts +20 -0
- package/lib/testing/node/unhandled-rejections.d.ts.map +1 -0
- package/lib/testing/node/unhandled-rejections.js +35 -0
- package/lib/testing/node/unhandled-rejections.js.map +1 -0
- package/package.json +1 -1
- package/src/client/data-session.ts +138 -17
- package/src/client/index.ts +1 -0
- package/src/client/working-copy.ts +1100 -0
- package/src/pending-work-tracker.ts +6 -5
- package/src/testing/harness.ts +10 -0
- package/src/testing/node/index.ts +2 -1
- package/src/testing/node/unhandled-rejections.ts +31 -0
|
@@ -17,14 +17,15 @@ export class PendingWorkTracker {
|
|
|
17
17
|
/** The tracked work. {@link track} removes each entry once it settles. */
|
|
18
18
|
protected readonly pending = new Set<Promise<unknown>>();
|
|
19
19
|
|
|
20
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Watch `work` until it settles. The promise handed back settles as `work`
|
|
22
|
+
* does, so a caller that drops it still sees a failure reported.
|
|
23
|
+
*/
|
|
21
24
|
track<T>(work: Promise<T>): Promise<T> {
|
|
22
25
|
this.pending.add(work);
|
|
23
|
-
|
|
26
|
+
return work.finally(() => {
|
|
24
27
|
this.pending.delete(work);
|
|
25
|
-
};
|
|
26
|
-
work.then(done, done);
|
|
27
|
-
return work;
|
|
28
|
+
});
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
/** How much of the tracked work has not settled yet. */
|
package/src/testing/harness.ts
CHANGED
|
@@ -22,3 +22,13 @@ export interface Harness {
|
|
|
22
22
|
/** Release every resource the harness holds. Idempotent; the uniform teardown hook. */
|
|
23
23
|
dispose(): void;
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* {@link Harness} for a harness whose teardown has to wait, such as one that
|
|
28
|
+
* deletes a directory only once its server reads none of it. Separate rather
|
|
29
|
+
* than a widened `Harness`, whose callers rely on a synchronous `dispose()`.
|
|
30
|
+
*/
|
|
31
|
+
export interface AsyncHarness {
|
|
32
|
+
/** Release every resource the harness holds, resolving once it has. Idempotent. */
|
|
33
|
+
dispose(): Promise<void>;
|
|
34
|
+
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
10
|
// Subpath barrel for `@hydranium/protocol/testing/node` — the test transports
|
|
11
|
-
// that need a Node runtime.
|
|
11
|
+
// that need a Node runtime, and the capture of `process`'s unhandled rejections.
|
|
12
12
|
//
|
|
13
13
|
// Separate from `./testing` because a `PassThrough` is in `DuplexStreamPair`'s
|
|
14
14
|
// exported type and `StreamMessageReader` comes from `vscode-jsonrpc/node`, so
|
|
@@ -20,3 +20,4 @@
|
|
|
20
20
|
export * from './duplex-connection';
|
|
21
21
|
export * from './duplex-stream';
|
|
22
22
|
export * from './message-port-pair';
|
|
23
|
+
export * from './unhandled-rejections';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Run a Node-only assertion while collecting process-level unhandled rejection
|
|
12
|
+
* events. The callback owns the event-loop drain and can therefore choose the
|
|
13
|
+
* right observation window for the operation under test.
|
|
14
|
+
*
|
|
15
|
+
* Inside the window a rejection reaches only the array: while any listener is
|
|
16
|
+
* registered, Node hands none to its default handler and Vitest reports none as
|
|
17
|
+
* an error. A callback that never asserts on the array therefore hides every
|
|
18
|
+
* rejection it provokes.
|
|
19
|
+
*/
|
|
20
|
+
export async function captureUnhandledRejections<T>(callback: (rejections: unknown[]) => Promise<T>): Promise<T> {
|
|
21
|
+
const rejections: unknown[] = [];
|
|
22
|
+
const listener = (reason: unknown): void => {
|
|
23
|
+
rejections.push(reason);
|
|
24
|
+
};
|
|
25
|
+
process.on('unhandledRejection', listener);
|
|
26
|
+
try {
|
|
27
|
+
return await callback(rejections);
|
|
28
|
+
} finally {
|
|
29
|
+
process.off('unhandledRejection', listener);
|
|
30
|
+
}
|
|
31
|
+
}
|