repluggable-core 0.0.0-pr280.413 → 0.0.0-pr282.418
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/__tests__/spec-setup.js +3 -0
- package/dist/es/{API.d.ts → src/API.d.ts} +31 -10
- package/dist/es/src/API.d.ts.map +1 -0
- package/dist/es/src/API.js +2 -0
- package/dist/es/src/API.js.map +1 -0
- package/dist/es/src/IterableWeakMap.d.ts +20 -0
- package/dist/es/src/IterableWeakMap.d.ts.map +1 -0
- package/dist/es/src/IterableWeakMap.js +92 -0
- package/dist/es/src/IterableWeakMap.js.map +1 -0
- package/dist/es/src/appHost.d.ts +7 -0
- package/dist/es/src/appHost.d.ts.map +1 -0
- package/dist/es/src/appHost.js +848 -0
- package/dist/es/src/appHost.js.map +1 -0
- package/dist/es/src/appHostServices.d.ts +12 -0
- package/dist/es/src/appHostServices.d.ts.map +1 -0
- package/dist/es/src/appHostServices.js +25 -0
- package/dist/es/src/appHostServices.js.map +1 -0
- package/dist/es/src/appHostUtils.d.ts +4 -0
- package/dist/es/src/appHostUtils.d.ts.map +1 -0
- package/dist/es/src/appHostUtils.js +8 -0
- package/dist/es/src/appHostUtils.js.map +1 -0
- package/dist/es/src/extensionSlot.d.ts +8 -0
- package/dist/es/src/extensionSlot.d.ts.map +1 -0
- package/dist/es/src/extensionSlot.js +59 -0
- package/dist/es/src/extensionSlot.js.map +1 -0
- package/dist/es/src/hot.d.ts +14 -0
- package/dist/es/src/hot.d.ts.map +1 -0
- package/dist/es/src/hot.js +52 -0
- package/dist/es/src/hot.js.map +1 -0
- package/dist/es/src/index.d.ts +11 -0
- package/dist/es/src/index.d.ts.map +1 -0
- package/dist/es/src/index.js +10 -0
- package/dist/es/src/index.js.map +1 -0
- package/dist/es/src/installedShellsState.d.ts +19 -0
- package/dist/es/src/installedShellsState.d.ts.map +1 -0
- package/dist/es/src/installedShellsState.js +30 -0
- package/dist/es/src/installedShellsState.js.map +1 -0
- package/dist/es/src/interceptAnyObject.d.ts +7 -0
- package/dist/es/src/interceptAnyObject.d.ts.map +1 -0
- package/dist/es/src/interceptAnyObject.js +21 -0
- package/dist/es/src/interceptAnyObject.js.map +1 -0
- package/dist/es/src/interceptEntryPoints.d.ts +6 -0
- package/dist/es/src/interceptEntryPoints.d.ts.map +1 -0
- package/dist/es/src/interceptEntryPoints.js +22 -0
- package/dist/es/src/interceptEntryPoints.js.map +1 -0
- package/dist/es/src/invokeSlotCallbacks.d.ts +3 -0
- package/dist/es/src/invokeSlotCallbacks.d.ts.map +1 -0
- package/dist/es/src/invokeSlotCallbacks.js +20 -0
- package/dist/es/src/invokeSlotCallbacks.js.map +1 -0
- package/dist/es/src/loggers.d.ts +4 -0
- package/dist/es/src/loggers.d.ts.map +1 -0
- package/dist/es/src/loggers.js +100 -0
- package/dist/es/src/loggers.js.map +1 -0
- package/dist/es/src/monitorAPI.d.ts +3 -0
- package/dist/es/src/monitorAPI.d.ts.map +1 -0
- package/dist/es/src/monitorAPI.js +53 -0
- package/dist/es/src/monitorAPI.js.map +1 -0
- package/dist/es/src/repluggableAppDebug/index.d.ts +2 -0
- package/dist/es/src/repluggableAppDebug/index.d.ts.map +1 -0
- package/dist/es/src/repluggableAppDebug/index.js +2 -0
- package/dist/es/src/repluggableAppDebug/index.js.map +1 -0
- package/dist/es/src/repluggableAppDebug/performanceDebugInfo.d.ts +15 -0
- package/dist/es/src/repluggableAppDebug/performanceDebugInfo.d.ts.map +1 -0
- package/dist/es/src/repluggableAppDebug/performanceDebugInfo.js +94 -0
- package/dist/es/src/repluggableAppDebug/performanceDebugInfo.js.map +1 -0
- package/dist/es/src/repluggableAppDebug/repluggableAppDebug.d.ts +24 -0
- package/dist/es/src/repluggableAppDebug/repluggableAppDebug.d.ts.map +1 -0
- package/dist/es/src/repluggableAppDebug/repluggableAppDebug.js +132 -0
- package/dist/es/src/repluggableAppDebug/repluggableAppDebug.js.map +1 -0
- package/dist/es/src/tarjanGraph.d.ts +27 -0
- package/dist/es/src/tarjanGraph.d.ts.map +1 -0
- package/dist/es/src/tarjanGraph.js +94 -0
- package/dist/es/src/tarjanGraph.js.map +1 -0
- package/dist/es/src/throttledStore.d.ts +32 -0
- package/dist/es/src/throttledStore.d.ts.map +1 -0
- package/dist/es/src/throttledStore.js +240 -0
- package/dist/es/src/throttledStore.js.map +1 -0
- package/dist/es/test/IterableWeakMap.spec.d.ts +2 -0
- package/dist/es/test/IterableWeakMap.spec.d.ts.map +1 -0
- package/dist/es/test/IterableWeakMap.spec.js +218 -0
- package/dist/es/test/IterableWeakMap.spec.js.map +1 -0
- package/dist/es/test/appHost.mock.d.ts +4 -0
- package/dist/es/test/appHost.mock.d.ts.map +1 -0
- package/dist/es/test/appHost.mock.js +54 -0
- package/dist/es/test/appHost.mock.js.map +1 -0
- package/dist/es/test/appHost.spec.d.ts +2 -0
- package/dist/es/test/appHost.spec.d.ts.map +1 -0
- package/dist/es/test/appHost.spec.js +1323 -0
- package/dist/es/test/appHost.spec.js.map +1 -0
- package/dist/es/test/customExtensionSlot.spec.d.ts +2 -0
- package/dist/es/test/customExtensionSlot.spec.d.ts.map +1 -0
- package/dist/es/test/customExtensionSlot.spec.js +112 -0
- package/dist/es/test/customExtensionSlot.spec.js.map +1 -0
- package/dist/es/test/extensionSlot.spec.d.ts +2 -0
- package/dist/es/test/extensionSlot.spec.d.ts.map +1 -0
- package/dist/es/test/extensionSlot.spec.js +73 -0
- package/dist/es/test/extensionSlot.spec.js.map +1 -0
- package/dist/es/test/installedShellsState.spec.d.ts +2 -0
- package/dist/es/test/installedShellsState.spec.d.ts.map +1 -0
- package/dist/es/test/installedShellsState.spec.js +28 -0
- package/dist/es/test/installedShellsState.spec.js.map +1 -0
- package/dist/es/test/interceptAnyObject.spec.d.ts +2 -0
- package/dist/es/test/interceptAnyObject.spec.d.ts.map +1 -0
- package/dist/es/test/interceptAnyObject.spec.js +166 -0
- package/dist/es/test/interceptAnyObject.spec.js.map +1 -0
- package/dist/es/test/interceptEntryPoints.spec.d.ts +2 -0
- package/dist/es/test/interceptEntryPoints.spec.d.ts.map +1 -0
- package/dist/es/test/interceptEntryPoints.spec.js +244 -0
- package/dist/es/test/interceptEntryPoints.spec.js.map +1 -0
- package/dist/es/test/loggers.spec.d.ts +2 -0
- package/dist/es/test/loggers.spec.d.ts.map +1 -0
- package/dist/es/test/loggers.spec.js +218 -0
- package/dist/es/test/loggers.spec.js.map +1 -0
- package/dist/es/test/repluggableAppDebug.spec.d.ts +2 -0
- package/dist/es/test/repluggableAppDebug.spec.d.ts.map +1 -0
- package/dist/es/test/repluggableAppDebug.spec.js +107 -0
- package/dist/es/test/repluggableAppDebug.spec.js.map +1 -0
- package/dist/es/test/testKit.spec.d.ts +2 -0
- package/dist/es/test/testKit.spec.d.ts.map +1 -0
- package/dist/es/test/testKit.spec.js +129 -0
- package/dist/es/test/testKit.spec.js.map +1 -0
- package/dist/es/testKit/emptyLoggerOptions.d.ts +3 -0
- package/dist/es/testKit/emptyLoggerOptions.d.ts.map +1 -0
- package/dist/es/testKit/emptyLoggerOptions.js +15 -0
- package/dist/es/testKit/emptyLoggerOptions.js.map +1 -0
- package/dist/es/testKit/index.d.ts +25 -0
- package/dist/es/testKit/index.d.ts.map +1 -0
- package/dist/es/testKit/index.js +130 -0
- package/dist/es/testKit/index.js.map +1 -0
- package/dist/es/testKit/mockPackage.d.ts +21 -0
- package/dist/es/testKit/mockPackage.d.ts.map +1 -0
- package/dist/es/testKit/mockPackage.js +85 -0
- package/dist/es/testKit/mockPackage.js.map +1 -0
- package/dist/es/testKit/withConsoleErrors.d.ts +2 -0
- package/dist/es/testKit/withConsoleErrors.d.ts.map +1 -0
- package/dist/es/testKit/withConsoleErrors.js +12 -0
- package/dist/es/testKit/withConsoleErrors.js.map +1 -0
- package/dist/es/testKit/withThrowOnError.d.ts +3 -0
- package/dist/es/testKit/withThrowOnError.d.ts.map +1 -0
- package/dist/es/testKit/withThrowOnError.js +27 -0
- package/dist/es/testKit/withThrowOnError.js.map +1 -0
- package/dist/src/API.d.ts +31 -10
- package/dist/src/API.d.ts.map +1 -1
- package/dist/src/API.js +3 -0
- package/dist/src/API.js.map +1 -1
- package/dist/src/IterableWeakMap.d.ts +20 -0
- package/dist/src/IterableWeakMap.d.ts.map +1 -0
- package/dist/src/IterableWeakMap.js +96 -0
- package/dist/src/IterableWeakMap.js.map +1 -0
- package/dist/src/appHost.d.ts +7 -0
- package/dist/src/appHost.d.ts.map +1 -0
- package/dist/src/appHost.js +856 -0
- package/dist/src/appHost.js.map +1 -0
- package/dist/src/appHostServices.d.ts +12 -0
- package/dist/src/appHostServices.d.ts.map +1 -0
- package/dist/src/appHostServices.js +29 -0
- package/dist/src/appHostServices.js.map +1 -0
- package/dist/src/appHostUtils.d.ts +4 -0
- package/dist/src/appHostUtils.d.ts.map +1 -0
- package/dist/src/appHostUtils.js +16 -0
- package/dist/src/appHostUtils.js.map +1 -0
- package/dist/src/extensionSlot.d.ts +8 -0
- package/dist/src/extensionSlot.d.ts.map +1 -0
- package/dist/src/extensionSlot.js +67 -0
- package/dist/src/extensionSlot.js.map +1 -0
- package/dist/src/hot.d.ts +14 -0
- package/dist/src/hot.d.ts.map +1 -0
- package/dist/src/hot.js +56 -0
- package/dist/src/hot.js.map +1 -0
- package/dist/src/index.d.ts +10 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +23 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/installedShellsState.d.ts +19 -0
- package/dist/src/installedShellsState.d.ts.map +1 -0
- package/dist/src/installedShellsState.js +38 -0
- package/dist/src/installedShellsState.js.map +1 -0
- package/dist/src/interceptAnyObject.d.ts +7 -0
- package/dist/src/interceptAnyObject.d.ts.map +1 -0
- package/dist/src/interceptAnyObject.js +28 -0
- package/dist/src/interceptAnyObject.js.map +1 -0
- package/dist/src/interceptEntryPoints.d.ts +6 -0
- package/dist/src/interceptEntryPoints.d.ts.map +1 -0
- package/dist/src/interceptEntryPoints.js +30 -0
- package/dist/src/interceptEntryPoints.js.map +1 -0
- package/dist/src/invokeSlotCallbacks.d.ts +3 -0
- package/dist/src/invokeSlotCallbacks.d.ts.map +1 -0
- package/dist/src/invokeSlotCallbacks.js +24 -0
- package/dist/src/invokeSlotCallbacks.js.map +1 -0
- package/dist/src/loggers.d.ts +4 -0
- package/dist/src/loggers.d.ts.map +1 -0
- package/dist/src/loggers.js +104 -0
- package/dist/src/loggers.js.map +1 -0
- package/dist/src/monitorAPI.d.ts +3 -0
- package/dist/src/monitorAPI.d.ts.map +1 -0
- package/dist/src/monitorAPI.js +57 -0
- package/dist/src/monitorAPI.js.map +1 -0
- package/dist/src/repluggableAppDebug/index.d.ts +2 -0
- package/dist/src/repluggableAppDebug/index.d.ts.map +1 -0
- package/dist/src/repluggableAppDebug/index.js +6 -0
- package/dist/src/repluggableAppDebug/index.js.map +1 -0
- package/dist/src/repluggableAppDebug/performanceDebugInfo.d.ts +15 -0
- package/dist/src/repluggableAppDebug/performanceDebugInfo.d.ts.map +1 -0
- package/dist/src/repluggableAppDebug/performanceDebugInfo.js +101 -0
- package/dist/src/repluggableAppDebug/performanceDebugInfo.js.map +1 -0
- package/dist/src/repluggableAppDebug/repluggableAppDebug.d.ts +24 -0
- package/dist/src/repluggableAppDebug/repluggableAppDebug.d.ts.map +1 -0
- package/dist/src/repluggableAppDebug/repluggableAppDebug.js +139 -0
- package/dist/src/repluggableAppDebug/repluggableAppDebug.js.map +1 -0
- package/dist/src/tarjanGraph.d.ts +27 -0
- package/dist/src/tarjanGraph.d.ts.map +1 -0
- package/dist/src/tarjanGraph.js +100 -0
- package/dist/src/tarjanGraph.js.map +1 -0
- package/dist/src/throttledStore.d.ts +32 -0
- package/dist/src/throttledStore.d.ts.map +1 -0
- package/dist/src/throttledStore.js +249 -0
- package/dist/src/throttledStore.js.map +1 -0
- package/dist/test/IterableWeakMap.spec.d.ts +2 -0
- package/dist/test/IterableWeakMap.spec.d.ts.map +1 -0
- package/dist/test/IterableWeakMap.spec.js +220 -0
- package/dist/test/IterableWeakMap.spec.js.map +1 -0
- package/dist/test/appHost.mock.d.ts +4 -0
- package/dist/test/appHost.mock.d.ts.map +1 -0
- package/dist/test/appHost.mock.js +59 -0
- package/dist/test/appHost.mock.js.map +1 -0
- package/dist/test/appHost.spec.d.ts +2 -0
- package/dist/test/appHost.spec.d.ts.map +1 -0
- package/dist/test/appHost.spec.js +1328 -0
- package/dist/test/appHost.spec.js.map +1 -0
- package/dist/test/customExtensionSlot.spec.d.ts +2 -0
- package/dist/test/customExtensionSlot.spec.d.ts.map +1 -0
- package/dist/test/customExtensionSlot.spec.js +117 -0
- package/dist/test/customExtensionSlot.spec.js.map +1 -0
- package/dist/test/extensionSlot.spec.d.ts +2 -0
- package/dist/test/extensionSlot.spec.d.ts.map +1 -0
- package/dist/test/extensionSlot.spec.js +75 -0
- package/dist/test/extensionSlot.spec.js.map +1 -0
- package/dist/test/installedShellsState.spec.d.ts +2 -0
- package/dist/test/installedShellsState.spec.d.ts.map +1 -0
- package/dist/test/installedShellsState.spec.js +30 -0
- package/dist/test/installedShellsState.spec.js.map +1 -0
- package/dist/test/interceptAnyObject.spec.d.ts +2 -0
- package/dist/test/interceptAnyObject.spec.d.ts.map +1 -0
- package/dist/test/interceptAnyObject.spec.js +171 -0
- package/dist/test/interceptAnyObject.spec.js.map +1 -0
- package/dist/test/interceptEntryPoints.spec.d.ts +2 -0
- package/dist/test/interceptEntryPoints.spec.d.ts.map +1 -0
- package/dist/test/interceptEntryPoints.spec.js +249 -0
- package/dist/test/interceptEntryPoints.spec.js.map +1 -0
- package/dist/test/loggers.spec.d.ts +2 -0
- package/dist/test/loggers.spec.d.ts.map +1 -0
- package/dist/test/loggers.spec.js +220 -0
- package/dist/test/loggers.spec.js.map +1 -0
- package/dist/test/repluggableAppDebug.spec.d.ts +2 -0
- package/dist/test/repluggableAppDebug.spec.d.ts.map +1 -0
- package/dist/test/repluggableAppDebug.spec.js +109 -0
- package/dist/test/repluggableAppDebug.spec.js.map +1 -0
- package/dist/test/testKit.spec.d.ts +2 -0
- package/dist/test/testKit.spec.d.ts.map +1 -0
- package/dist/test/testKit.spec.js +134 -0
- package/dist/test/testKit.spec.js.map +1 -0
- package/dist/testKit/emptyLoggerOptions.d.ts +3 -0
- package/dist/testKit/emptyLoggerOptions.d.ts.map +1 -0
- package/dist/testKit/emptyLoggerOptions.js +18 -0
- package/dist/testKit/emptyLoggerOptions.js.map +1 -0
- package/dist/testKit/index.d.ts +25 -0
- package/dist/testKit/index.d.ts.map +1 -0
- package/dist/testKit/index.js +158 -0
- package/dist/testKit/index.js.map +1 -0
- package/dist/testKit/mockPackage.d.ts +21 -0
- package/dist/testKit/mockPackage.d.ts.map +1 -0
- package/dist/testKit/mockPackage.js +91 -0
- package/dist/testKit/mockPackage.js.map +1 -0
- package/dist/testKit/withConsoleErrors.d.ts +2 -0
- package/dist/testKit/withConsoleErrors.d.ts.map +1 -0
- package/dist/testKit/withConsoleErrors.js +16 -0
- package/dist/testKit/withConsoleErrors.js.map +1 -0
- package/dist/testKit/withThrowOnError.d.ts +3 -0
- package/dist/testKit/withThrowOnError.d.ts.map +1 -0
- package/dist/testKit/withThrowOnError.js +31 -0
- package/dist/testKit/withThrowOnError.js.map +1 -0
- package/jest.config.js +16 -0
- package/package.json +5 -3
- package/src/API.ts +474 -378
- package/src/IterableWeakMap.ts +121 -0
- package/src/appHost.ts +1383 -0
- package/src/appHostServices.ts +42 -0
- package/src/appHostUtils.ts +11 -0
- package/src/extensionSlot.ts +96 -0
- package/src/hot.ts +53 -0
- package/src/index.ts +55 -3
- package/src/installedShellsState.ts +54 -0
- package/src/interceptAnyObject.ts +39 -0
- package/src/interceptEntryPoints.ts +25 -0
- package/src/invokeSlotCallbacks.ts +20 -0
- package/src/loggers.ts +112 -0
- package/src/monitorAPI.ts +71 -0
- package/src/repluggableAppDebug/debug.d.ts +37 -0
- package/src/repluggableAppDebug/index.ts +1 -0
- package/src/repluggableAppDebug/performanceDebugInfo.ts +96 -0
- package/src/repluggableAppDebug/repluggableAppDebug.ts +192 -0
- package/src/tarjanGraph.ts +96 -0
- package/src/throttledStore.ts +355 -0
- package/test/IterableWeakMap.spec.ts +284 -0
- package/test/appHost.mock.ts +58 -0
- package/test/appHost.spec.ts +1629 -0
- package/test/customExtensionSlot.spec.ts +153 -0
- package/test/extensionSlot.spec.ts +94 -0
- package/test/installedShellsState.spec.ts +39 -0
- package/test/interceptAnyObject.spec.ts +217 -0
- package/test/interceptEntryPoints.spec.ts +291 -0
- package/test/loggers.spec.ts +288 -0
- package/test/repluggableAppDebug.spec.ts +118 -0
- package/test/testKit.spec.tsx +153 -0
- package/testKit/emptyLoggerOptions.ts +16 -0
- package/testKit/index.ts +172 -0
- package/testKit/mockPackage.ts +99 -0
- package/testKit/package.json +3 -0
- package/testKit/withConsoleErrors.ts +12 -0
- package/testKit/withThrowOnError.ts +34 -0
- package/tsconfig.json +11 -1
- package/dist/es/API.d.ts.map +0 -1
- package/dist/es/API.js +0 -2
- package/dist/es/API.js.map +0 -1
- package/dist/es/index.d.ts +0 -2
- package/dist/es/index.d.ts.map +0 -1
- package/dist/es/index.js +0 -2
- package/dist/es/index.js.map +0 -1
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import _ from 'lodash'
|
|
2
|
+
import { EntryPoint, EntryPointInterceptor } from '../src/API'
|
|
3
|
+
import { interceptEntryPoints, interceptEntryPointsMap } from '../src/interceptEntryPoints'
|
|
4
|
+
import { createAppHost } from '../testKit'
|
|
5
|
+
|
|
6
|
+
type LogSpy = jest.Mock<void, string[]>
|
|
7
|
+
|
|
8
|
+
function takeLog(spy: LogSpy): string[] {
|
|
9
|
+
return _.flatten(spy.mock.calls)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function takeAndClearLog(spy: LogSpy): string[] {
|
|
13
|
+
const result = takeLog(spy)
|
|
14
|
+
spy.mockClear()
|
|
15
|
+
return result
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe('interceptEntryPoints', () => {
|
|
19
|
+
it('should intercept name', () => {
|
|
20
|
+
const spy: LogSpy = jest.fn()
|
|
21
|
+
|
|
22
|
+
const entryPoints = createTestEntryPoints(2, spy)
|
|
23
|
+
const interceptor = createTestInterceptor(spy, 'INTR1', { interceptName: true })
|
|
24
|
+
const intercepted = interceptEntryPoints(entryPoints, interceptor)
|
|
25
|
+
|
|
26
|
+
expect(intercepted[0].name).toBe('INTR1!EP-0')
|
|
27
|
+
expect(intercepted[1].name).toBe('INTR1!EP-1')
|
|
28
|
+
})
|
|
29
|
+
it('should intercept tags', () => {
|
|
30
|
+
const spy: LogSpy = jest.fn()
|
|
31
|
+
|
|
32
|
+
const entryPoints = createTestEntryPoints(2, spy)
|
|
33
|
+
const interceptor = createTestInterceptor(spy, 'INTR1', { interceptTags: true })
|
|
34
|
+
const intercepted = interceptEntryPoints(entryPoints, interceptor)
|
|
35
|
+
|
|
36
|
+
expect(intercepted[0].tags).toMatchObject({ test_ep_index: '0', intercepted_by: 'INTR1' })
|
|
37
|
+
expect(intercepted[1].tags).toMatchObject({ test_ep_index: '1', intercepted_by: 'INTR1' })
|
|
38
|
+
})
|
|
39
|
+
it('should intercept attach', () => {
|
|
40
|
+
const spy: LogSpy = jest.fn()
|
|
41
|
+
|
|
42
|
+
const entryPoints = createTestEntryPoints(1, spy)
|
|
43
|
+
const interceptor = createTestInterceptor(spy, 'INTR1', { interceptAttach: true })
|
|
44
|
+
const intercepted = interceptEntryPoints(entryPoints, interceptor)
|
|
45
|
+
|
|
46
|
+
intercepted[0].attach && intercepted[0].attach({} as any)
|
|
47
|
+
|
|
48
|
+
expect(takeLog(spy)).toEqual(['INTR1:attach', 'EP-0:attach'])
|
|
49
|
+
})
|
|
50
|
+
it('should intercept extend', () => {
|
|
51
|
+
const spy: LogSpy = jest.fn()
|
|
52
|
+
|
|
53
|
+
const entryPoints = createTestEntryPoints(1, spy)
|
|
54
|
+
const interceptor = createTestInterceptor(spy, 'INTR1', { interceptExtend: true })
|
|
55
|
+
const intercepted = interceptEntryPoints(entryPoints, interceptor)
|
|
56
|
+
|
|
57
|
+
intercepted[0].extend && intercepted[0].extend({} as any)
|
|
58
|
+
|
|
59
|
+
expect(takeLog(spy)).toEqual(['INTR1:extend', 'EP-0:extend'])
|
|
60
|
+
})
|
|
61
|
+
it('should intercept detach', () => {
|
|
62
|
+
const spy: LogSpy = jest.fn()
|
|
63
|
+
|
|
64
|
+
const entryPoints = createTestEntryPoints(1, spy)
|
|
65
|
+
const interceptor = createTestInterceptor(spy, 'INTR1', { interceptDetach: true })
|
|
66
|
+
const intercepted = interceptEntryPoints(entryPoints, interceptor)
|
|
67
|
+
|
|
68
|
+
intercepted[0].detach && intercepted[0].detach({} as any)
|
|
69
|
+
|
|
70
|
+
expect(takeLog(spy)).toEqual(['INTR1:detach', 'EP-0:detach'])
|
|
71
|
+
})
|
|
72
|
+
it('should intercept declareAPIs', () => {
|
|
73
|
+
const spy: LogSpy = jest.fn()
|
|
74
|
+
|
|
75
|
+
const entryPoints = createTestEntryPoints(1, spy)
|
|
76
|
+
const interceptor = createTestInterceptor(spy, 'I1', { interceptDeclareAPIs: true })
|
|
77
|
+
const intercepted = interceptEntryPoints(entryPoints, interceptor)
|
|
78
|
+
|
|
79
|
+
intercepted[0].declareAPIs && intercepted[0].declareAPIs()
|
|
80
|
+
|
|
81
|
+
expect(takeLog(spy)).toEqual(['I1:declareAPIs', 'EP-0:declareAPIs'])
|
|
82
|
+
})
|
|
83
|
+
it('should intercept getDependencyAPIs', () => {
|
|
84
|
+
const spy: LogSpy = jest.fn()
|
|
85
|
+
|
|
86
|
+
const entryPoints = createTestEntryPoints(1, spy)
|
|
87
|
+
const interceptor = createTestInterceptor(spy, 'I1', { interceptGetDependencyAPIs: true })
|
|
88
|
+
const intercepted = interceptEntryPoints(entryPoints, interceptor)
|
|
89
|
+
|
|
90
|
+
intercepted[0].getDependencyAPIs && intercepted[0].getDependencyAPIs()
|
|
91
|
+
|
|
92
|
+
expect(takeLog(spy)).toEqual(['I1:getDependencyAPIs', 'EP-0:getDependencyAPIs'])
|
|
93
|
+
})
|
|
94
|
+
it('should invoke original if not intercepted', () => {
|
|
95
|
+
const spy: LogSpy = jest.fn()
|
|
96
|
+
|
|
97
|
+
const entryPoints = createTestEntryPoints(1, spy)
|
|
98
|
+
const interceptor = createTestInterceptor(spy, 'INTR1', {}) // flags are all false
|
|
99
|
+
const intercepted = interceptEntryPoints(entryPoints, interceptor)
|
|
100
|
+
|
|
101
|
+
const interceptedName = intercepted[0].name
|
|
102
|
+
intercepted[0].attach && intercepted[0].attach({} as any)
|
|
103
|
+
intercepted[0].extend && intercepted[0].extend({} as any)
|
|
104
|
+
intercepted[0].detach && intercepted[0].detach({} as any)
|
|
105
|
+
intercepted[0].getDependencyAPIs && intercepted[0].getDependencyAPIs()
|
|
106
|
+
intercepted[0].declareAPIs && intercepted[0].declareAPIs()
|
|
107
|
+
|
|
108
|
+
expect(interceptedName).toBe('EP-0')
|
|
109
|
+
expect(takeLog(spy)).toEqual(['EP-0:attach', 'EP-0:extend', 'EP-0:detach', 'EP-0:getDependencyAPIs', 'EP-0:declareAPIs'])
|
|
110
|
+
})
|
|
111
|
+
it('should allow multiple interceptors', () => {
|
|
112
|
+
const spy: LogSpy = jest.fn()
|
|
113
|
+
|
|
114
|
+
const entryPoints = createTestEntryPoints(3, spy)
|
|
115
|
+
const interceptor1 = createTestInterceptor(spy, 'I1', { interceptAttach: true })
|
|
116
|
+
const interceptor2 = createTestInterceptor(spy, 'I2', { interceptAttach: true })
|
|
117
|
+
const intercepted1 = interceptEntryPoints(entryPoints[0], interceptor1)
|
|
118
|
+
const intercepted2 = interceptEntryPoints(intercepted1, interceptor2)
|
|
119
|
+
|
|
120
|
+
intercepted2[0].attach && intercepted2[0].attach({} as any)
|
|
121
|
+
|
|
122
|
+
expect(takeLog(spy)).toEqual(['I2:attach', 'I1:attach', 'EP-0:attach'])
|
|
123
|
+
})
|
|
124
|
+
it('should apply single interceptor to map of entry points', () => {
|
|
125
|
+
const spy: LogSpy = jest.fn()
|
|
126
|
+
|
|
127
|
+
const entryPoints = createTestEntryPoints(3, spy)
|
|
128
|
+
const packagesMap = {
|
|
129
|
+
one: entryPoints[0],
|
|
130
|
+
two: [entryPoints[1], entryPoints[2]]
|
|
131
|
+
}
|
|
132
|
+
const interceptor = createTestInterceptor(spy, 'I1', { interceptAttach: true })
|
|
133
|
+
const interceptedMap = interceptEntryPointsMap(packagesMap, interceptor)
|
|
134
|
+
const intercepted = [
|
|
135
|
+
(interceptedMap.one as EntryPoint[])[0],
|
|
136
|
+
(interceptedMap.two as EntryPoint[])[0],
|
|
137
|
+
(interceptedMap.two as EntryPoint[])[1]
|
|
138
|
+
]
|
|
139
|
+
|
|
140
|
+
intercepted[0].attach && intercepted[0].attach({} as any)
|
|
141
|
+
const logOne0 = takeAndClearLog(spy)
|
|
142
|
+
|
|
143
|
+
intercepted[1].attach && intercepted[1].attach({} as any)
|
|
144
|
+
const logTwo0 = takeAndClearLog(spy)
|
|
145
|
+
|
|
146
|
+
intercepted[2].attach && intercepted[2].attach({} as any)
|
|
147
|
+
const logTwo1 = takeAndClearLog(spy)
|
|
148
|
+
|
|
149
|
+
expect(typeof interceptedMap).toBe('object')
|
|
150
|
+
expect(logOne0).toEqual(['I1:attach', 'EP-0:attach'])
|
|
151
|
+
expect(logTwo0).toEqual(['I1:attach', 'EP-1:attach'])
|
|
152
|
+
expect(logTwo1).toEqual(['I1:attach', 'EP-2:attach'])
|
|
153
|
+
})
|
|
154
|
+
it('should apply multiple interceptors to map of entry points', () => {
|
|
155
|
+
const spy: LogSpy = jest.fn()
|
|
156
|
+
|
|
157
|
+
const entryPoints = createTestEntryPoints(3, spy)
|
|
158
|
+
const packagesMap = {
|
|
159
|
+
one: entryPoints[0],
|
|
160
|
+
two: [entryPoints[1], entryPoints[2]]
|
|
161
|
+
}
|
|
162
|
+
const interceptor1 = createTestInterceptor(spy, 'I1', { interceptAttach: true })
|
|
163
|
+
const interceptor2 = createTestInterceptor(spy, 'I2', { interceptAttach: true })
|
|
164
|
+
const interceptedMap1 = interceptEntryPointsMap(packagesMap, interceptor1)
|
|
165
|
+
const interceptedMap2 = interceptEntryPointsMap(interceptedMap1, interceptor2)
|
|
166
|
+
const intercepted = [
|
|
167
|
+
(interceptedMap2.one as EntryPoint[])[0],
|
|
168
|
+
(interceptedMap2.two as EntryPoint[])[0],
|
|
169
|
+
(interceptedMap2.two as EntryPoint[])[1]
|
|
170
|
+
]
|
|
171
|
+
|
|
172
|
+
intercepted[0].attach && intercepted[0].attach({} as any)
|
|
173
|
+
const logOne0 = takeAndClearLog(spy)
|
|
174
|
+
|
|
175
|
+
intercepted[1].attach && intercepted[1].attach({} as any)
|
|
176
|
+
const logTwo0 = takeAndClearLog(spy)
|
|
177
|
+
|
|
178
|
+
intercepted[2].attach && intercepted[2].attach({} as any)
|
|
179
|
+
const logTwo1 = takeAndClearLog(spy)
|
|
180
|
+
|
|
181
|
+
expect(typeof interceptedMap1).toBe('object')
|
|
182
|
+
expect(logOne0).toEqual(['I2:attach', 'I1:attach', 'EP-0:attach'])
|
|
183
|
+
expect(logTwo0).toEqual(['I2:attach', 'I1:attach', 'EP-1:attach'])
|
|
184
|
+
expect(logTwo1).toEqual(['I2:attach', 'I1:attach', 'EP-2:attach'])
|
|
185
|
+
})
|
|
186
|
+
it('should be able to add intercepted entry point to AppHost', () => {
|
|
187
|
+
const spy: LogSpy = jest.fn()
|
|
188
|
+
|
|
189
|
+
const entryPoints = createTestEntryPoints(1, spy)
|
|
190
|
+
const interceptor = createTestInterceptor(spy, 'I1', { interceptAttach: true, interceptExtend: true })
|
|
191
|
+
const intercepted = interceptEntryPoints(entryPoints, interceptor)
|
|
192
|
+
|
|
193
|
+
createAppHost(intercepted, {
|
|
194
|
+
monitoring: {}
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
// getDependencyAPIs appears to be called multiple times
|
|
198
|
+
expect(_.uniq(takeLog(spy))).toEqual([
|
|
199
|
+
'EP-0:declareAPIs', // called because of circular validation
|
|
200
|
+
'EP-0:getDependencyAPIs',
|
|
201
|
+
'I1:attach',
|
|
202
|
+
'EP-0:attach',
|
|
203
|
+
'I1:extend',
|
|
204
|
+
'EP-0:extend'
|
|
205
|
+
])
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
type TestInterceptorFlags = { [P in keyof EntryPointInterceptor]?: boolean }
|
|
210
|
+
|
|
211
|
+
function createTestEntryPoints(count: number, spy: LogSpy): EntryPoint[] {
|
|
212
|
+
return _.times(count).map<EntryPoint>(index => ({
|
|
213
|
+
name: `EP-${index}`,
|
|
214
|
+
tags: { test_ep_index: `${index}` },
|
|
215
|
+
getDependencyAPIs() {
|
|
216
|
+
spy(`EP-${index}:getDependencyAPIs`)
|
|
217
|
+
return []
|
|
218
|
+
},
|
|
219
|
+
declareAPIs() {
|
|
220
|
+
spy(`EP-${index}:declareAPIs`)
|
|
221
|
+
return []
|
|
222
|
+
},
|
|
223
|
+
attach() {
|
|
224
|
+
spy(`EP-${index}:attach`)
|
|
225
|
+
return []
|
|
226
|
+
},
|
|
227
|
+
extend() {
|
|
228
|
+
spy(`EP-${index}:extend`)
|
|
229
|
+
return []
|
|
230
|
+
},
|
|
231
|
+
detach() {
|
|
232
|
+
spy(`EP-${index}:detach`)
|
|
233
|
+
return []
|
|
234
|
+
}
|
|
235
|
+
}))
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function createTestInterceptor(spy: LogSpy, interceptorName: string, flags: TestInterceptorFlags): EntryPointInterceptor {
|
|
239
|
+
return {
|
|
240
|
+
interceptName: flags.interceptName
|
|
241
|
+
? name => {
|
|
242
|
+
return `${interceptorName}!${name}`
|
|
243
|
+
}
|
|
244
|
+
: undefined,
|
|
245
|
+
interceptTags: flags.interceptTags
|
|
246
|
+
? tags => {
|
|
247
|
+
return { intercepted_by: interceptorName, ...tags }
|
|
248
|
+
}
|
|
249
|
+
: undefined,
|
|
250
|
+
interceptDeclareAPIs: flags.interceptDeclareAPIs
|
|
251
|
+
? innerDeclareAPIs => {
|
|
252
|
+
return () => {
|
|
253
|
+
spy(`${interceptorName}:declareAPIs`)
|
|
254
|
+
return (innerDeclareAPIs && innerDeclareAPIs()) || []
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
: undefined,
|
|
258
|
+
interceptGetDependencyAPIs: flags.interceptGetDependencyAPIs
|
|
259
|
+
? innerGetDependencyAPIs => {
|
|
260
|
+
return () => {
|
|
261
|
+
spy(`${interceptorName}:getDependencyAPIs`)
|
|
262
|
+
return (innerGetDependencyAPIs && innerGetDependencyAPIs()) || []
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
: undefined,
|
|
266
|
+
interceptAttach: flags.interceptAttach
|
|
267
|
+
? innerAttach => {
|
|
268
|
+
return shell => {
|
|
269
|
+
spy(`${interceptorName}:attach`)
|
|
270
|
+
innerAttach && innerAttach(shell)
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
: undefined,
|
|
274
|
+
interceptExtend: flags.interceptExtend
|
|
275
|
+
? innerExtend => {
|
|
276
|
+
return shell => {
|
|
277
|
+
spy(`${interceptorName}:extend`)
|
|
278
|
+
innerExtend && innerExtend(shell)
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
: undefined,
|
|
282
|
+
interceptDetach: flags.interceptDetach
|
|
283
|
+
? innerDetach => {
|
|
284
|
+
return shell => {
|
|
285
|
+
spy(`${interceptorName}:detach`)
|
|
286
|
+
innerDetach && innerDetach(shell)
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
: undefined
|
|
290
|
+
}
|
|
291
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { EntryPoint, HostLogger, EntryPointTags } from '../src/API'
|
|
2
|
+
import { createAppHost } from '../src/appHost'
|
|
3
|
+
import { createShellLogger } from '../src/loggers'
|
|
4
|
+
|
|
5
|
+
describe('ShellLogger', () => {
|
|
6
|
+
function setup(tags?: EntryPointTags) {
|
|
7
|
+
const logSpy = jest.fn()
|
|
8
|
+
const spanSpy = jest.fn().mockImplementation(() => ({}))
|
|
9
|
+
|
|
10
|
+
const entryPoint: EntryPoint = {
|
|
11
|
+
name: 'ep-1',
|
|
12
|
+
tags
|
|
13
|
+
}
|
|
14
|
+
const hostLogger: HostLogger = {
|
|
15
|
+
log: logSpy,
|
|
16
|
+
spanChild: spanSpy,
|
|
17
|
+
spanRoot: spanSpy
|
|
18
|
+
}
|
|
19
|
+
const host = createAppHost([], { logger: hostLogger, monitoring: {} })
|
|
20
|
+
const shellLogger = createShellLogger(host, entryPoint)
|
|
21
|
+
|
|
22
|
+
logSpy.mockClear()
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
entryPoint,
|
|
26
|
+
hostLogger,
|
|
27
|
+
host,
|
|
28
|
+
shellLogger
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function delay(milliseconds: number) {
|
|
33
|
+
return new Promise(resolve => {
|
|
34
|
+
setTimeout(resolve, milliseconds)
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
it('should log simple message', () => {
|
|
39
|
+
const { shellLogger, hostLogger } = setup()
|
|
40
|
+
|
|
41
|
+
shellLogger.debug('M1')
|
|
42
|
+
shellLogger.info('M2')
|
|
43
|
+
shellLogger.warning('M3')
|
|
44
|
+
shellLogger.error('M4')
|
|
45
|
+
|
|
46
|
+
expect(hostLogger.log).toHaveBeenCalledTimes(4)
|
|
47
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(1, 'debug', 'M1', undefined, { $ep: 'ep-1' })
|
|
48
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(2, 'info', 'M2', undefined, { $ep: 'ep-1' })
|
|
49
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(3, 'warning', 'M3', undefined, { $ep: 'ep-1' })
|
|
50
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(4, 'error', 'M4', undefined, { $ep: 'ep-1' })
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('should log simple message with key-value pairs', () => {
|
|
54
|
+
const { shellLogger, hostLogger } = setup()
|
|
55
|
+
|
|
56
|
+
shellLogger.debug('M1', { k1: 'v1' })
|
|
57
|
+
shellLogger.info('M2', { k2: 'v2' })
|
|
58
|
+
shellLogger.warning('M3', { k3: 'v3' })
|
|
59
|
+
shellLogger.error('M4', undefined, { k4: 'v4' })
|
|
60
|
+
|
|
61
|
+
expect(hostLogger.log).toHaveBeenCalledTimes(4)
|
|
62
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(1, 'debug', 'M1', undefined, { $ep: 'ep-1', k1: 'v1' })
|
|
63
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(2, 'info', 'M2', undefined, { $ep: 'ep-1', k2: 'v2' })
|
|
64
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(3, 'warning', 'M3', undefined, { $ep: 'ep-1', k3: 'v3' })
|
|
65
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(4, 'error', 'M4', undefined, { $ep: 'ep-1', k4: 'v4' })
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('should include entry point tags in key-value pairs', () => {
|
|
69
|
+
const { shellLogger, hostLogger } = setup({ t1: 'T1', t2: 'T2' })
|
|
70
|
+
|
|
71
|
+
shellLogger.debug('M1', { k1: 'v1' })
|
|
72
|
+
shellLogger.info('M2', { k2: 'v2' })
|
|
73
|
+
shellLogger.warning('M3', { k3: 'v3' })
|
|
74
|
+
shellLogger.error('M4', undefined, { k4: 'v4' })
|
|
75
|
+
|
|
76
|
+
expect(hostLogger.log).toHaveBeenCalledTimes(4)
|
|
77
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(1, 'debug', 'M1', undefined, { $ep: 'ep-1', k1: 'v1', t1: 'T1', t2: 'T2' })
|
|
78
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(2, 'info', 'M2', undefined, { $ep: 'ep-1', k2: 'v2', t1: 'T1', t2: 'T2' })
|
|
79
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(3, 'warning', 'M3', undefined, { $ep: 'ep-1', k3: 'v3', t1: 'T1', t2: 'T2' })
|
|
80
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(4, 'error', 'M4', undefined, { $ep: 'ep-1', k4: 'v4', t1: 'T1', t2: 'T2' })
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('should begin span', () => {
|
|
84
|
+
const { shellLogger, hostLogger } = setup({ t1: 'T1' })
|
|
85
|
+
|
|
86
|
+
const span = shellLogger.spanChild('M1', { k1: 'v1' })
|
|
87
|
+
|
|
88
|
+
expect(span).toBeDefined()
|
|
89
|
+
expect(hostLogger.spanChild).toHaveBeenCalledTimes(1)
|
|
90
|
+
expect(hostLogger.spanChild).toHaveBeenNthCalledWith(1, 'M1', { $ep: 'ep-1', k1: 'v1', t1: 'T1' })
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it.skip('should monitor synchronous void function success', () => {
|
|
94
|
+
const { shellLogger, hostLogger } = setup({ t1: 'T1' })
|
|
95
|
+
|
|
96
|
+
shellLogger.monitor('M1', { k1: 'v1' }, () => {
|
|
97
|
+
shellLogger.debug('this-is-monitored-code')
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
expect(hostLogger.log).toHaveBeenCalledTimes(3)
|
|
101
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(1, 'span', 'M1', undefined, { $ep: 'ep-1', k1: 'v1', t1: 'T1' }, 'begin')
|
|
102
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(2, 'debug', 'this-is-monitored-code', undefined, { $ep: 'ep-1', t1: 'T1' })
|
|
103
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(
|
|
104
|
+
3,
|
|
105
|
+
'span',
|
|
106
|
+
'M1',
|
|
107
|
+
{
|
|
108
|
+
$ep: 'ep-1',
|
|
109
|
+
k1: 'v1',
|
|
110
|
+
t1: 'T1',
|
|
111
|
+
success: true,
|
|
112
|
+
returnValue: undefined,
|
|
113
|
+
error: undefined
|
|
114
|
+
},
|
|
115
|
+
'end'
|
|
116
|
+
)
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
it.skip('should monitor synchronous non-void function success', () => {
|
|
120
|
+
const { shellLogger, hostLogger } = setup({ t1: 'T1' })
|
|
121
|
+
|
|
122
|
+
const returnValue = shellLogger.monitor('M1', { k1: 'v1' }, () => {
|
|
123
|
+
shellLogger.debug('this-is-monitored-code')
|
|
124
|
+
return 123
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
expect(returnValue).toBe(123)
|
|
128
|
+
expect(hostLogger.log).toHaveBeenCalledTimes(3)
|
|
129
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(1, 'span', 'M1', undefined, { $ep: 'ep-1', k1: 'v1', t1: 'T1' }, 'begin')
|
|
130
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(2, 'debug', 'this-is-monitored-code', undefined, { $ep: 'ep-1', t1: 'T1' })
|
|
131
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(
|
|
132
|
+
3,
|
|
133
|
+
'span',
|
|
134
|
+
'M1',
|
|
135
|
+
{
|
|
136
|
+
$ep: 'ep-1',
|
|
137
|
+
k1: 'v1',
|
|
138
|
+
t1: 'T1',
|
|
139
|
+
success: true,
|
|
140
|
+
returnValue: 123,
|
|
141
|
+
error: undefined
|
|
142
|
+
},
|
|
143
|
+
'end'
|
|
144
|
+
)
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it.skip('should monitor synchronous function that returns null', () => {
|
|
148
|
+
const { shellLogger, hostLogger } = setup({ t1: 'T1' })
|
|
149
|
+
|
|
150
|
+
const returnValue = shellLogger.monitor('M1', { k1: 'v1' }, () => {
|
|
151
|
+
shellLogger.debug('this-is-monitored-code')
|
|
152
|
+
return null
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
expect(returnValue).toBeNull()
|
|
156
|
+
expect(hostLogger.log).toHaveBeenCalledTimes(3)
|
|
157
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(1, 'span', 'M1', { $ep: 'ep-1', k1: 'v1', t1: 'T1' }, 'begin')
|
|
158
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(2, 'debug', 'this-is-monitored-code', { $ep: 'ep-1', t1: 'T1' })
|
|
159
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(
|
|
160
|
+
3,
|
|
161
|
+
'span',
|
|
162
|
+
'M1',
|
|
163
|
+
{
|
|
164
|
+
$ep: 'ep-1',
|
|
165
|
+
k1: 'v1',
|
|
166
|
+
t1: 'T1',
|
|
167
|
+
success: true,
|
|
168
|
+
returnValue: null,
|
|
169
|
+
error: undefined
|
|
170
|
+
},
|
|
171
|
+
'end'
|
|
172
|
+
)
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it.skip('should monitor synchronous function failure', () => {
|
|
176
|
+
const { shellLogger, hostLogger } = setup({ t1: 'T1' })
|
|
177
|
+
|
|
178
|
+
expect(() => {
|
|
179
|
+
shellLogger.monitor('M1', { k1: 'v1' }, () => {
|
|
180
|
+
throw new Error('ERR1')
|
|
181
|
+
})
|
|
182
|
+
}).toThrowError('ERR1')
|
|
183
|
+
|
|
184
|
+
expect(hostLogger.log).toHaveBeenCalledTimes(2)
|
|
185
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(1, 'span', 'M1', { $ep: 'ep-1', k1: 'v1', t1: 'T1' }, 'begin')
|
|
186
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(
|
|
187
|
+
2,
|
|
188
|
+
'span',
|
|
189
|
+
'M1',
|
|
190
|
+
{
|
|
191
|
+
$ep: 'ep-1',
|
|
192
|
+
k1: 'v1',
|
|
193
|
+
t1: 'T1',
|
|
194
|
+
success: false,
|
|
195
|
+
returnValue: undefined,
|
|
196
|
+
error: new Error('ERR1')
|
|
197
|
+
},
|
|
198
|
+
'end'
|
|
199
|
+
)
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
it.skip('should monitor async void function success', async () => {
|
|
203
|
+
const { shellLogger, hostLogger } = setup({ t1: 'T1' })
|
|
204
|
+
|
|
205
|
+
await shellLogger.monitor('M1', { k1: 'v1' }, async () => {
|
|
206
|
+
await delay(10)
|
|
207
|
+
shellLogger.debug('this-is-monitored-code')
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
expect(hostLogger.log).toHaveBeenCalledTimes(3)
|
|
211
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(1, 'span', 'M1', { $ep: 'ep-1', k1: 'v1', t1: 'T1' }, 'begin')
|
|
212
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(2, 'debug', 'this-is-monitored-code', { $ep: 'ep-1', t1: 'T1' })
|
|
213
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(
|
|
214
|
+
3,
|
|
215
|
+
'span',
|
|
216
|
+
'M1',
|
|
217
|
+
{
|
|
218
|
+
$ep: 'ep-1',
|
|
219
|
+
k1: 'v1',
|
|
220
|
+
t1: 'T1',
|
|
221
|
+
success: true,
|
|
222
|
+
returnValue: undefined,
|
|
223
|
+
error: undefined
|
|
224
|
+
},
|
|
225
|
+
'end'
|
|
226
|
+
)
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
it.skip('should monitor async non-void function success', async () => {
|
|
230
|
+
const { shellLogger, hostLogger } = setup({ t1: 'T1' })
|
|
231
|
+
|
|
232
|
+
const returnValue = await shellLogger.monitor('M1', { k1: 'v1' }, async () => {
|
|
233
|
+
shellLogger.debug('this-is-monitored-code')
|
|
234
|
+
await delay(10)
|
|
235
|
+
return 123
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
expect(returnValue).toBe(123)
|
|
239
|
+
expect(hostLogger.log).toHaveBeenCalledTimes(3)
|
|
240
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(1, 'span', 'M1', { $ep: 'ep-1', k1: 'v1', t1: 'T1' }, 'begin')
|
|
241
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(2, 'debug', 'this-is-monitored-code', { $ep: 'ep-1', t1: 'T1' })
|
|
242
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(
|
|
243
|
+
3,
|
|
244
|
+
'span',
|
|
245
|
+
'M1',
|
|
246
|
+
{
|
|
247
|
+
$ep: 'ep-1',
|
|
248
|
+
k1: 'v1',
|
|
249
|
+
t1: 'T1',
|
|
250
|
+
success: true,
|
|
251
|
+
returnValue: 123,
|
|
252
|
+
error: undefined
|
|
253
|
+
},
|
|
254
|
+
'end'
|
|
255
|
+
)
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
it.skip('should monitor async function failure', async () => {
|
|
259
|
+
const { shellLogger, hostLogger } = setup({ t1: 'T1' })
|
|
260
|
+
|
|
261
|
+
try {
|
|
262
|
+
await shellLogger.monitor('M1', { k1: 'v1' }, async () => {
|
|
263
|
+
await delay(10)
|
|
264
|
+
throw new Error('ERR1')
|
|
265
|
+
})
|
|
266
|
+
fail('expected to throw, but did not')
|
|
267
|
+
} catch (err) {
|
|
268
|
+
expect(err.message).toBe('ERR1')
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
expect(hostLogger.log).toHaveBeenCalledTimes(2)
|
|
272
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(1, 'span', 'M1', { $ep: 'ep-1', k1: 'v1', t1: 'T1' }, 'begin')
|
|
273
|
+
expect(hostLogger.log).toHaveBeenNthCalledWith(
|
|
274
|
+
2,
|
|
275
|
+
'span',
|
|
276
|
+
'M1',
|
|
277
|
+
{
|
|
278
|
+
$ep: 'ep-1',
|
|
279
|
+
k1: 'v1',
|
|
280
|
+
t1: 'T1',
|
|
281
|
+
success: false,
|
|
282
|
+
returnValue: undefined,
|
|
283
|
+
error: new Error('ERR1')
|
|
284
|
+
},
|
|
285
|
+
'end'
|
|
286
|
+
)
|
|
287
|
+
})
|
|
288
|
+
})
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { createAppHost } from '../src'
|
|
2
|
+
|
|
3
|
+
const unreadAPI = { name: 'unreadyAPI' }
|
|
4
|
+
|
|
5
|
+
const getUnreadyAPIs = async () => {
|
|
6
|
+
await new Promise(resolve => setTimeout(resolve, 0))
|
|
7
|
+
return globalThis.repluggableAppDebug.utils.getRootUnreadyAPI()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
describe('RepluggableAppDebug', () => {
|
|
11
|
+
describe('getRootUnreadyAPI', () => {
|
|
12
|
+
it('should not report any issues in case there are no entry points', async () => {
|
|
13
|
+
createAppHost([])
|
|
14
|
+
|
|
15
|
+
const unreadyAPIs = await getUnreadyAPIs()
|
|
16
|
+
|
|
17
|
+
expect(unreadyAPIs).toEqual([])
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('should not report any issues in case all entry points are loaded', async () => {
|
|
21
|
+
createAppHost([
|
|
22
|
+
{
|
|
23
|
+
name: 'entryPoint',
|
|
24
|
+
declareAPIs: () => []
|
|
25
|
+
}
|
|
26
|
+
])
|
|
27
|
+
|
|
28
|
+
const unreadyAPIs = await getUnreadyAPIs()
|
|
29
|
+
|
|
30
|
+
expect(unreadyAPIs).toEqual([])
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('should return an API if its not ready', async () => {
|
|
34
|
+
createAppHost([
|
|
35
|
+
{
|
|
36
|
+
name: 'entryPoint',
|
|
37
|
+
getDependencyAPIs: () => [unreadAPI]
|
|
38
|
+
}
|
|
39
|
+
])
|
|
40
|
+
|
|
41
|
+
const unreadyAPIs = await getUnreadyAPIs()
|
|
42
|
+
|
|
43
|
+
expect(unreadyAPIs).toEqual([{ name: 'unreadyAPI' }])
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('should return the root unready API when there are multiple entry points that depend on the same API', async () => {
|
|
47
|
+
createAppHost([
|
|
48
|
+
{
|
|
49
|
+
name: 'entryPoint A',
|
|
50
|
+
getDependencyAPIs: () => [unreadAPI]
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'entryPoint B',
|
|
54
|
+
getDependencyAPIs: () => [unreadAPI]
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'entryPoint C',
|
|
58
|
+
getDependencyAPIs: () => [unreadAPI]
|
|
59
|
+
}
|
|
60
|
+
])
|
|
61
|
+
|
|
62
|
+
const unreadyAPIs = await getUnreadyAPIs()
|
|
63
|
+
|
|
64
|
+
expect(unreadyAPIs).toEqual([{ name: 'unreadyAPI' }])
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('should return the root unready API when there is a graph of dependencies', async () => {
|
|
68
|
+
createAppHost([
|
|
69
|
+
{
|
|
70
|
+
name: 'entryPoint A',
|
|
71
|
+
declareAPIs: () => [{ name: 'API A' }],
|
|
72
|
+
getDependencyAPIs: () => [{ name: 'API B' }]
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'entryPoint B',
|
|
76
|
+
declareAPIs: () => [{ name: 'API B' }],
|
|
77
|
+
getDependencyAPIs: () => [{ name: 'API C' }]
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: 'entryPoint C',
|
|
81
|
+
declareAPIs: () => [{ name: 'API C' }],
|
|
82
|
+
getDependencyAPIs: () => [unreadAPI]
|
|
83
|
+
}
|
|
84
|
+
])
|
|
85
|
+
|
|
86
|
+
const unreadyAPIs = await getUnreadyAPIs()
|
|
87
|
+
|
|
88
|
+
expect(unreadyAPIs).toEqual([{ name: 'unreadyAPI' }, { name: 'API C' }, { name: 'API B' }])
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('should return the root unready API when there is a graph of dependencies (declation order is reversed)', async () => {
|
|
92
|
+
createAppHost(
|
|
93
|
+
[
|
|
94
|
+
{
|
|
95
|
+
name: 'entryPoint A',
|
|
96
|
+
declareAPIs: () => [{ name: 'API A' }],
|
|
97
|
+
getDependencyAPIs: () => [{ name: 'API B' }]
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: 'entryPoint B',
|
|
101
|
+
declareAPIs: () => [{ name: 'API B' }],
|
|
102
|
+
getDependencyAPIs: () => [{ name: 'API C' }]
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: 'entryPoint C',
|
|
106
|
+
declareAPIs: () => [{ name: 'API C' }],
|
|
107
|
+
getDependencyAPIs: () => [unreadAPI]
|
|
108
|
+
}
|
|
109
|
+
].reverse()
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
const unreadyAPIs = await getUnreadyAPIs()
|
|
113
|
+
// because we take the first unready entry point, and in this case its the root,
|
|
114
|
+
// we don't get the rest of the unready APIs
|
|
115
|
+
expect(unreadyAPIs).toEqual([{ name: 'unreadyAPI' }])
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
})
|