@fluid-internal/presence-runtime 2.101.1 → 2.103.0
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/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/runtime/extension/containerPresence.d.ts +1 -1
- package/dist/runtime/presenceDatastoreManager.d.ts +2 -2
- package/dist/runtime/presenceDatastoreManager.d.ts.map +1 -1
- package/dist/runtime/presenceDatastoreManager.js.map +1 -1
- package/dist/runtime/presenceManager.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/runtime/extension/containerPresence.d.ts +1 -1
- package/lib/runtime/presenceDatastoreManager.d.ts +2 -2
- package/lib/runtime/presenceDatastoreManager.d.ts.map +1 -1
- package/lib/runtime/presenceDatastoreManager.js.map +1 -1
- package/lib/runtime/presenceManager.js.map +1 -1
- package/package.json +14 -14
- package/dist/runtime/test/presenceDatastoreManager.spec.js +0 -618
- package/dist/runtime/test/presenceDatastoreManager.spec.js.map +0 -1
- package/dist/runtime/test/presenceManager.spec.js +0 -651
- package/dist/runtime/test/presenceManager.spec.js.map +0 -1
- package/dist/states/test/batching.spec.js +0 -843
- package/dist/states/test/batching.spec.js.map +0 -1
- package/dist/states/test/broadcastControlsTests.js +0 -60
- package/dist/states/test/broadcastControlsTests.js.map +0 -1
- package/dist/states/test/eventing.spec.js +0 -576
- package/dist/states/test/eventing.spec.js.map +0 -1
- package/dist/states/test/latestMapValueManager.spec.js +0 -210
- package/dist/states/test/latestMapValueManager.spec.js.map +0 -1
- package/dist/states/test/latestValueManager.spec.js +0 -193
- package/dist/states/test/latestValueManager.spec.js.map +0 -1
- package/dist/states/test/mockEphemeralRuntime.js +0 -11
- package/dist/states/test/mockEphemeralRuntime.js.map +0 -1
- package/dist/states/test/notificationsManager.spec.js +0 -460
- package/dist/states/test/notificationsManager.spec.js.map +0 -1
- package/dist/states/test/presenceStates.spec.js +0 -73
- package/dist/states/test/presenceStates.spec.js.map +0 -1
- package/dist/states/test/schemaValidation/protocol.spec.js +0 -246
- package/dist/states/test/schemaValidation/protocol.spec.js.map +0 -1
- package/dist/states/test/schemaValidation/valueManagers.spec.js +0 -784
- package/dist/states/test/schemaValidation/valueManagers.spec.js.map +0 -1
- package/dist/states/test/testUtils.js +0 -21
- package/dist/states/test/testUtils.js.map +0 -1
- package/dist/test/mockEphemeralRuntime.js +0 -175
- package/dist/test/mockEphemeralRuntime.js.map +0 -1
- package/dist/test/testUtils.js +0 -262
- package/dist/test/testUtils.js.map +0 -1
- package/dist/test/utils/index.js +0 -27
- package/dist/test/utils/index.js.map +0 -1
- package/dist/utils/test/timerManager.spec.js +0 -93
- package/dist/utils/test/timerManager.spec.js.map +0 -1
- package/lib/runtime/test/presenceDatastoreManager.spec.js +0 -616
- package/lib/runtime/test/presenceDatastoreManager.spec.js.map +0 -1
- package/lib/runtime/test/presenceManager.spec.js +0 -649
- package/lib/runtime/test/presenceManager.spec.js.map +0 -1
- package/lib/states/test/batching.spec.js +0 -841
- package/lib/states/test/batching.spec.js.map +0 -1
- package/lib/states/test/broadcastControlsTests.js +0 -56
- package/lib/states/test/broadcastControlsTests.js.map +0 -1
- package/lib/states/test/eventing.spec.js +0 -574
- package/lib/states/test/eventing.spec.js.map +0 -1
- package/lib/states/test/latestMapValueManager.spec.js +0 -206
- package/lib/states/test/latestMapValueManager.spec.js.map +0 -1
- package/lib/states/test/latestValueManager.spec.js +0 -189
- package/lib/states/test/latestValueManager.spec.js.map +0 -1
- package/lib/states/test/mockEphemeralRuntime.js +0 -6
- package/lib/states/test/mockEphemeralRuntime.js.map +0 -1
- package/lib/states/test/notificationsManager.spec.js +0 -456
- package/lib/states/test/notificationsManager.spec.js.map +0 -1
- package/lib/states/test/presenceStates.spec.js +0 -69
- package/lib/states/test/presenceStates.spec.js.map +0 -1
- package/lib/states/test/schemaValidation/protocol.spec.js +0 -244
- package/lib/states/test/schemaValidation/protocol.spec.js.map +0 -1
- package/lib/states/test/schemaValidation/valueManagers.spec.js +0 -782
- package/lib/states/test/schemaValidation/valueManagers.spec.js.map +0 -1
- package/lib/states/test/testUtils.js +0 -6
- package/lib/states/test/testUtils.js.map +0 -1
- package/lib/test/mockEphemeralRuntime.js +0 -171
- package/lib/test/mockEphemeralRuntime.js.map +0 -1
- package/lib/test/testUtils.js +0 -251
- package/lib/test/testUtils.js.map +0 -1
- package/lib/test/utils/index.js +0 -8
- package/lib/test/utils/index.js.map +0 -1
- package/lib/utils/test/timerManager.spec.js +0 -91
- package/lib/utils/test/timerManager.spec.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"testUtils.js","sourceRoot":"","sources":["../../src/test/testUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAcH,kEAAqF;AACrF,iCAA4B;AAU5B,yEAGwD;AAGxD,uEAA2E;AAE3E;;GAEG;AACH,SAAgB,oBAAoB,CACnC,OAAgE,EAChE,SAAkE;IAElE,OAAO,SAAgE,CAAC;AACzE,CAAC;AALD,oDAKC;AAED;;GAEG;AACH,SAAgB,gBAAgB;IAC/B,OAAO,SAAc,CAAC;AACvB,CAAC;AAFD,4CAEC;AAMD;;GAEG;AACH,SAAgB,wBAAwB,CACvC,EAAK;IAEL,OAAO,EAA2B,CAAC;AACpC,CAAC;AAJD,4DAIC;AAED;;GAEG;AACU,QAAA,WAAW,GAAG,wBAAwB,CAAC,cAAc,CAAC,CAAC;AACpE;;GAEG;AACU,QAAA,aAAa,GAAG,SAA+C,CAAC;AAC7E;;GAEG;AACU,QAAA,eAAe,GAAG,wBAAwB,CAAC,iBAAiB,CAAC,CAAC;AAE3E;;GAEG;AACH,SAAgB,uBAAuB,CACtC,SAAiB,EACjB,EACC,UAAU,GAAG,uBAAe,EAC5B,kBAAkB,GAAG,wDAA8B,EACnD,eAAe,GAAG,CAAC,SAAS,EAAE,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B,OAAO,CAAC,OAAO,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;QAE/C,gCAAgC;QAChC,OAAO,CAAC,yBAAyB,EAAE,CAAC;QAEpC,4BAA4B,CAC3B,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,KAAK,EACL,eAAe,CACf,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACN,QAAQ;QACR,aAAa;QACb,OAAO;QACP,eAAe;KACf,CAAC;AACH,CAAC;AA3DD,kEA2DC;AAED;;GAEG;AACH,SAAgB,uBAAuB,CACtC,OAA6B,EAC7B,MAAmC;IAEnC,gFAAgF;IAChF,MAAM,SAAS,GAAG,IAAA,yCAA8B,EAAC,MAAM,CAAC,CAAC;IACzD,IAAI,SAAS,EAAE,CAAC;QACf,MAAM,SAAS,CAAC;IACjB,CAAC;IACD,4CAA4C;IAC5C,OAAO,CAAC,yBAAyB,EAAE,CAAC;AACrC,CAAC;AAXD,0DAWC;AAED;;;GAGG;AACH,MAAM,aAAa,GAAG,CAAmB,IAAa,EAAuB,EAAE;IAC9E,OAAO,IAA2B,CAAC;AACpC,CAAC,CAAC;AAEF;;;;GAIG;AACI,MAAM,oBAAoB,GAAG,CACnC,oBAA6C,CAAA,aAAgB,CAAA,EAE5D,EAAE,CAAC,IAAA,WAAG,EAAC,iBAAiB,CAAmC,CAAC;AAHjD,QAAA,oBAAoB,wBAG6B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tAttendeeId,\n\tClientConnectionId,\n\tPresenceWithNotifications,\n\tStateSchemaValidator,\n} from \"@fluid-internal/presence-definitions\";\nimport type { InboundExtensionMessage } from \"@fluidframework/container-runtime-definitions/internal\";\nimport type {\n\tInternalCoreInterfacesUtilityTypes,\n\tJsonDeserialized,\n} from \"@fluidframework/core-interfaces/internal\";\nimport type { EventAndErrorTrackingLogger } from \"@fluidframework/test-utils/internal\";\nimport { getUnexpectedLogErrorException } from \"@fluidframework/test-utils/internal\";\nimport { spy } from \"sinon\";\nimport type { SinonFakeTimers } from \"sinon\";\n\nimport type {\n\tInboundClientJoinMessage,\n\tInboundDatastoreUpdateMessage,\n\tOutboundClientJoinMessage,\n\tSignalMessages,\n\tSystemWorkspaceDatastore,\n} from \"@fluid-internal/presence-runtime/internal/protocol\";\nimport {\n\tbroadcastJoinResponseDelaysMs,\n\tcreatePresenceManager,\n} from \"@fluid-internal/presence-runtime/internal/test\";\n\nimport type { MockEphemeralRuntime } from \"./mockEphemeralRuntime.js\";\nimport { initialLocalClientConnectionId } from \"./mockEphemeralRuntime.js\";\n\n/**\n * Use to compile-time assert types of two variables are identical.\n */\nexport function assertIdenticalTypes<T, U>(\n\t_actual: T & InternalCoreInterfacesUtilityTypes.IfSameType<T, U>,\n\t_expected: U & InternalCoreInterfacesUtilityTypes.IfSameType<T, U>,\n): InternalCoreInterfacesUtilityTypes.IfSameType<T, U> {\n\treturn undefined as InternalCoreInterfacesUtilityTypes.IfSameType<T, U>;\n}\n\n/**\n * Creates a non-viable (`undefined`) instance of type T to be used for type checking.\n */\nexport function createInstanceOf<T>(): T {\n\treturn undefined as T;\n}\n\ntype SpecificAttendeeId<T extends string> = string extends T\n\t? never\n\t: Exclude<T & AttendeeId, never>;\n\n/**\n * Forms {@link AttendeeId} for a specific attendee\n */\nexport function createSpecificAttendeeId<const T extends string>(\n\tid: T,\n): SpecificAttendeeId<T> {\n\treturn id as SpecificAttendeeId<T>;\n}\n\n/**\n * Mock {@link AttendeeId}.\n */\nexport const attendeeId1 = createSpecificAttendeeId(\"attendeeId-1\");\n/**\n * Mock {@link ClientConnectionId}.\n */\nexport const connectionId1 = \"client1\" as const satisfies ClientConnectionId;\n/**\n * Mock {@link AttendeeId} for the local client in tests.\n */\nexport const localAttendeeId = createSpecificAttendeeId(\"localAttendeeId\");\n\n/**\n * Generates expected inbound join signal for a client that was initialized while connected.\n */\nexport function generateBasicClientJoin(\n\tfixedTime: number,\n\t{\n\t\tattendeeId = localAttendeeId,\n\t\tclientConnectionId = initialLocalClientConnectionId,\n\t\tupdateProviders = [\"client0\", \"client1\", \"client3\"],\n\t\tconnectionOrder = 0,\n\t\taverageLatency = 0,\n\t\tpriorClientToSessionId = {},\n\t}: {\n\t\tattendeeId?: string;\n\t\tclientConnectionId?: ClientConnectionId;\n\t\tupdateProviders?: string[];\n\t\tconnectionOrder?: number;\n\t\taverageLatency?: number;\n\t\tpriorClientToSessionId?: SystemWorkspaceDatastore[\"clientToSessionId\"];\n\t},\n): InboundClientJoinMessage {\n\treturn {\n\t\ttype: \"Pres:ClientJoin\",\n\t\tcontent: {\n\t\t\t\"avgLatency\": averageLatency,\n\t\t\t\"data\": {\n\t\t\t\t\"system:presence\": {\n\t\t\t\t\t\"clientToSessionId\": {\n\t\t\t\t\t\t...priorClientToSessionId,\n\t\t\t\t\t\t[clientConnectionId]: {\n\t\t\t\t\t\t\t\"rev\": connectionOrder,\n\t\t\t\t\t\t\t\"timestamp\": fixedTime,\n\t\t\t\t\t\t\t\"value\": attendeeId as AttendeeId,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t\"sendTimestamp\": fixedTime,\n\t\t\tupdateProviders,\n\t\t},\n\t\tclientId: clientConnectionId,\n\t};\n}\n\n/**\n * Function signature for sending a signal to the presence manager.\n */\nexport type ProcessSignalFunction = ReturnType<typeof createPresenceManager>[\"processSignal\"];\n\n/**\n * Expected shape of Presence signals\n */\nexport type InboundPresenceSignalMessage = InboundExtensionMessage<SignalMessages>;\n\n/**\n * Creates a processSignal wrapper function for a presence manager.\n */\nfunction createProcessSignal(\n\tpresence: ReturnType<typeof createPresenceManager>,\n): ProcessSignalFunction {\n\treturn (\n\t\taddressChain: string[],\n\t\tsignalMessage: InboundPresenceSignalMessage,\n\t\tlocal: boolean,\n\t): void => {\n\t\t// Pass on to presence manager, but first clone the message to avoid\n\t\t// possibility of Presence mutating the original message which often\n\t\t// contains reference to general (shared) test data.\n\t\t// Additionally JSON.parse(JSON.stringify(signalMessage)) is used to\n\t\t// ensure only regular JSON-serializable data is passed to Presence.\n\t\t// In production environment, the message is always extracted from\n\t\t// the network and Presence can safely mutate it.\n\t\tpresence.processSignal(\n\t\t\taddressChain,\n\t\t\t// eslint-disable-next-line unicorn/prefer-structured-clone -- not structural clone, but filters to JSON-serializable data\n\t\t\tJSON.parse(JSON.stringify(signalMessage)) as InboundPresenceSignalMessage,\n\t\t\tlocal,\n\t\t);\n\t};\n}\n\n/**\n * Calculates update providers based on current audience members.\n */\nfunction calculateUpdateProviders(\n\truntime: MockEphemeralRuntime,\n\tclientConnectionId: ClientConnectionId,\n): ClientConnectionId[] {\n\t// This logic needs to be kept in sync with datastore manager.\n\t// From PresenceDatastoreManager.getAudienceInformation:\n\tconst members = runtime.audience.getMembers();\n\tmembers.delete(clientConnectionId);\n\tconst all = new Set<ClientConnectionId>();\n\tconst writers = new Set<ClientConnectionId>();\n\tfor (const [id, client] of members) {\n\t\tif (client.details.capabilities.interactive) {\n\t\t\tall.add(id);\n\t\t\tif (client.mode === \"write\") {\n\t\t\t\twriters.add(id);\n\t\t\t}\n\t\t}\n\t}\n\t// From PresenceDatastoreManager.joinSession:\n\tconst updateProviders = [...(writers.size > 0 ? writers : all)];\n\tif (updateProviders.length > 3) {\n\t\tupdateProviders.length = 3;\n\t}\n\treturn updateProviders;\n}\n\n/**\n * Prepares the expected client join signal and calculates update providers.\n */\nfunction prepareExpectedClientJoin(\n\truntime: MockEphemeralRuntime,\n\tattendeeId: string,\n\tclientConnectionId: ClientConnectionId,\n\tclock: Omit<SinonFakeTimers, \"restore\">,\n): {\n\texpectedClientJoin: OutboundClientJoinMessage &\n\t\tPartial<Pick<InboundClientJoinMessage, \"clientId\">>;\n\tupdateProviders: ClientConnectionId[];\n} {\n\tconst updateProviders = calculateUpdateProviders(runtime, clientConnectionId);\n\n\tconst expectedClientJoin: OutboundClientJoinMessage &\n\t\tPartial<Pick<InboundClientJoinMessage, \"clientId\">> = generateBasicClientJoin(clock.now, {\n\t\tattendeeId,\n\t\tclientConnectionId,\n\t\tupdateProviders,\n\t});\n\tdelete expectedClientJoin.clientId;\n\truntime.signalsExpected.push([expectedClientJoin]);\n\n\treturn { expectedClientJoin, updateProviders };\n}\n\n/**\n * Processes the local join signal and sends a fake join response.\n */\nfunction processJoinSignalAndResponse(\n\tprocessSignal: ProcessSignalFunction,\n\texpectedClientJoin: OutboundClientJoinMessage &\n\t\tPartial<Pick<InboundClientJoinMessage, \"clientId\">>,\n\tclientConnectionId: ClientConnectionId,\n\tupdateProviders: ClientConnectionId[],\n\tclock: Omit<SinonFakeTimers, \"restore\">,\n\tlatency: number,\n): void {\n\t// Pass a little time (to mimic reality)\n\tclock.tick(latency);\n\n\t// Return the [local] join signal\n\tprocessSignal([], { ...expectedClientJoin, clientId: clientConnectionId }, true);\n\n\tif (updateProviders.length > 0) {\n\t\t// Pass time (to mimic likely response)\n\t\tclock.tick(broadcastJoinResponseDelaysMs.namedResponder + 20);\n\n\t\t// Send a fake join response\n\t\t// There are no other attendees in the session (not realistic) but this\n\t\t// convinces the presence manager that it now has full knowledge, which\n\t\t// enables it to respond to other's join requests accurately.\n\t\tprocessSignal(\n\t\t\t[],\n\t\t\t{\n\t\t\t\ttype: \"Pres:DatastoreUpdate\",\n\t\t\t\tcontent: {\n\t\t\t\t\t...expectedClientJoin.content,\n\t\t\t\t\tisComplete: true,\n\t\t\t\t\tjoinResponseFor: [clientConnectionId],\n\t\t\t\t},\n\t\t\t\tclientId: updateProviders[0],\n\t\t\t} satisfies InboundDatastoreUpdateMessage,\n\t\t\tfalse,\n\t\t);\n\t}\n}\n\n/**\n * The simulated local average latency used in test helpers.\n */\nconst localAvgLatency = 10;\n\n/**\n * Creates presence manager for testing.\n */\nfunction createPresence(\n\truntime: MockEphemeralRuntime,\n\tattendeeId: string,\n\tlogger: EventAndErrorTrackingLogger,\n): {\n\tpresence: ReturnType<typeof createPresenceManager>;\n\tprocessSignal: ProcessSignalFunction;\n} {\n\tlogger.registerExpectedEvent({ eventName: \"Presence:PresenceInstantiated\" });\n\n\tconst presence = createPresenceManager(runtime, attendeeId as AttendeeId);\n\tconst processSignal = createProcessSignal(presence);\n\n\t// Validate expectations post initialization to make sure logger\n\t// and runtime are left in a clean expectation state.\n\tconst logErrors = getUnexpectedLogErrorException(logger);\n\tif (logErrors) {\n\t\tthrow logErrors;\n\t}\n\n\treturn { presence, processSignal };\n}\n\n/**\n * Prepares an instance of presence as it would be if initialized while connected.\n *\n * @param runtime - the mock runtime\n * @param attendeeId - the client session id given to presence\n * @param clientConnectionId - the client connection id\n * @param clock - the fake timer.\n * @param logger - logger to track telemetry events\n */\nexport function prepareConnectedPresence(\n\truntime: MockEphemeralRuntime,\n\tattendeeId: string,\n\tclientConnectionId: ClientConnectionId,\n\tclock: Omit<SinonFakeTimers, \"restore\">,\n\tlogger: EventAndErrorTrackingLogger,\n): {\n\tpresence: PresenceWithNotifications;\n\tprocessSignal: ProcessSignalFunction;\n\tlocalAvgLatency: number;\n} {\n\t// Set runtime to connected state\n\truntime.clientId = clientConnectionId;\n\truntime.joined = true;\n\n\tconst { expectedClientJoin, updateProviders } = prepareExpectedClientJoin(\n\t\truntime,\n\t\tattendeeId,\n\t\tclientConnectionId,\n\t\tclock,\n\t);\n\n\tconst { presence, processSignal } = createPresence(runtime, attendeeId, logger);\n\truntime.assertAllSignalsSubmitted();\n\n\tprocessJoinSignalAndResponse(\n\t\tprocessSignal,\n\t\texpectedClientJoin,\n\t\tclientConnectionId,\n\t\tupdateProviders,\n\t\tclock,\n\t\tlocalAvgLatency,\n\t);\n\n\treturn {\n\t\tpresence,\n\t\tprocessSignal,\n\t\tlocalAvgLatency,\n\t};\n}\n\n/**\n * Prepares an instance of presence in a disconnected state.\n *\n * @remarks\n * Use this helper when you need to test events that occur during the initial\n * connection, such as `attendeeConnected` for the local client.\n *\n * @param runtime - the mock runtime\n * @param attendeeId - the client session id given to presence\n * @param clientConnectionId - the client connection id to use when connecting\n * @param clock - the fake timer\n * @param logger - logger to track telemetry events\n */\nexport function prepareDisconnectedPresence(\n\truntime: MockEphemeralRuntime,\n\tattendeeId: string,\n\tclientConnectionId: ClientConnectionId,\n\tclock: Omit<SinonFakeTimers, \"restore\">,\n\tlogger: EventAndErrorTrackingLogger,\n): {\n\tpresence: PresenceWithNotifications;\n\tprocessSignal: ProcessSignalFunction;\n\t/**\n\t * Connects presence using the client connection id provided to prepareDisconnectedPresence.\n\t */\n\tconnect: () => void;\n\t/**\n\t * The simulated local average latency used by connect.\n\t */\n\tlocalAvgLatency: number;\n} {\n\t// Ensure runtime is in disconnected state\n\truntime.clientId = undefined;\n\truntime.joined = false;\n\n\t// Remove client connection id from audience if present\n\tif (runtime.audience.getMember(clientConnectionId) !== undefined) {\n\t\truntime.removeMember(clientConnectionId);\n\t}\n\n\tconst { presence, processSignal } = createPresence(runtime, attendeeId, logger);\n\n\tconst connect = (): void => {\n\t\tconst { expectedClientJoin, updateProviders } = prepareExpectedClientJoin(\n\t\t\truntime,\n\t\t\tattendeeId,\n\t\t\tclientConnectionId,\n\t\t\tclock,\n\t\t);\n\n\t\t// Simulate connection\n\t\truntime.connect(clientConnectionId, undefined);\n\n\t\t// Validate signal was submitted\n\t\truntime.assertAllSignalsSubmitted();\n\n\t\tprocessJoinSignalAndResponse(\n\t\t\tprocessSignal,\n\t\t\texpectedClientJoin,\n\t\t\tclientConnectionId,\n\t\t\tupdateProviders,\n\t\t\tclock,\n\t\t\tlocalAvgLatency,\n\t\t);\n\t};\n\n\treturn {\n\t\tpresence,\n\t\tprocessSignal,\n\t\tconnect,\n\t\tlocalAvgLatency,\n\t};\n}\n\n/**\n * Asserts that all expected telemetry and signals were sent.\n */\nexport function assertFinalExpectations(\n\truntime: MockEphemeralRuntime,\n\tlogger: EventAndErrorTrackingLogger,\n): void {\n\t// Make sure all expected events were logged and there are no unexpected errors.\n\tconst logErrors = getUnexpectedLogErrorException(logger);\n\tif (logErrors) {\n\t\tthrow logErrors;\n\t}\n\t// Make sure all expected signals were sent.\n\truntime.assertAllSignalsSubmitted();\n}\n\n/**\n * A null validator (one that does nothing) for a given type T. It simply casts the value to\n * `JsonDeserialized<T>`.\n */\nconst nullValidator = <T extends object>(data: unknown): JsonDeserialized<T> => {\n\treturn data as JsonDeserialized<T>;\n};\n\n/**\n * Creates a spied validator for test purposes.\n *\n * @param validatorFunction - A {@link StateSchemaValidator} to wrap in a spy.\n */\nexport const createSpiedValidator = <T extends object>(\n\tvalidatorFunction: StateSchemaValidator<T> = nullValidator<T>,\n\t// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type\n) => spy(validatorFunction) satisfies StateSchemaValidator<T>;\n"]}
|
package/dist/test/utils/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
-
if (k2 === undefined) k2 = k;
|
|
8
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
-
}
|
|
12
|
-
Object.defineProperty(o, k2, desc);
|
|
13
|
-
}) : (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
o[k2] = m[k];
|
|
16
|
-
}));
|
|
17
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.MockEphemeralRuntime = exports.initialLocalClientConnectionId = void 0;
|
|
22
|
-
var mockEphemeralRuntime_js_1 = require("../mockEphemeralRuntime.js");
|
|
23
|
-
Object.defineProperty(exports, "initialLocalClientConnectionId", { enumerable: true, get: function () { return mockEphemeralRuntime_js_1.initialLocalClientConnectionId; } });
|
|
24
|
-
Object.defineProperty(exports, "MockEphemeralRuntime", { enumerable: true, get: function () { return mockEphemeralRuntime_js_1.MockEphemeralRuntime; } });
|
|
25
|
-
// eslint-disable-next-line no-restricted-syntax -- internally export all testUtils exports
|
|
26
|
-
__exportStar(require("../testUtils.js"), exports);
|
|
27
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/test/utils/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;AAEH,sEAGoC;AAFnC,yIAAA,8BAA8B,OAAA;AAC9B,+HAAA,oBAAoB,OAAA;AAGrB,2FAA2F;AAC3F,kDAAgC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\tinitialLocalClientConnectionId,\n\tMockEphemeralRuntime,\n} from \"../mockEphemeralRuntime.js\";\n\n// eslint-disable-next-line no-restricted-syntax -- internally export all testUtils exports\nexport * from \"../testUtils.js\";\n"]}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const node_assert_1 = require("node:assert");
|
|
8
|
-
const mocha_1 = require("mocha");
|
|
9
|
-
const sinon_1 = require("sinon");
|
|
10
|
-
const index_js_1 = require("../index.js");
|
|
11
|
-
// TODO: separate Presence/Utils from TimerManager after file move is merged.
|
|
12
|
-
(0, mocha_1.describe)("Presence/Utils:TimerManager", () => {
|
|
13
|
-
const initialTime = 1000;
|
|
14
|
-
let clock;
|
|
15
|
-
(0, mocha_1.before)(async () => {
|
|
16
|
-
clock = (0, sinon_1.useFakeTimers)();
|
|
17
|
-
});
|
|
18
|
-
(0, mocha_1.beforeEach)(() => {
|
|
19
|
-
clock.setSystemTime(initialTime);
|
|
20
|
-
});
|
|
21
|
-
(0, mocha_1.afterEach)(() => {
|
|
22
|
-
clock.reset();
|
|
23
|
-
});
|
|
24
|
-
(0, mocha_1.after)(() => {
|
|
25
|
-
clock.restore();
|
|
26
|
-
});
|
|
27
|
-
(0, mocha_1.it)("fires on time", () => {
|
|
28
|
-
const timer = new index_js_1.TimerManager();
|
|
29
|
-
const handler = (0, sinon_1.spy)(() => node_assert_1.strict.strictEqual(Date.now(), 1100));
|
|
30
|
-
timer.setTimeout(handler, 100);
|
|
31
|
-
clock.tick(50);
|
|
32
|
-
node_assert_1.strict.strictEqual(handler.callCount, 0);
|
|
33
|
-
node_assert_1.strict.strictEqual(timer.hasExpired(), false);
|
|
34
|
-
clock.tick(100);
|
|
35
|
-
node_assert_1.strict.strictEqual(handler.callCount, 1);
|
|
36
|
-
node_assert_1.strict.strictEqual(timer.hasExpired(), true);
|
|
37
|
-
});
|
|
38
|
-
(0, mocha_1.it)("expire time is based on timeout", () => {
|
|
39
|
-
const timer = new index_js_1.TimerManager();
|
|
40
|
-
const handler = (0, sinon_1.spy)(() => undefined);
|
|
41
|
-
timer.setTimeout(handler, 50);
|
|
42
|
-
node_assert_1.strict.strictEqual(timer.expireTime, 1050);
|
|
43
|
-
node_assert_1.strict.strictEqual(timer.hasExpired(), false);
|
|
44
|
-
});
|
|
45
|
-
(0, mocha_1.it)("does not fire if cleared before timeout", () => {
|
|
46
|
-
const timer = new index_js_1.TimerManager();
|
|
47
|
-
const handler = (0, sinon_1.spy)(() => undefined);
|
|
48
|
-
timer.setTimeout(handler, 100);
|
|
49
|
-
clock.tick(50);
|
|
50
|
-
timer.clearTimeout();
|
|
51
|
-
node_assert_1.strict.strictEqual(handler.callCount, 0);
|
|
52
|
-
node_assert_1.strict.strictEqual(timer.hasExpired(), true);
|
|
53
|
-
});
|
|
54
|
-
(0, mocha_1.it)("does not fire on old timeout when new timeout set", () => {
|
|
55
|
-
const timer = new index_js_1.TimerManager();
|
|
56
|
-
const handler = (0, sinon_1.spy)(() => node_assert_1.strict.strictEqual(Date.now(), 1150));
|
|
57
|
-
timer.setTimeout(handler, 100);
|
|
58
|
-
node_assert_1.strict.strictEqual(timer.expireTime, 1100);
|
|
59
|
-
clock.tick(50);
|
|
60
|
-
timer.setTimeout(handler, 100);
|
|
61
|
-
node_assert_1.strict.strictEqual(timer.expireTime, 1150);
|
|
62
|
-
// advance to time 1120 - after the original timer should have fired, but before the new one.
|
|
63
|
-
clock.tick(70);
|
|
64
|
-
node_assert_1.strict.strictEqual(handler.callCount, 0);
|
|
65
|
-
// Advance past timeout
|
|
66
|
-
clock.tick(50);
|
|
67
|
-
node_assert_1.strict.strictEqual(timer.hasExpired(), true);
|
|
68
|
-
node_assert_1.strict.strictEqual(handler.callCount, 1);
|
|
69
|
-
});
|
|
70
|
-
(0, mocha_1.it)("fires correctly on reuse", () => {
|
|
71
|
-
const timer = new index_js_1.TimerManager();
|
|
72
|
-
const handler = (0, sinon_1.spy)(() => (0, node_assert_1.strict)(Date.now() === 1100));
|
|
73
|
-
timer.setTimeout(handler, 100);
|
|
74
|
-
clock.tick(200);
|
|
75
|
-
const handler2 = (0, sinon_1.spy)(() => node_assert_1.strict.strictEqual(Date.now(), 1300));
|
|
76
|
-
timer.setTimeout(handler2, 100);
|
|
77
|
-
clock.tick(200);
|
|
78
|
-
node_assert_1.strict.strictEqual(handler.callCount, 1);
|
|
79
|
-
node_assert_1.strict.strictEqual(handler2.callCount, 1);
|
|
80
|
-
});
|
|
81
|
-
(0, mocha_1.it)("multiple timers", () => {
|
|
82
|
-
const timer = new index_js_1.TimerManager();
|
|
83
|
-
const timer2 = new index_js_1.TimerManager();
|
|
84
|
-
const handler = (0, sinon_1.spy)(() => { });
|
|
85
|
-
const handler2 = (0, sinon_1.spy)(() => { });
|
|
86
|
-
timer.setTimeout(handler, 100);
|
|
87
|
-
timer2.setTimeout(handler2, 50);
|
|
88
|
-
clock.tick(200);
|
|
89
|
-
node_assert_1.strict.strictEqual(handler.callCount, 1);
|
|
90
|
-
node_assert_1.strict.strictEqual(handler2.callCount, 1);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
//# sourceMappingURL=timerManager.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"timerManager.spec.js","sourceRoot":"","sources":["../../../src/utils/test/timerManager.spec.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAEH,6CAA+C;AAE/C,iCAA2E;AAC3E,iCAAiE;AAEjE,0CAA2C;AAE3C,6EAA6E;AAC7E,IAAA,gBAAQ,EAAC,6BAA6B,EAAE,GAAG,EAAE;IAC5C,MAAM,WAAW,GAAG,IAAI,CAAC;IACzB,IAAI,KAAsB,CAAC;IAE3B,IAAA,cAAM,EAAC,KAAK,IAAI,EAAE;QACjB,KAAK,GAAG,IAAA,qBAAa,GAAE,CAAC;IACzB,CAAC,CAAC,CAAC;IAEH,IAAA,kBAAU,EAAC,GAAG,EAAE;QACf,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH,IAAA,iBAAS,EAAC,GAAG,EAAE;QACd,KAAK,CAAC,KAAK,EAAE,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,IAAA,aAAK,EAAC,GAAG,EAAE;QACV,KAAK,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,IAAA,UAAE,EAAC,eAAe,EAAE,GAAG,EAAE;QACxB,MAAM,KAAK,GAAG,IAAI,uBAAY,EAAE,CAAC;QACjC,MAAM,OAAO,GAAG,IAAA,WAAG,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AC;QAEhB,oBAAM,CAAC,WAAW,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QACzC,oBAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { strict as assert } from \"node:assert\";\n\nimport { describe, it, after, afterEach, before, beforeEach } from \"mocha\";\nimport { useFakeTimers, type SinonFakeTimers, spy } from \"sinon\";\n\nimport { TimerManager } from \"../index.js\";\n\n// TODO: separate Presence/Utils from TimerManager after file move is merged.\ndescribe(\"Presence/Utils:TimerManager\", () => {\n\tconst initialTime = 1000;\n\tlet clock: SinonFakeTimers;\n\n\tbefore(async () => {\n\t\tclock = useFakeTimers();\n\t});\n\n\tbeforeEach(() => {\n\t\tclock.setSystemTime(initialTime);\n\t});\n\n\tafterEach(() => {\n\t\tclock.reset();\n\t});\n\n\tafter(() => {\n\t\tclock.restore();\n\t});\n\n\tit(\"fires on time\", () => {\n\t\tconst timer = new TimerManager();\n\t\tconst handler = spy(() => assert.strictEqual(Date.now(), 1100));\n\t\ttimer.setTimeout(handler, 100);\n\n\t\tclock.tick(50);\n\t\tassert.strictEqual(handler.callCount, 0);\n\t\tassert.strictEqual(timer.hasExpired(), false);\n\n\t\tclock.tick(100);\n\t\tassert.strictEqual(handler.callCount, 1);\n\t\tassert.strictEqual(timer.hasExpired(), true);\n\t});\n\n\tit(\"expire time is based on timeout\", () => {\n\t\tconst timer = new TimerManager();\n\t\tconst handler = spy(() => undefined);\n\t\ttimer.setTimeout(handler, 50);\n\n\t\tassert.strictEqual(timer.expireTime, 1050);\n\t\tassert.strictEqual(timer.hasExpired(), false);\n\t});\n\n\tit(\"does not fire if cleared before timeout\", () => {\n\t\tconst timer = new TimerManager();\n\t\tconst handler = spy(() => undefined);\n\t\ttimer.setTimeout(handler, 100);\n\n\t\tclock.tick(50);\n\t\ttimer.clearTimeout();\n\n\t\tassert.strictEqual(handler.callCount, 0);\n\t\tassert.strictEqual(timer.hasExpired(), true);\n\t});\n\n\tit(\"does not fire on old timeout when new timeout set\", () => {\n\t\tconst timer = new TimerManager();\n\t\tconst handler = spy(() => assert.strictEqual(Date.now(), 1150));\n\t\ttimer.setTimeout(handler, 100);\n\t\tassert.strictEqual(timer.expireTime, 1100);\n\n\t\tclock.tick(50);\n\t\ttimer.setTimeout(handler, 100);\n\t\tassert.strictEqual(timer.expireTime, 1150);\n\n\t\t// advance to time 1120 - after the original timer should have fired, but before the new one.\n\t\tclock.tick(70);\n\t\tassert.strictEqual(handler.callCount, 0);\n\n\t\t// Advance past timeout\n\t\tclock.tick(50);\n\n\t\tassert.strictEqual(timer.hasExpired(), true);\n\t\tassert.strictEqual(handler.callCount, 1);\n\t});\n\n\tit(\"fires correctly on reuse\", () => {\n\t\tconst timer = new TimerManager();\n\t\tconst handler = spy(() => assert(Date.now() === 1100));\n\t\ttimer.setTimeout(handler, 100);\n\n\t\tclock.tick(200);\n\t\tconst handler2 = spy(() => assert.strictEqual(Date.now(), 1300));\n\t\ttimer.setTimeout(handler2, 100);\n\n\t\tclock.tick(200);\n\t\tassert.strictEqual(handler.callCount, 1);\n\t\tassert.strictEqual(handler2.callCount, 1);\n\t});\n\n\tit(\"multiple timers\", () => {\n\t\tconst timer = new TimerManager();\n\t\tconst timer2 = new TimerManager();\n\t\tconst handler = spy(() => {});\n\t\tconst handler2 = spy(() => {});\n\n\t\ttimer.setTimeout(handler, 100);\n\t\ttimer2.setTimeout(handler2, 50);\n\t\tclock.tick(200);\n\n\t\tassert.strictEqual(handler.callCount, 1);\n\t\tassert.strictEqual(handler2.callCount, 1);\n\t});\n});\n"]}
|