@luvio/adapter-test-library 0.154.7 → 0.154.9
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/dist/test-library.js
CHANGED
|
@@ -554,6 +554,40 @@ class MockDurableStore {
|
|
|
554
554
|
}
|
|
555
555
|
}
|
|
556
556
|
|
|
557
|
+
class MockCrossEnvironmentStorage {
|
|
558
|
+
constructor() {
|
|
559
|
+
this.environments = new Map();
|
|
560
|
+
}
|
|
561
|
+
registerEnvironmentForNotifications(notification) {
|
|
562
|
+
const identifier = (Math.random() + 1).toString(36).substring(2);
|
|
563
|
+
this.environments.set(identifier, notification);
|
|
564
|
+
return Promise.resolve({
|
|
565
|
+
identifier,
|
|
566
|
+
unsubscribe: () => {
|
|
567
|
+
this.environments.delete(identifier);
|
|
568
|
+
return Promise.resolve();
|
|
569
|
+
},
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
notifyCrossEnvironments(identifier, notification) {
|
|
573
|
+
this.environments.forEach((callback, id) => {
|
|
574
|
+
if (identifier !== id) {
|
|
575
|
+
callback(notification);
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
return Promise.resolve();
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
async function createMockCrossEnvironmentNotifier(listener, storage) {
|
|
582
|
+
const { identifier, unsubscribe } = await storage.registerEnvironmentForNotifications(listener);
|
|
583
|
+
return {
|
|
584
|
+
unsubscribe,
|
|
585
|
+
notifyCrossEnvironments: (notification) => {
|
|
586
|
+
return storage.notifyCrossEnvironments(identifier, notification);
|
|
587
|
+
},
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
|
|
557
591
|
// Use this util if you want to configure multiple network mocks in your test code.
|
|
558
592
|
// If you're only mocking one, we suggest you use buildLuvioWithNetwork instead.
|
|
559
593
|
function buildLuvioInstance(mockNetworkAdapter) {
|
|
@@ -638,4 +672,4 @@ async function testDeleteAdapterCompletesRoundtrip(params) {
|
|
|
638
672
|
return result;
|
|
639
673
|
}
|
|
640
674
|
|
|
641
|
-
export { ConnectivityState, MemoryDurableStorePersistence, MockDurableStore, buildErrorMockPayload, buildFetchResponse, buildLuvioInstance, buildLuvioWithNetwork, buildMockNetworkAdapter, buildSuccessMockPayload, customMatchers, flushPendingNetworkRequests, getMockFulfilledSnapshot, getMockLuvioWithFulfilledSnapshot, getMockNetworkAdapterCallCount, isImmutable, overrideMockNetworkResponses, resetMockNetworkAdapter, setMockNetworkPayloads, setNetworkConnectivity, setupCustomLuvioMatchers, stripProperties, testAdapterCompletesRoundtrip, testDeleteAdapterCompletesRoundtrip, verifyImmutable };
|
|
675
|
+
export { ConnectivityState, MemoryDurableStorePersistence, MockCrossEnvironmentStorage, MockDurableStore, buildErrorMockPayload, buildFetchResponse, buildLuvioInstance, buildLuvioWithNetwork, buildMockNetworkAdapter, buildSuccessMockPayload, createMockCrossEnvironmentNotifier, customMatchers, flushPendingNetworkRequests, getMockFulfilledSnapshot, getMockLuvioWithFulfilledSnapshot, getMockNetworkAdapterCallCount, isImmutable, overrideMockNetworkResponses, resetMockNetworkAdapter, setMockNetworkPayloads, setNetworkConnectivity, setupCustomLuvioMatchers, stripProperties, testAdapterCompletesRoundtrip, testDeleteAdapterCompletesRoundtrip, verifyImmutable };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CrossEnvironmentNotifier, EnvironmentChangeNotification } from '@luvio/environments';
|
|
2
|
+
export type NotificationEvent = (notification: EnvironmentChangeNotification) => Promise<void>;
|
|
3
|
+
type StorageCreate = {
|
|
4
|
+
identifier: string;
|
|
5
|
+
unsubscribe: () => Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare class MockCrossEnvironmentStorage {
|
|
8
|
+
protected environments: Map<string, NotificationEvent>;
|
|
9
|
+
registerEnvironmentForNotifications(notification: NotificationEvent): Promise<StorageCreate>;
|
|
10
|
+
notifyCrossEnvironments(identifier: string, notification: EnvironmentChangeNotification): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export declare function createMockCrossEnvironmentNotifier(listener: (notification: EnvironmentChangeNotification) => Promise<void>, storage: MockCrossEnvironmentStorage): Promise<CrossEnvironmentNotifier>;
|
|
13
|
+
export {};
|
package/dist/types/main.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { getMockLuvioWithFulfilledSnapshot, getMockFulfilledSnapshot } from './m
|
|
|
4
4
|
export { stripProperties, customMatchers } from './utils';
|
|
5
5
|
export { setupCustomLuvioMatchers } from './jest.setup';
|
|
6
6
|
export { MockDurableStore } from './MockDurableStore';
|
|
7
|
+
export { createMockCrossEnvironmentNotifier, MockCrossEnvironmentStorage, } from './MockCrossEnvironmentNotifier';
|
|
7
8
|
export { MemoryDurableStorePersistence, DurableStorePersistence } from './durableStorePersistence';
|
|
8
9
|
export { testAdapterCompletesRoundtrip, buildLuvioWithNetwork, buildLuvioInstance, } from './adapterRoundtrip';
|
|
9
10
|
export { testDeleteAdapterCompletesRoundtrip } from './deleteAdapterRoundtrip';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luvio/adapter-test-library",
|
|
3
|
-
"version": "0.154.
|
|
3
|
+
"version": "0.154.9",
|
|
4
4
|
"description": "Test library for luvio adapters",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"sinon": "^14.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@luvio/engine": "^0.154.
|
|
32
|
-
"@luvio/environments": "^0.154.
|
|
31
|
+
"@luvio/engine": "^0.154.9",
|
|
32
|
+
"@luvio/environments": "^0.154.9",
|
|
33
33
|
"@types/sinon": "^7.5.2"
|
|
34
34
|
},
|
|
35
35
|
"volta": {
|