repluggable-core 0.0.0-pr351.77 → 0.0.0-pr355.81

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.
Files changed (40) hide show
  1. package/dist/es/src/interceptAnyObject.d.ts.map +1 -1
  2. package/dist/es/src/interceptAnyObject.js +20 -2
  3. package/dist/es/src/interceptAnyObject.js.map +1 -1
  4. package/dist/es/src/repluggableAppDebug/repluggableAppDebug.d.ts.map +1 -1
  5. package/dist/es/src/repluggableAppDebug/repluggableAppDebug.js +48 -18
  6. package/dist/es/src/repluggableAppDebug/repluggableAppDebug.js.map +1 -1
  7. package/dist/es/test/interceptAnyObject.spec.js +45 -0
  8. package/dist/es/test/interceptAnyObject.spec.js.map +1 -1
  9. package/dist/es/test/repluggableAppDebug.spec.js +7 -26
  10. package/dist/es/test/repluggableAppDebug.spec.js.map +1 -1
  11. package/dist/es/test/testKit.spec.js +0 -31
  12. package/dist/es/test/testKit.spec.js.map +1 -1
  13. package/dist/es/testKit/index.d.ts +1 -1
  14. package/dist/es/testKit/index.d.ts.map +1 -1
  15. package/dist/es/testKit/index.js +6 -6
  16. package/dist/es/testKit/index.js.map +1 -1
  17. package/dist/src/interceptAnyObject.d.ts.map +1 -1
  18. package/dist/src/interceptAnyObject.js +20 -2
  19. package/dist/src/interceptAnyObject.js.map +1 -1
  20. package/dist/src/repluggableAppDebug/repluggableAppDebug.d.ts.map +1 -1
  21. package/dist/src/repluggableAppDebug/repluggableAppDebug.js +48 -18
  22. package/dist/src/repluggableAppDebug/repluggableAppDebug.js.map +1 -1
  23. package/dist/test/interceptAnyObject.spec.js +45 -0
  24. package/dist/test/interceptAnyObject.spec.js.map +1 -1
  25. package/dist/test/repluggableAppDebug.spec.js +7 -26
  26. package/dist/test/repluggableAppDebug.spec.js.map +1 -1
  27. package/dist/test/testKit.spec.js +0 -31
  28. package/dist/test/testKit.spec.js.map +1 -1
  29. package/dist/testKit/index.d.ts +1 -1
  30. package/dist/testKit/index.d.ts.map +1 -1
  31. package/dist/testKit/index.js +6 -6
  32. package/dist/testKit/index.js.map +1 -1
  33. package/package.json +2 -2
  34. package/src/interceptAnyObject.ts +21 -3
  35. package/src/repluggableAppDebug/debug.d.ts +0 -4
  36. package/src/repluggableAppDebug/repluggableAppDebug.ts +52 -21
  37. package/test/interceptAnyObject.spec.ts +53 -0
  38. package/test/repluggableAppDebug.spec.ts +7 -29
  39. package/test/testKit.spec.tsx +0 -42
  40. package/testKit/index.ts +5 -11
@@ -214,4 +214,57 @@ describe('interceptAnyObject', () => {
214
214
  const intercepted = interceptAnyObject(real, createFuncInterceptor(spy), createPropInterceptor(spy))
215
215
  expect(intercepted.get('key')).toEqual('value')
216
216
  })
217
+
218
+ it('should keep getters live instead of reading them once', () => {
219
+ const spy: LogSpy = jest.fn()
220
+ let current = 'initial'
221
+ const real = {
222
+ get liveProp() {
223
+ spy('liveProp')
224
+ return current
225
+ }
226
+ }
227
+ const intercepted = interceptAnyObject(real, createFuncInterceptor(spy), createPropInterceptor(spy))
228
+
229
+ expect(takeLog(spy)).toEqual([])
230
+ current = 'updated'
231
+ expect(intercepted.liveProp).toBe('updated')
232
+ expect(takeLog(spy)).toEqual(['liveProp'])
233
+ })
234
+
235
+ it('should delegate setters to the inner object', () => {
236
+ const spy: LogSpy = jest.fn()
237
+ let stored = 'initial'
238
+ const real = {
239
+ get value() {
240
+ return stored
241
+ },
242
+ set value(newValue: string) {
243
+ stored = newValue
244
+ }
245
+ }
246
+ const intercepted = interceptAnyObject(real, createFuncInterceptor(spy), createPropInterceptor(spy))
247
+
248
+ intercepted.value = 'updated'
249
+
250
+ expect(stored).toBe('updated')
251
+ expect(intercepted.value).toBe('updated')
252
+ })
253
+
254
+ it('should keep getters of nested objects live', () => {
255
+ const spy: LogSpy = jest.fn()
256
+ let current = 'initial'
257
+ const real = {
258
+ nested: {
259
+ get liveProp() {
260
+ return current
261
+ }
262
+ }
263
+ }
264
+ const intercepted = interceptAnyObject(real, createFuncInterceptor(spy), createPropInterceptor(spy), 1)
265
+
266
+ current = 'updated'
267
+
268
+ expect(intercepted.nested.liveProp).toBe('updated')
269
+ })
217
270
  })
@@ -4,7 +4,7 @@ const unreadAPI = { name: 'unreadyAPI' }
4
4
 
5
5
  const getUnreadyAPIs = async () => {
6
6
  await new Promise(resolve => setTimeout(resolve, 0))
7
- return globalThis.repluggableAppDebug.utils.getRootUnreadyAPIs()
7
+ return globalThis.repluggableAppDebug.utils.getRootUnreadyAPI()
8
8
  }
9
9
 
10
10
  describe('RepluggableAppDebug', () => {
@@ -14,7 +14,7 @@ describe('RepluggableAppDebug', () => {
14
14
 
15
15
  const unreadyAPIs = await getUnreadyAPIs()
16
16
 
17
- expect(unreadyAPIs).toEqual([])
17
+ expect(unreadyAPIs).toBeUndefined()
18
18
  })
19
19
 
20
20
  it('should not report any issues in case all entry points are loaded', async () => {
@@ -27,7 +27,7 @@ describe('RepluggableAppDebug', () => {
27
27
 
28
28
  const unreadyAPIs = await getUnreadyAPIs()
29
29
 
30
- expect(unreadyAPIs).toEqual([])
30
+ expect(unreadyAPIs).toBeUndefined()
31
31
  })
32
32
 
33
33
  it('should return an API if its not ready', async () => {
@@ -40,7 +40,7 @@ describe('RepluggableAppDebug', () => {
40
40
 
41
41
  const unreadyAPIs = await getUnreadyAPIs()
42
42
 
43
- expect(unreadyAPIs).toEqual([{ name: 'unreadyAPI' }])
43
+ expect(unreadyAPIs).toEqual({ name: 'unreadyAPI' })
44
44
  })
45
45
 
46
46
  it('should return the root unready API when there are multiple entry points that depend on the same API', async () => {
@@ -61,7 +61,7 @@ describe('RepluggableAppDebug', () => {
61
61
 
62
62
  const unreadyAPIs = await getUnreadyAPIs()
63
63
 
64
- expect(unreadyAPIs).toEqual([{ name: 'unreadyAPI' }])
64
+ expect(unreadyAPIs).toEqual({ name: 'unreadyAPI' })
65
65
  })
66
66
 
67
67
  it('should return the root unready API when there is a graph of dependencies', async () => {
@@ -85,29 +85,7 @@ describe('RepluggableAppDebug', () => {
85
85
 
86
86
  const unreadyAPIs = await getUnreadyAPIs()
87
87
 
88
- expect(unreadyAPIs).toEqual([{ name: 'unreadyAPI' }])
89
- })
90
-
91
- it('should return all root unready APIs, excluding transitively blocked ones', async () => {
92
- createAppHost([
93
- {
94
- name: 'entryPoint A',
95
- getDependencyAPIs: () => [{ name: 'API B' }]
96
- },
97
- {
98
- name: 'entryPoint B',
99
- declareAPIs: () => [{ name: 'API B' }],
100
- getDependencyAPIs: () => [{ name: 'missing B' }]
101
- },
102
- {
103
- name: 'entryPoint C',
104
- getDependencyAPIs: () => [{ name: 'missing C' }]
105
- }
106
- ])
107
-
108
- const unreadyAPIs = await getUnreadyAPIs()
109
-
110
- expect(unreadyAPIs).toEqual([{ name: 'missing B' }, { name: 'missing C' }])
88
+ expect(unreadyAPIs).toEqual({ name: 'unreadyAPI' })
111
89
  })
112
90
 
113
91
  it('should return all traversal paths from an entry point to a transitive API', () => {
@@ -264,7 +242,7 @@ describe('RepluggableAppDebug', () => {
264
242
  const unreadyAPIs = await getUnreadyAPIs()
265
243
  // because we take the first unready entry point, and in this case its the root,
266
244
  // we don't get the rest of the unready APIs
267
- expect(unreadyAPIs).toEqual([{ name: 'unreadyAPI' }])
245
+ expect(unreadyAPIs).toEqual({ name: 'unreadyAPI' })
268
246
  })
269
247
  })
270
248
  })
@@ -149,47 +149,5 @@ describe('App Host TestKit', () => {
149
149
  jest.runAllTimers()
150
150
  await expect(hostPromise).rejects.toThrow(new RegExp(MockPublicAPI.name))
151
151
  })
152
-
153
- it('should report all root unready APIs of independent unready entry points', async () => {
154
- const hostPromise = createAppHostAndWaitForLoading(
155
- [
156
- {
157
- name: 'entryPoint A',
158
- declareAPIs: () => [{ name: 'API A' }],
159
- getDependencyAPIs: () => [{ name: 'missing A' }]
160
- },
161
- {
162
- name: 'entryPoint B',
163
- declareAPIs: () => [{ name: 'API B' }],
164
- getDependencyAPIs: () => [{ name: 'missing B' }]
165
- }
166
- ],
167
- []
168
- )
169
- jest.runAllTimers()
170
- const error: Error = await hostPromise.then(
171
- () => {
172
- throw new Error('expected hostPromise to reject')
173
- },
174
- e => e
175
- )
176
-
177
- expect(error.message).toContain('"missing A"')
178
- expect(error.message).toContain('"missing B"')
179
- })
180
-
181
- it('should respect a custom loading timeout', async () => {
182
- let settled = false
183
- const hostPromise = createAppHostAndWaitForLoading([dependsOnMockPackageEntryPoint], [], 10000)
184
- hostPromise.catch(() => (settled = true))
185
-
186
- jest.advanceTimersByTime(9999)
187
- await Promise.resolve()
188
- await Promise.resolve()
189
- expect(settled).toBe(false)
190
-
191
- jest.advanceTimersByTime(1)
192
- await expect(hostPromise).rejects.toThrow('timed out after 10000ms')
193
- })
194
152
  })
195
153
  })
package/testKit/index.ts CHANGED
@@ -81,11 +81,7 @@ export function createAppHostWithPacts(packages: EntryPointOrPackage[], pacts: P
81
81
  })
82
82
  }
83
83
 
84
- export async function createAppHostAndWaitForLoading(
85
- packages: EntryPointOrPackage[],
86
- pacts: PactAPIBase[],
87
- timeout: number = 3000
88
- ): Promise<AppHost> {
84
+ export async function createAppHostAndWaitForLoading(packages: EntryPointOrPackage[], pacts: PactAPIBase[]): Promise<AppHost> {
89
85
  const appHost = createAppHostWithPacts(packages, pacts)
90
86
  const declaredAPIs = _(packages)
91
87
  .flatten()
@@ -96,19 +92,17 @@ export async function createAppHostAndWaitForLoading(
96
92
  setTimeout(() => {
97
93
  const readyAPIs = Array.from(globalThis.repluggableAppDebug.readyAPIs)
98
94
  const unreadyAPIs = declaredAPIs.filter(api => !readyAPIs.some(readyAPI => readyAPI.name === api.name))
99
- const rootUnreadyAPIs = globalThis.repluggableAppDebug.utils.getRootUnreadyAPIs()
95
+ const rootUnreadyAPI = globalThis.repluggableAppDebug.utils.getRootUnreadyAPI()
100
96
 
101
97
  reject(
102
98
  new Error(
103
- `createAppHostAndWaitForLoading - waiting for loading timed out after ${timeout}ms.
104
- 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(
105
- rootUnreadyAPIs
106
- )}
99
+ `createAppHostAndWaitForLoading - waiting for loading timed out.
100
+ there's a high chance this missing API is the main reason for it: ${JSON.stringify(rootUnreadyAPI)}
107
101
 
108
102
  in addition here's the full list of declared APIs that have not been contributed: ${JSON.stringify(unreadyAPIs)}`
109
103
  )
110
104
  )
111
- }, timeout)
105
+ }, 3000)
112
106
  })
113
107
 
114
108
  const loadingPromise = new Promise<void>(async resolve => {