repluggable-core 0.0.0-pr302.475 → 0.0.0-pr303.476
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/es/{src/API.d.ts → API.d.ts} +8 -46
- package/dist/es/API.d.ts.map +1 -0
- package/dist/es/API.js +2 -0
- package/dist/es/API.js.map +1 -0
- package/dist/es/__internal.d.ts.map +1 -0
- package/dist/es/__internal.js +5 -0
- package/dist/es/__internal.js.map +1 -0
- package/dist/es/index.d.ts +3 -0
- package/dist/es/index.d.ts.map +1 -0
- package/dist/es/index.js +2 -0
- package/dist/es/index.js.map +1 -0
- package/dist/src/API.d.ts +8 -46
- package/dist/src/API.d.ts.map +1 -1
- package/dist/src/API.js +0 -4
- package/dist/src/API.js.map +1 -1
- package/dist/src/__internal.d.ts.map +1 -1
- package/dist/src/__internal.js +1 -1
- package/dist/src/__internal.js.map +1 -1
- package/dist/src/index.d.ts +2 -10
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +15 -22
- package/dist/src/index.js.map +1 -1
- package/package.json +3 -21
- package/src/API.ts +9 -47
- package/src/__internal.ts +1 -1
- package/src/index.ts +2 -42
- package/tsconfig.json +2 -9
- package/__tests__/spec-setup.js +0 -3
- package/dist/es/src/API.d.ts.map +0 -1
- package/dist/es/src/API.js +0 -3
- package/dist/es/src/API.js.map +0 -1
- package/dist/es/src/IterableWeakMap.d.ts +0 -20
- package/dist/es/src/IterableWeakMap.d.ts.map +0 -1
- package/dist/es/src/IterableWeakMap.js +0 -93
- package/dist/es/src/IterableWeakMap.js.map +0 -1
- package/dist/es/src/__internal.d.ts.map +0 -1
- package/dist/es/src/__internal.js +0 -5
- package/dist/es/src/__internal.js.map +0 -1
- package/dist/es/src/appHost.d.ts +0 -7
- package/dist/es/src/appHost.d.ts.map +0 -1
- package/dist/es/src/appHost.js +0 -898
- package/dist/es/src/appHost.js.map +0 -1
- package/dist/es/src/appHostServices.d.ts +0 -12
- package/dist/es/src/appHostServices.d.ts.map +0 -1
- package/dist/es/src/appHostServices.js +0 -25
- package/dist/es/src/appHostServices.js.map +0 -1
- package/dist/es/src/appHostUtils.d.ts +0 -4
- package/dist/es/src/appHostUtils.d.ts.map +0 -1
- package/dist/es/src/appHostUtils.js +0 -8
- package/dist/es/src/appHostUtils.js.map +0 -1
- package/dist/es/src/extensionSlot.d.ts +0 -8
- package/dist/es/src/extensionSlot.d.ts.map +0 -1
- package/dist/es/src/extensionSlot.js +0 -59
- package/dist/es/src/extensionSlot.js.map +0 -1
- package/dist/es/src/hot.d.ts +0 -14
- package/dist/es/src/hot.d.ts.map +0 -1
- package/dist/es/src/hot.js +0 -52
- package/dist/es/src/hot.js.map +0 -1
- package/dist/es/src/index.d.ts +0 -11
- package/dist/es/src/index.d.ts.map +0 -1
- package/dist/es/src/index.js +0 -10
- package/dist/es/src/index.js.map +0 -1
- package/dist/es/src/installedShellsState.d.ts +0 -19
- package/dist/es/src/installedShellsState.d.ts.map +0 -1
- package/dist/es/src/installedShellsState.js +0 -30
- package/dist/es/src/installedShellsState.js.map +0 -1
- package/dist/es/src/interceptAnyObject.d.ts +0 -7
- package/dist/es/src/interceptAnyObject.d.ts.map +0 -1
- package/dist/es/src/interceptAnyObject.js +0 -21
- package/dist/es/src/interceptAnyObject.js.map +0 -1
- package/dist/es/src/invokeSlotCallbacks.d.ts +0 -3
- package/dist/es/src/invokeSlotCallbacks.d.ts.map +0 -1
- package/dist/es/src/invokeSlotCallbacks.js +0 -20
- package/dist/es/src/invokeSlotCallbacks.js.map +0 -1
- package/dist/es/src/loggers.d.ts +0 -4
- package/dist/es/src/loggers.d.ts.map +0 -1
- package/dist/es/src/loggers.js +0 -100
- package/dist/es/src/loggers.js.map +0 -1
- package/dist/es/src/monitorAPI.d.ts +0 -3
- package/dist/es/src/monitorAPI.d.ts.map +0 -1
- package/dist/es/src/monitorAPI.js +0 -53
- package/dist/es/src/monitorAPI.js.map +0 -1
- package/dist/es/src/repluggableAppDebug/index.d.ts +0 -2
- package/dist/es/src/repluggableAppDebug/index.d.ts.map +0 -1
- package/dist/es/src/repluggableAppDebug/index.js +0 -2
- package/dist/es/src/repluggableAppDebug/index.js.map +0 -1
- package/dist/es/src/repluggableAppDebug/performanceDebugInfo.d.ts +0 -15
- package/dist/es/src/repluggableAppDebug/performanceDebugInfo.d.ts.map +0 -1
- package/dist/es/src/repluggableAppDebug/performanceDebugInfo.js +0 -94
- package/dist/es/src/repluggableAppDebug/performanceDebugInfo.js.map +0 -1
- package/dist/es/src/repluggableAppDebug/repluggableAppDebug.d.ts +0 -24
- package/dist/es/src/repluggableAppDebug/repluggableAppDebug.d.ts.map +0 -1
- package/dist/es/src/repluggableAppDebug/repluggableAppDebug.js +0 -132
- package/dist/es/src/repluggableAppDebug/repluggableAppDebug.js.map +0 -1
- package/dist/es/src/tarjanGraph.d.ts +0 -27
- package/dist/es/src/tarjanGraph.d.ts.map +0 -1
- package/dist/es/src/tarjanGraph.js +0 -94
- package/dist/es/src/tarjanGraph.js.map +0 -1
- package/dist/es/src/throttledStore.d.ts +0 -32
- package/dist/es/src/throttledStore.d.ts.map +0 -1
- package/dist/es/src/throttledStore.js +0 -240
- package/dist/es/src/throttledStore.js.map +0 -1
- package/dist/es/test/IterableWeakMap.spec.d.ts +0 -2
- package/dist/es/test/IterableWeakMap.spec.d.ts.map +0 -1
- package/dist/es/test/IterableWeakMap.spec.js +0 -218
- package/dist/es/test/IterableWeakMap.spec.js.map +0 -1
- package/dist/es/test/appHost.mock.d.ts +0 -4
- package/dist/es/test/appHost.mock.d.ts.map +0 -1
- package/dist/es/test/appHost.mock.js +0 -54
- package/dist/es/test/appHost.mock.js.map +0 -1
- package/dist/es/test/appHost.spec.d.ts +0 -2
- package/dist/es/test/appHost.spec.d.ts.map +0 -1
- package/dist/es/test/appHost.spec.js +0 -1451
- package/dist/es/test/appHost.spec.js.map +0 -1
- package/dist/es/test/installedShellsState.spec.d.ts +0 -2
- package/dist/es/test/installedShellsState.spec.d.ts.map +0 -1
- package/dist/es/test/installedShellsState.spec.js +0 -28
- package/dist/es/test/installedShellsState.spec.js.map +0 -1
- package/dist/es/test/interceptAnyObject.spec.d.ts +0 -2
- package/dist/es/test/interceptAnyObject.spec.d.ts.map +0 -1
- package/dist/es/test/interceptAnyObject.spec.js +0 -166
- package/dist/es/test/interceptAnyObject.spec.js.map +0 -1
- package/dist/es/test/loggers.spec.d.ts +0 -2
- package/dist/es/test/loggers.spec.d.ts.map +0 -1
- package/dist/es/test/loggers.spec.js +0 -218
- package/dist/es/test/loggers.spec.js.map +0 -1
- package/dist/es/test/repluggableAppDebug.spec.d.ts +0 -2
- package/dist/es/test/repluggableAppDebug.spec.d.ts.map +0 -1
- package/dist/es/test/repluggableAppDebug.spec.js +0 -107
- package/dist/es/test/repluggableAppDebug.spec.js.map +0 -1
- package/dist/es/test/testKit.spec.d.ts +0 -2
- package/dist/es/test/testKit.spec.d.ts.map +0 -1
- package/dist/es/test/testKit.spec.js +0 -129
- package/dist/es/test/testKit.spec.js.map +0 -1
- package/dist/es/testKit/emptyLoggerOptions.d.ts +0 -3
- package/dist/es/testKit/emptyLoggerOptions.d.ts.map +0 -1
- package/dist/es/testKit/emptyLoggerOptions.js +0 -15
- package/dist/es/testKit/emptyLoggerOptions.js.map +0 -1
- package/dist/es/testKit/index.d.ts +0 -33
- package/dist/es/testKit/index.d.ts.map +0 -1
- package/dist/es/testKit/index.js +0 -132
- package/dist/es/testKit/index.js.map +0 -1
- package/dist/es/testKit/mockPackage.d.ts +0 -23
- package/dist/es/testKit/mockPackage.d.ts.map +0 -1
- package/dist/es/testKit/mockPackage.js +0 -95
- package/dist/es/testKit/mockPackage.js.map +0 -1
- package/dist/es/testKit/withConsoleErrors.d.ts +0 -2
- package/dist/es/testKit/withConsoleErrors.d.ts.map +0 -1
- package/dist/es/testKit/withConsoleErrors.js +0 -12
- package/dist/es/testKit/withConsoleErrors.js.map +0 -1
- package/dist/es/testKit/withThrowOnError.d.ts +0 -3
- package/dist/es/testKit/withThrowOnError.d.ts.map +0 -1
- package/dist/es/testKit/withThrowOnError.js +0 -27
- package/dist/es/testKit/withThrowOnError.js.map +0 -1
- package/dist/src/IterableWeakMap.d.ts +0 -20
- package/dist/src/IterableWeakMap.d.ts.map +0 -1
- package/dist/src/IterableWeakMap.js +0 -97
- package/dist/src/IterableWeakMap.js.map +0 -1
- package/dist/src/appHost.d.ts +0 -7
- package/dist/src/appHost.d.ts.map +0 -1
- package/dist/src/appHost.js +0 -906
- package/dist/src/appHost.js.map +0 -1
- package/dist/src/appHostServices.d.ts +0 -12
- package/dist/src/appHostServices.d.ts.map +0 -1
- package/dist/src/appHostServices.js +0 -29
- package/dist/src/appHostServices.js.map +0 -1
- package/dist/src/appHostUtils.d.ts +0 -4
- package/dist/src/appHostUtils.d.ts.map +0 -1
- package/dist/src/appHostUtils.js +0 -16
- package/dist/src/appHostUtils.js.map +0 -1
- package/dist/src/extensionSlot.d.ts +0 -8
- package/dist/src/extensionSlot.d.ts.map +0 -1
- package/dist/src/extensionSlot.js +0 -67
- package/dist/src/extensionSlot.js.map +0 -1
- package/dist/src/hot.d.ts +0 -14
- package/dist/src/hot.d.ts.map +0 -1
- package/dist/src/hot.js +0 -56
- package/dist/src/hot.js.map +0 -1
- package/dist/src/installedShellsState.d.ts +0 -19
- package/dist/src/installedShellsState.d.ts.map +0 -1
- package/dist/src/installedShellsState.js +0 -38
- package/dist/src/installedShellsState.js.map +0 -1
- package/dist/src/interceptAnyObject.d.ts +0 -7
- package/dist/src/interceptAnyObject.d.ts.map +0 -1
- package/dist/src/interceptAnyObject.js +0 -28
- package/dist/src/interceptAnyObject.js.map +0 -1
- package/dist/src/invokeSlotCallbacks.d.ts +0 -3
- package/dist/src/invokeSlotCallbacks.d.ts.map +0 -1
- package/dist/src/invokeSlotCallbacks.js +0 -24
- package/dist/src/invokeSlotCallbacks.js.map +0 -1
- package/dist/src/loggers.d.ts +0 -4
- package/dist/src/loggers.d.ts.map +0 -1
- package/dist/src/loggers.js +0 -104
- package/dist/src/loggers.js.map +0 -1
- package/dist/src/monitorAPI.d.ts +0 -3
- package/dist/src/monitorAPI.d.ts.map +0 -1
- package/dist/src/monitorAPI.js +0 -57
- package/dist/src/monitorAPI.js.map +0 -1
- package/dist/src/repluggableAppDebug/index.d.ts +0 -2
- package/dist/src/repluggableAppDebug/index.d.ts.map +0 -1
- package/dist/src/repluggableAppDebug/index.js +0 -6
- package/dist/src/repluggableAppDebug/index.js.map +0 -1
- package/dist/src/repluggableAppDebug/performanceDebugInfo.d.ts +0 -15
- package/dist/src/repluggableAppDebug/performanceDebugInfo.d.ts.map +0 -1
- package/dist/src/repluggableAppDebug/performanceDebugInfo.js +0 -101
- package/dist/src/repluggableAppDebug/performanceDebugInfo.js.map +0 -1
- package/dist/src/repluggableAppDebug/repluggableAppDebug.d.ts +0 -24
- package/dist/src/repluggableAppDebug/repluggableAppDebug.d.ts.map +0 -1
- package/dist/src/repluggableAppDebug/repluggableAppDebug.js +0 -139
- package/dist/src/repluggableAppDebug/repluggableAppDebug.js.map +0 -1
- package/dist/src/tarjanGraph.d.ts +0 -27
- package/dist/src/tarjanGraph.d.ts.map +0 -1
- package/dist/src/tarjanGraph.js +0 -100
- package/dist/src/tarjanGraph.js.map +0 -1
- package/dist/src/throttledStore.d.ts +0 -32
- package/dist/src/throttledStore.d.ts.map +0 -1
- package/dist/src/throttledStore.js +0 -249
- package/dist/src/throttledStore.js.map +0 -1
- package/dist/test/IterableWeakMap.spec.d.ts +0 -2
- package/dist/test/IterableWeakMap.spec.d.ts.map +0 -1
- package/dist/test/IterableWeakMap.spec.js +0 -220
- package/dist/test/IterableWeakMap.spec.js.map +0 -1
- package/dist/test/appHost.mock.d.ts +0 -4
- package/dist/test/appHost.mock.d.ts.map +0 -1
- package/dist/test/appHost.mock.js +0 -59
- package/dist/test/appHost.mock.js.map +0 -1
- package/dist/test/appHost.spec.d.ts +0 -2
- package/dist/test/appHost.spec.d.ts.map +0 -1
- package/dist/test/appHost.spec.js +0 -1456
- package/dist/test/appHost.spec.js.map +0 -1
- package/dist/test/installedShellsState.spec.d.ts +0 -2
- package/dist/test/installedShellsState.spec.d.ts.map +0 -1
- package/dist/test/installedShellsState.spec.js +0 -30
- package/dist/test/installedShellsState.spec.js.map +0 -1
- package/dist/test/interceptAnyObject.spec.d.ts +0 -2
- package/dist/test/interceptAnyObject.spec.d.ts.map +0 -1
- package/dist/test/interceptAnyObject.spec.js +0 -171
- package/dist/test/interceptAnyObject.spec.js.map +0 -1
- package/dist/test/loggers.spec.d.ts +0 -2
- package/dist/test/loggers.spec.d.ts.map +0 -1
- package/dist/test/loggers.spec.js +0 -220
- package/dist/test/loggers.spec.js.map +0 -1
- package/dist/test/repluggableAppDebug.spec.d.ts +0 -2
- package/dist/test/repluggableAppDebug.spec.d.ts.map +0 -1
- package/dist/test/repluggableAppDebug.spec.js +0 -109
- package/dist/test/repluggableAppDebug.spec.js.map +0 -1
- package/dist/test/testKit.spec.d.ts +0 -2
- package/dist/test/testKit.spec.d.ts.map +0 -1
- package/dist/test/testKit.spec.js +0 -134
- package/dist/test/testKit.spec.js.map +0 -1
- package/dist/testKit/emptyLoggerOptions.d.ts +0 -3
- package/dist/testKit/emptyLoggerOptions.d.ts.map +0 -1
- package/dist/testKit/emptyLoggerOptions.js +0 -18
- package/dist/testKit/emptyLoggerOptions.js.map +0 -1
- package/dist/testKit/index.d.ts +0 -33
- package/dist/testKit/index.d.ts.map +0 -1
- package/dist/testKit/index.js +0 -160
- package/dist/testKit/index.js.map +0 -1
- package/dist/testKit/mockPackage.d.ts +0 -23
- package/dist/testKit/mockPackage.d.ts.map +0 -1
- package/dist/testKit/mockPackage.js +0 -101
- package/dist/testKit/mockPackage.js.map +0 -1
- package/dist/testKit/withConsoleErrors.d.ts +0 -2
- package/dist/testKit/withConsoleErrors.d.ts.map +0 -1
- package/dist/testKit/withConsoleErrors.js +0 -16
- package/dist/testKit/withConsoleErrors.js.map +0 -1
- package/dist/testKit/withThrowOnError.d.ts +0 -3
- package/dist/testKit/withThrowOnError.d.ts.map +0 -1
- package/dist/testKit/withThrowOnError.js +0 -31
- package/dist/testKit/withThrowOnError.js.map +0 -1
- package/jest.config.js +0 -16
- package/src/IterableWeakMap.ts +0 -124
- package/src/appHost.ts +0 -1222
- package/src/appHostServices.ts +0 -42
- package/src/appHostUtils.ts +0 -11
- package/src/extensionSlot.ts +0 -96
- package/src/hot.ts +0 -53
- package/src/installedShellsState.ts +0 -54
- package/src/interceptAnyObject.ts +0 -39
- package/src/invokeSlotCallbacks.ts +0 -20
- package/src/loggers.ts +0 -112
- package/src/monitorAPI.ts +0 -71
- package/src/repluggableAppDebug/debug.d.ts +0 -37
- package/src/repluggableAppDebug/index.ts +0 -1
- package/src/repluggableAppDebug/performanceDebugInfo.ts +0 -96
- package/src/repluggableAppDebug/repluggableAppDebug.ts +0 -192
- package/src/tarjanGraph.ts +0 -96
- package/src/throttledStore.ts +0 -355
- package/test/IterableWeakMap.spec.ts +0 -280
- package/test/appHost.mock.ts +0 -58
- package/test/appHost.spec.ts +0 -1765
- package/test/installedShellsState.spec.ts +0 -39
- package/test/interceptAnyObject.spec.ts +0 -217
- package/test/loggers.spec.ts +0 -288
- package/test/repluggableAppDebug.spec.ts +0 -118
- package/test/testKit.spec.tsx +0 -153
- package/testKit/emptyLoggerOptions.ts +0 -16
- package/testKit/index.ts +0 -177
- package/testKit/mockPackage.ts +0 -110
- package/testKit/withConsoleErrors.ts +0 -12
- package/testKit/withThrowOnError.ts +0 -34
- /package/dist/es/{src/__internal.d.ts → __internal.d.ts} +0 -0
package/test/testKit.spec.tsx
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash'
|
|
2
|
-
import { EntryPoint, EntryPointOrPackage, SlotKey } from '../src/API'
|
|
3
|
-
import { AnyExtensionSlot } from '../src/extensionSlot'
|
|
4
|
-
import {
|
|
5
|
-
getPackagesDependencies,
|
|
6
|
-
createAppHost,
|
|
7
|
-
addMockShell,
|
|
8
|
-
MockAPI,
|
|
9
|
-
mockPackage,
|
|
10
|
-
createAppHostWithPacts,
|
|
11
|
-
PactAPI,
|
|
12
|
-
asyncLoadMockPackage,
|
|
13
|
-
dependsOnMockPackageEntryPoint,
|
|
14
|
-
MockPublicAPI,
|
|
15
|
-
createAppHostAndWaitForLoading
|
|
16
|
-
} from '../testKit'
|
|
17
|
-
|
|
18
|
-
interface APIKeys {
|
|
19
|
-
[name: string]: AnyExtensionSlot
|
|
20
|
-
}
|
|
21
|
-
const APIs: APIKeys = {
|
|
22
|
-
A: { name: 'A' },
|
|
23
|
-
B: { name: 'B' },
|
|
24
|
-
C: { name: 'C' },
|
|
25
|
-
D: { name: 'D' },
|
|
26
|
-
E: { name: 'E' },
|
|
27
|
-
F: { name: 'F' }
|
|
28
|
-
}
|
|
29
|
-
interface PackagesMap {
|
|
30
|
-
[name: string]: EntryPointOrPackage
|
|
31
|
-
}
|
|
32
|
-
const allPackages: PackagesMap = {
|
|
33
|
-
A: {
|
|
34
|
-
name: 'A'
|
|
35
|
-
},
|
|
36
|
-
B: {
|
|
37
|
-
name: 'B',
|
|
38
|
-
declareAPIs() {
|
|
39
|
-
return [APIs.B]
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
C: {
|
|
43
|
-
name: 'C',
|
|
44
|
-
getDependencyAPIs() {
|
|
45
|
-
return [APIs.B]
|
|
46
|
-
},
|
|
47
|
-
declareAPIs() {
|
|
48
|
-
return [APIs.C]
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
D: [
|
|
52
|
-
{
|
|
53
|
-
name: 'D',
|
|
54
|
-
getDependencyAPIs() {
|
|
55
|
-
return [APIs.C]
|
|
56
|
-
},
|
|
57
|
-
declareAPIs() {
|
|
58
|
-
return [APIs.E]
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
name: 'E'
|
|
63
|
-
}
|
|
64
|
-
],
|
|
65
|
-
F: {
|
|
66
|
-
name: 'F',
|
|
67
|
-
getDependencyAPIs() {
|
|
68
|
-
return [APIs.E]
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
describe('App Host TestKit', () => {
|
|
74
|
-
it('should get packages dependencies', () => {
|
|
75
|
-
const toResult = (packages: EntryPointOrPackage[]) => _(packages).flatten().sortBy('name').value()
|
|
76
|
-
const getDependencies = (packages: EntryPointOrPackage[]) => toResult(getPackagesDependencies(_.values(allPackages), packages))
|
|
77
|
-
const { A, B, C, D, F } = allPackages
|
|
78
|
-
|
|
79
|
-
expect(getDependencies([])).toEqual(toResult([]))
|
|
80
|
-
expect(getDependencies([A])).toEqual(toResult([A]))
|
|
81
|
-
expect(getDependencies([C])).toEqual(toResult([B, C]))
|
|
82
|
-
expect(getDependencies([D])).toEqual(toResult([B, C, D]))
|
|
83
|
-
expect(getDependencies([D, B])).toEqual(toResult([B, C, D]))
|
|
84
|
-
expect(getDependencies([D, B, A])).toEqual(toResult([B, C, D, A]))
|
|
85
|
-
|
|
86
|
-
// TODO: Should 'E' be included ?
|
|
87
|
-
expect(getDependencies([F])).toEqual(toResult([B, C, (D as EntryPoint[])[0], F]))
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
it('should add mock shell', async () => {
|
|
91
|
-
const host = createAppHost([mockPackage])
|
|
92
|
-
const shell = addMockShell(host, {
|
|
93
|
-
name: 'MOCK',
|
|
94
|
-
getDependencyAPIs() {
|
|
95
|
-
return [MockAPI]
|
|
96
|
-
}
|
|
97
|
-
})
|
|
98
|
-
//await new Promise(resolve => host.onShellsChanged(resolve))
|
|
99
|
-
expect(host.hasShell('MOCK')).toBe(true)
|
|
100
|
-
expect(() => shell.getAPI(MockAPI)).not.toThrow()
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
it('should throw if could not add mock shell', async () => {
|
|
104
|
-
const host = createAppHost([mockPackage])
|
|
105
|
-
const APIKey = 'API that would never exist'
|
|
106
|
-
const add = async () => {
|
|
107
|
-
addMockShell(host, {
|
|
108
|
-
name: 'MOCK',
|
|
109
|
-
getDependencyAPIs() {
|
|
110
|
-
return [MockAPI, { name: APIKey }]
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
//await new Promise(resolve => host.onShellsChanged(resolve))
|
|
114
|
-
}
|
|
115
|
-
await expect(add()).rejects.toThrow(new RegExp(APIKey))
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
it('should create app host with provided pacts', () => {
|
|
119
|
-
interface MockAPI1 {
|
|
120
|
-
f(): number
|
|
121
|
-
}
|
|
122
|
-
const key: SlotKey<MockAPI1> = { name: 'MOCK-API', layer: 'MOCK_LAYER' }
|
|
123
|
-
const pactAPI: MockAPI1 & PactAPI<MockAPI1> = {
|
|
124
|
-
getAPIKey: () => key,
|
|
125
|
-
f: () => 1
|
|
126
|
-
}
|
|
127
|
-
const host = createAppHostWithPacts([], [pactAPI])
|
|
128
|
-
expect(host.getAPI(key).f()).toBe(1)
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
describe('createAppHostAndWaitForLoading', () => {
|
|
132
|
-
beforeAll(() => {
|
|
133
|
-
jest.useFakeTimers()
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
afterAll(() => {
|
|
137
|
-
jest.useRealTimers()
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
it('should wait for loading all packages', async () => {
|
|
141
|
-
const hostPromise = createAppHostAndWaitForLoading([dependsOnMockPackageEntryPoint, asyncLoadMockPackage], [])
|
|
142
|
-
jest.runAllTimers()
|
|
143
|
-
const host = await hostPromise
|
|
144
|
-
expect(host.getAPI(MockPublicAPI)).toBeDefined()
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
it('should throw if failed to load all packages', async () => {
|
|
148
|
-
const hostPromise = createAppHostAndWaitForLoading([dependsOnMockPackageEntryPoint], [])
|
|
149
|
-
jest.runAllTimers()
|
|
150
|
-
await expect(hostPromise).rejects.toThrow(new RegExp(MockPublicAPI.name))
|
|
151
|
-
})
|
|
152
|
-
})
|
|
153
|
-
})
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { AppHostOptions } from '../src/API'
|
|
2
|
-
|
|
3
|
-
export const emptyLoggerOptions: AppHostOptions = {
|
|
4
|
-
logger: {
|
|
5
|
-
log: jest.fn(),
|
|
6
|
-
spanChild: jest.fn().mockImplementation(() => ({
|
|
7
|
-
end() {}
|
|
8
|
-
})),
|
|
9
|
-
spanRoot: jest.fn().mockImplementation(() => ({
|
|
10
|
-
end() {}
|
|
11
|
-
}))
|
|
12
|
-
},
|
|
13
|
-
monitoring: {
|
|
14
|
-
disableMonitoring: true
|
|
15
|
-
}
|
|
16
|
-
}
|
package/testKit/index.ts
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash'
|
|
2
|
-
import { EntryPoint, ObservableState } from '../src/API'
|
|
3
|
-
import { AnySlotKey, AppHost, createAppHost as _createAppHost, EntryPointOrPackage, Shell, SlotKey } from '../src/index'
|
|
4
|
-
import { createShellLogger } from '../src/loggers'
|
|
5
|
-
import { emptyLoggerOptions } from './emptyLoggerOptions'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* When using the testKit you are not directly depends on the global of the repluggableAppDebug,
|
|
9
|
-
* So in order of it to populate global 'only' when import testKit we re-export it here.
|
|
10
|
-
* And not in repluggable-core so it will not pollute the global when using repluggable-core
|
|
11
|
-
* */
|
|
12
|
-
export type * from '../src/repluggableAppDebug/debug'
|
|
13
|
-
|
|
14
|
-
export {createShellLogger}
|
|
15
|
-
export { emptyLoggerOptions }
|
|
16
|
-
export { AppHost } from '../src/index'
|
|
17
|
-
|
|
18
|
-
export { withConsoleErrors } from './withConsoleErrors'
|
|
19
|
-
export { withThrowOnError } from './withThrowOnError'
|
|
20
|
-
export * from './mockPackage'
|
|
21
|
-
|
|
22
|
-
export const createAppHost: typeof _createAppHost = (packages, options = emptyLoggerOptions) => {
|
|
23
|
-
return _createAppHost(packages, options)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface PactAPIBase {
|
|
27
|
-
getAPIKey(): AnySlotKey
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface PactAPI<T> extends PactAPIBase {
|
|
31
|
-
getAPIKey(): SlotKey<T>
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function forEachDeclaredAPI(allPackages: EntryPointOrPackage[], iteration: (dependency: AnySlotKey, entryPoint: EntryPoint) => void) {
|
|
35
|
-
_.forEach(_.flatten(allPackages), (entryPoint: EntryPoint) => {
|
|
36
|
-
_.forEach(entryPoint.declareAPIs ? entryPoint.declareAPIs() : [], dependency => {
|
|
37
|
-
iteration(dependency, entryPoint)
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export const getPackagesDependencies = (
|
|
43
|
-
allPackages: EntryPointOrPackage[],
|
|
44
|
-
requiredPackages: EntryPointOrPackage[]
|
|
45
|
-
): EntryPointOrPackage[] => {
|
|
46
|
-
const apiToEntryPoint = new Map<string, EntryPoint | undefined>()
|
|
47
|
-
const loadedEntryPoints = new Set<string>()
|
|
48
|
-
|
|
49
|
-
forEachDeclaredAPI(allPackages, (dependency, entryPoint) => {
|
|
50
|
-
apiToEntryPoint.set(dependency.name, entryPoint)
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
const packagesList: EntryPointOrPackage[] = []
|
|
54
|
-
const entryPointsQueue: EntryPoint[] = _.flatten(requiredPackages)
|
|
55
|
-
|
|
56
|
-
while (entryPointsQueue.length) {
|
|
57
|
-
const currEntryPoint = entryPointsQueue.shift()
|
|
58
|
-
if (!currEntryPoint || loadedEntryPoints.has(currEntryPoint.name)) {
|
|
59
|
-
continue
|
|
60
|
-
}
|
|
61
|
-
loadedEntryPoints.add(currEntryPoint.name)
|
|
62
|
-
packagesList.push(currEntryPoint)
|
|
63
|
-
const dependencies = currEntryPoint.getDependencyAPIs ? currEntryPoint.getDependencyAPIs() : []
|
|
64
|
-
const dependencyEntryPoints = dependencies.map((API: AnySlotKey) => apiToEntryPoint.get(API.name))
|
|
65
|
-
entryPointsQueue.push(..._.compact(dependencyEntryPoints))
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return _.uniq(packagesList)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function createAppHostWithPacts(packages: EntryPointOrPackage[], pacts: PactAPIBase[]) {
|
|
72
|
-
const pactsEntryPoint: EntryPoint = {
|
|
73
|
-
name: 'PACTS_ENTRY_POINT',
|
|
74
|
-
declareAPIs() {
|
|
75
|
-
return pacts.map(pact => pact.getAPIKey())
|
|
76
|
-
},
|
|
77
|
-
attach(shell: Shell): void {
|
|
78
|
-
_.each(pacts, pact => {
|
|
79
|
-
shell.contributeAPI(pact.getAPIKey(), () => pact)
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return createAppHost([...packages, pactsEntryPoint], { ...emptyLoggerOptions, disableLayersValidation: true })
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export async function createAppHostAndWaitForLoading(packages: EntryPointOrPackage[], pacts: PactAPIBase[]): Promise<AppHost> {
|
|
88
|
-
const appHost = createAppHostWithPacts(packages, pacts)
|
|
89
|
-
const declaredAPIs = _(packages)
|
|
90
|
-
.flatten()
|
|
91
|
-
.value()
|
|
92
|
-
.flatMap((entryPoint: EntryPoint) => (entryPoint.declareAPIs ? entryPoint.declareAPIs() : []))
|
|
93
|
-
|
|
94
|
-
const timeoutPromise = new Promise((resolve, reject) => {
|
|
95
|
-
setTimeout(() => {
|
|
96
|
-
const readyAPIs = Array.from(globalThis.repluggableAppDebug.readyAPIs)
|
|
97
|
-
const unreadyAPIs = declaredAPIs.filter(api => !readyAPIs.some(readyAPI => readyAPI.name === api.name))
|
|
98
|
-
reject(
|
|
99
|
-
new Error(
|
|
100
|
-
'createAppHostAndWaitForLoading - waiting for loading timed out - the following declaredAPIs were not contributed ' +
|
|
101
|
-
JSON.stringify(unreadyAPIs)
|
|
102
|
-
)
|
|
103
|
-
)
|
|
104
|
-
}, 3000)
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
const loadingPromise = new Promise<void>(async resolve => {
|
|
108
|
-
await appHost.addShells([
|
|
109
|
-
{
|
|
110
|
-
name: 'Depends on all declared APIs',
|
|
111
|
-
getDependencyAPIs() {
|
|
112
|
-
return declaredAPIs
|
|
113
|
-
},
|
|
114
|
-
extend() {
|
|
115
|
-
resolve()
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
])
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
return Promise.race([timeoutPromise, loadingPromise]).then(() => appHost)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
|
|
126
|
-
interface EntryPointOverrides extends Omit<EntryPoint, 'name'> {
|
|
127
|
-
name?: EntryPoint['name']
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// this function assumes that addShells completes synchronously
|
|
131
|
-
export const addMockShell = (host: AppHost, entryPointOverrides: EntryPointOverrides = {}): Shell => {
|
|
132
|
-
let shell = null
|
|
133
|
-
host.addShells([
|
|
134
|
-
{
|
|
135
|
-
name: _.uniqueId('__MOCK_SHELL_'),
|
|
136
|
-
...entryPointOverrides,
|
|
137
|
-
attach(_shell: Shell) {
|
|
138
|
-
shell = _shell
|
|
139
|
-
if (entryPointOverrides.attach) {
|
|
140
|
-
entryPointOverrides.attach(_shell)
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
])
|
|
145
|
-
if (!shell) {
|
|
146
|
-
const dependencies = entryPointOverrides.getDependencyAPIs ? entryPointOverrides.getDependencyAPIs() : []
|
|
147
|
-
const canGetAPI = (key: AnySlotKey) => {
|
|
148
|
-
try {
|
|
149
|
-
host.getAPI(key)
|
|
150
|
-
return true
|
|
151
|
-
} catch (e) {
|
|
152
|
-
return false
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
const missing = dependencies.filter((key: AnySlotKey) => !canGetAPI(key))
|
|
156
|
-
throw new Error(
|
|
157
|
-
`addMockShell: overridden entry point is not ready (missing dependency APIs?) host could not find: ${missing.map(
|
|
158
|
-
(v: AnySlotKey) => `"${v.name}"`
|
|
159
|
-
)}`
|
|
160
|
-
)
|
|
161
|
-
}
|
|
162
|
-
return shell
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
export function mockObservable<T>(value: T): ObservableState<T> {
|
|
168
|
-
return {
|
|
169
|
-
subscribe: () => {
|
|
170
|
-
return () => {}
|
|
171
|
-
},
|
|
172
|
-
current() {
|
|
173
|
-
return value
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
package/testKit/mockPackage.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash'
|
|
2
|
-
|
|
3
|
-
import { AnyAction } from 'redux'
|
|
4
|
-
import { EntryPoint, Shell, SlotKey } from '../src/API'
|
|
5
|
-
|
|
6
|
-
export interface MockAPI {
|
|
7
|
-
stubTrue(): boolean
|
|
8
|
-
getNewObject(): object
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface MockPublicAPI {
|
|
12
|
-
stubTrue(): boolean
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const MockAPI: SlotKey<MockAPI> = { name: 'mock API' }
|
|
16
|
-
export const MockSlot: SlotKey<any> = { name: 'mock slot' }
|
|
17
|
-
export const MockPublicAPI: SlotKey<MockPublicAPI> = {
|
|
18
|
-
name: 'mock API public',
|
|
19
|
-
public: true
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const createMockAPI = (shell: Shell): MockAPI => ({
|
|
23
|
-
stubTrue: _.stubTrue,
|
|
24
|
-
getNewObject: () => ({})
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
export interface MockState {
|
|
28
|
-
mockValue: boolean
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const mockShellInitialState: MockState = {
|
|
32
|
-
mockValue: true
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const TOGGLE_MOCK_VALUE = 'mockEntryPoint/mockAction'
|
|
36
|
-
|
|
37
|
-
const mockReducer = (state: MockState = mockShellInitialState, action: AnyAction): MockState => {
|
|
38
|
-
switch (action.type) {
|
|
39
|
-
case TOGGLE_MOCK_VALUE:
|
|
40
|
-
return { ...state, mockValue: !state.mockValue }
|
|
41
|
-
}
|
|
42
|
-
return state
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export const mockShellStateKey = 'mockEntryPoint'
|
|
46
|
-
|
|
47
|
-
export const mockPackage: EntryPoint = {
|
|
48
|
-
name: 'MOCK_ENTRY_POINT',
|
|
49
|
-
declareAPIs() {
|
|
50
|
-
return [MockAPI]
|
|
51
|
-
},
|
|
52
|
-
attach(shell: Shell) {
|
|
53
|
-
shell.contributeAPI(MockAPI, () => createMockAPI(shell))
|
|
54
|
-
shell.contributeState(() => ({
|
|
55
|
-
[mockShellStateKey]: mockReducer
|
|
56
|
-
}))
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export const asyncLoadMockPackage: EntryPoint = {
|
|
61
|
-
name: 'ASYNC_MOCK_ENTRY_POINT',
|
|
62
|
-
declareAPIs() {
|
|
63
|
-
return [MockAPI]
|
|
64
|
-
},
|
|
65
|
-
async extend(shell: Shell) {
|
|
66
|
-
await new Promise<void>(resolve => {
|
|
67
|
-
setTimeout(() => {
|
|
68
|
-
shell.contributeAPI(MockAPI, () => createMockAPI(shell))
|
|
69
|
-
resolve()
|
|
70
|
-
}, 500)
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export const dependsOnMockPackageEntryPoint: EntryPoint = {
|
|
76
|
-
name: 'DEPENDS ON MOCK API',
|
|
77
|
-
getDependencyAPIs() {
|
|
78
|
-
return [MockAPI]
|
|
79
|
-
},
|
|
80
|
-
declareAPIs() {
|
|
81
|
-
return [MockPublicAPI]
|
|
82
|
-
},
|
|
83
|
-
attach(shell: Shell) {
|
|
84
|
-
shell.contributeAPI(MockPublicAPI, () => ({
|
|
85
|
-
stubTrue: () => true
|
|
86
|
-
}))
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export const mockPackageWithPublicAPI: EntryPoint = {
|
|
91
|
-
name: 'MOCK_ENTRY_POINT_PUBLIC',
|
|
92
|
-
declareAPIs() {
|
|
93
|
-
return [MockPublicAPI]
|
|
94
|
-
},
|
|
95
|
-
attach(shell: Shell) {
|
|
96
|
-
shell.contributeAPI(MockPublicAPI, () => ({
|
|
97
|
-
stubTrue: () => true
|
|
98
|
-
}))
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export const mockPackageWithSlot: EntryPoint = {
|
|
103
|
-
name: 'MOCK_PACKAGE_WITH_SLOT',
|
|
104
|
-
declareAPIs() {
|
|
105
|
-
return []
|
|
106
|
-
},
|
|
107
|
-
attach(shell: Shell) {
|
|
108
|
-
shell.declareSlot(MockSlot)
|
|
109
|
-
}
|
|
110
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const noopConsoleError: Console['error'] = () => {}
|
|
2
|
-
|
|
3
|
-
export function withConsoleErrors<T>(action: () => T, mock?: Console['error']): T {
|
|
4
|
-
const savedConsoleError = console.error
|
|
5
|
-
console.error = mock || noopConsoleError
|
|
6
|
-
|
|
7
|
-
try {
|
|
8
|
-
return action()
|
|
9
|
-
} finally {
|
|
10
|
-
console.error = savedConsoleError
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { AppHostOptions, HostLogger, LogSeverity, ShellLoggerSpan } from '../src/API'
|
|
2
|
-
|
|
3
|
-
export function withThrowOnError(options: AppHostOptions = { monitoring: {} }): AppHostOptions {
|
|
4
|
-
const throwError = (error: Error, keyValuePairs?: Object) => {
|
|
5
|
-
throw new Error(`${error} ${keyValuePairs ? JSON.stringify(keyValuePairs) : ''}`)
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const span: ShellLoggerSpan = {
|
|
9
|
-
end(success, error, keyValuePairs) {
|
|
10
|
-
if (error) {
|
|
11
|
-
throwError(error, keyValuePairs)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const logger: HostLogger = {
|
|
17
|
-
spanRoot(messageId: string, error?: Error, keyValuePairs?: Object): ShellLoggerSpan {
|
|
18
|
-
return span
|
|
19
|
-
},
|
|
20
|
-
spanChild(messageId: string, error?: Error, keyValuePairs?: Object): ShellLoggerSpan {
|
|
21
|
-
return span
|
|
22
|
-
},
|
|
23
|
-
log(severity: LogSeverity, id: string, error?: Error, keyValuePairs?: Object): void {
|
|
24
|
-
if (severity === 'error' || severity === 'critical') {
|
|
25
|
-
throwError(error || new Error('Unknown error'), keyValuePairs)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
...options,
|
|
32
|
-
logger
|
|
33
|
-
}
|
|
34
|
-
}
|
|
File without changes
|