repluggable-core 0.0.0-pr351.71 → 0.0.0-pr351.72
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/repluggableAppDebug/index.d.ts +1 -1
- package/dist/es/src/repluggableAppDebug/index.d.ts.map +1 -1
- package/dist/es/src/repluggableAppDebug/index.js.map +1 -1
- package/dist/es/src/repluggableAppDebug/repluggableAppDebug.d.ts +0 -20
- package/dist/es/src/repluggableAppDebug/repluggableAppDebug.d.ts.map +1 -1
- package/dist/es/src/repluggableAppDebug/repluggableAppDebug.js +42 -41
- package/dist/es/src/repluggableAppDebug/repluggableAppDebug.js.map +1 -1
- package/dist/es/test/repluggableAppDebug.spec.js +0 -122
- package/dist/es/test/repluggableAppDebug.spec.js.map +1 -1
- package/dist/es/test/testKit.spec.js +5 -16
- package/dist/es/test/testKit.spec.js.map +1 -1
- package/dist/es/testKit/index.d.ts +1 -10
- package/dist/es/testKit/index.d.ts.map +1 -1
- package/dist/es/testKit/index.js +16 -54
- package/dist/es/testKit/index.js.map +1 -1
- package/dist/src/repluggableAppDebug/index.d.ts +1 -1
- package/dist/src/repluggableAppDebug/index.d.ts.map +1 -1
- package/dist/src/repluggableAppDebug/index.js.map +1 -1
- package/dist/src/repluggableAppDebug/repluggableAppDebug.d.ts +0 -20
- package/dist/src/repluggableAppDebug/repluggableAppDebug.d.ts.map +1 -1
- package/dist/src/repluggableAppDebug/repluggableAppDebug.js +42 -41
- package/dist/src/repluggableAppDebug/repluggableAppDebug.js.map +1 -1
- package/dist/test/repluggableAppDebug.spec.js +0 -122
- package/dist/test/repluggableAppDebug.spec.js.map +1 -1
- package/dist/test/testKit.spec.js +4 -15
- package/dist/test/testKit.spec.js.map +1 -1
- package/dist/testKit/index.d.ts +1 -10
- package/dist/testKit/index.d.ts.map +1 -1
- package/dist/testKit/index.js +17 -56
- package/dist/testKit/index.js.map +1 -1
- package/package.json +1 -1
- package/src/repluggableAppDebug/debug.d.ts +1 -16
- package/src/repluggableAppDebug/index.ts +1 -1
- package/src/repluggableAppDebug/repluggableAppDebug.ts +43 -65
- package/test/repluggableAppDebug.spec.ts +0 -150
- package/test/testKit.spec.tsx +6 -19
- package/testKit/index.ts +27 -66
package/testKit/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _ from 'lodash'
|
|
2
2
|
import { EntryPoint, ObservableState } from '../src/API'
|
|
3
3
|
import { AnySlotKey, AppHost, createAppHost as _createAppHost, EntryPointOrPackage, Shell, SlotKey } from '../src/index'
|
|
4
|
-
import { UnreadyEntryPointsReport } from '../src/repluggableAppDebug'
|
|
5
4
|
import { createShellLogger } from '../src/loggers'
|
|
6
5
|
import { emptyLoggerOptions } from './emptyLoggerOptions'
|
|
7
6
|
|
|
@@ -82,60 +81,10 @@ export function createAppHostWithPacts(packages: EntryPointOrPackage[], pacts: P
|
|
|
82
81
|
})
|
|
83
82
|
}
|
|
84
83
|
|
|
85
|
-
export interface WaitForLoadingOptions {
|
|
86
|
-
/** milliseconds to wait for host loading before rejecting with an unready entry points report (default: 3000) */
|
|
87
|
-
timeout?: number
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export class AppHostLoadingTimeoutError extends Error {
|
|
91
|
-
constructor(message: string, public readonly report: UnreadyEntryPointsReport) {
|
|
92
|
-
super(message)
|
|
93
|
-
this.name = 'AppHostLoadingTimeoutError'
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const WAIT_FOR_LOADING_PROBE_SHELL = 'Depends on all declared APIs'
|
|
98
|
-
|
|
99
|
-
const formatUnreadyReport = (timeout: number, report: UnreadyEntryPointsReport): string => {
|
|
100
|
-
const { utils } = globalThis.repluggableAppDebug
|
|
101
|
-
const isProbeShell = (name: string) => name === WAIT_FOR_LOADING_PROBE_SHELL
|
|
102
|
-
const header = `createAppHostAndWaitForLoading - host not ready within ${timeout}ms.`
|
|
103
|
-
const unreadyEntryPoints = report.unreadyEntryPoints.filter(entryPoint => !isProbeShell(entryPoint.name))
|
|
104
|
-
const rootUnreadyEntryPoints = report.rootUnreadyEntryPoints.filter(entryPoint => !isProbeShell(entryPoint.name))
|
|
105
|
-
|
|
106
|
-
if (report.probableDependencyCycle) {
|
|
107
|
-
const names = unreadyEntryPoints.map(entryPoint => `"${entryPoint.name}"`).join(', ')
|
|
108
|
-
return `${header}
|
|
109
|
-
No root unready API found while ${unreadyEntryPoints.length} entry points are unready - probable dependency cycle between: ${names}`
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const roots = report.rootUnreadyAPIs.map((info, index) => {
|
|
113
|
-
const declaredBy =
|
|
114
|
-
info.declaredBy === 'nobody'
|
|
115
|
-
? 'declared by NO entry point (missing package or pact?)'
|
|
116
|
-
: `declared by "${info.declaredBy.entryPointName}" (installed, but its contribution never completed - hung async contributeAPI?)`
|
|
117
|
-
const requiredBy = info.requiredBy.filter(name => !isProbeShell(name))
|
|
118
|
-
const lines = [`${index + 1}. "${info.key.name}" - ${declaredBy}`]
|
|
119
|
-
if (requiredBy.length) {
|
|
120
|
-
lines.push(` required by: ${requiredBy.join(', ')}`)
|
|
121
|
-
const tree = utils.visualizeDependencyTree(utils.traceAPIDependency(requiredBy[0], info.key.name))
|
|
122
|
-
lines.push(...tree.split('\n').map(line => ` ${line}`))
|
|
123
|
-
}
|
|
124
|
-
return lines.join('\n')
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
return `${header}
|
|
128
|
-
|
|
129
|
-
Root unready APIs (${report.rootUnreadyAPIs.length}):
|
|
130
|
-
${roots.join('\n')}
|
|
131
|
-
|
|
132
|
-
Unready entry points: ${rootUnreadyEntryPoints.length} blocked directly on root APIs, ${unreadyEntryPoints.length} total.`
|
|
133
|
-
}
|
|
134
|
-
|
|
135
84
|
export async function createAppHostAndWaitForLoading(
|
|
136
85
|
packages: EntryPointOrPackage[],
|
|
137
86
|
pacts: PactAPIBase[],
|
|
138
|
-
|
|
87
|
+
timeout: number = 3000
|
|
139
88
|
): Promise<AppHost> {
|
|
140
89
|
const appHost = createAppHostWithPacts(packages, pacts)
|
|
141
90
|
const declaredAPIs = _(packages)
|
|
@@ -143,18 +92,37 @@ export async function createAppHostAndWaitForLoading(
|
|
|
143
92
|
.value()
|
|
144
93
|
.flatMap((entryPoint: EntryPoint) => (entryPoint.declareAPIs ? entryPoint.declareAPIs() : []))
|
|
145
94
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
95
|
+
const timeoutPromise = new Promise((resolve, reject) => {
|
|
96
|
+
setTimeout(() => {
|
|
97
|
+
const readyAPIs = Array.from(globalThis.repluggableAppDebug.readyAPIs)
|
|
98
|
+
const unreadyAPIs = declaredAPIs.filter(api => !readyAPIs.some(readyAPI => readyAPI.name === api.name))
|
|
99
|
+
const unreadyEntryPoints = globalThis.repluggableAppDebug.utils.unReadyEntryPoints()
|
|
100
|
+
const readyNames = new Set(readyAPIs.map(api => api.name))
|
|
101
|
+
const declaredByUnready = new Set(unreadyEntryPoints.flatMap(ep => (ep.declareAPIs?.() || []).map(key => key.name)))
|
|
102
|
+
const rootUnreadyAPIs = _.uniqBy(
|
|
103
|
+
unreadyEntryPoints
|
|
104
|
+
.flatMap(ep => ep.getDependencyAPIs?.() || [])
|
|
105
|
+
.filter(key => !readyNames.has(key.name) && !declaredByUnready.has(key.name)),
|
|
106
|
+
'name'
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
reject(
|
|
110
|
+
new Error(
|
|
111
|
+
`createAppHostAndWaitForLoading - waiting for loading timed out after ${timeout}ms.
|
|
112
|
+
these root unready APIs are most likely the reason - unready entry points require them but nothing declares them (missing entry point or pact?): ${JSON.stringify(
|
|
113
|
+
rootUnreadyAPIs
|
|
114
|
+
)}
|
|
115
|
+
|
|
116
|
+
in addition here's the full list of declared APIs that have not been contributed: ${JSON.stringify(unreadyAPIs)}`
|
|
117
|
+
)
|
|
118
|
+
)
|
|
151
119
|
}, timeout)
|
|
152
120
|
})
|
|
153
121
|
|
|
154
122
|
const loadingPromise = new Promise<void>(async resolve => {
|
|
155
123
|
await appHost.addShells([
|
|
156
124
|
{
|
|
157
|
-
name:
|
|
125
|
+
name: 'Depends on all declared APIs',
|
|
158
126
|
getDependencyAPIs() {
|
|
159
127
|
return declaredAPIs
|
|
160
128
|
},
|
|
@@ -165,14 +133,7 @@ export async function createAppHostAndWaitForLoading(
|
|
|
165
133
|
])
|
|
166
134
|
})
|
|
167
135
|
|
|
168
|
-
|
|
169
|
-
await Promise.race([timeoutPromise, loadingPromise])
|
|
170
|
-
return appHost
|
|
171
|
-
} finally {
|
|
172
|
-
if (timer) {
|
|
173
|
-
clearTimeout(timer)
|
|
174
|
-
}
|
|
175
|
-
}
|
|
136
|
+
return Promise.race([timeoutPromise, loadingPromise]).then(() => appHost)
|
|
176
137
|
}
|
|
177
138
|
|
|
178
139
|
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
|