-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add function to repluggable app debug (#262)
add function to repluggable app debug
- Loading branch information
Showing
3 changed files
with
172 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { createAppHost } from '../src' | ||
|
||
const unreadAPI = { name: 'unreadyAPI' } | ||
|
||
const getUnreadyAPIs = async () => { | ||
await new Promise(resolve => setTimeout(resolve, 0)) | ||
return window.repluggableAppDebug.utils.getRootUnreadyAPI() | ||
} | ||
|
||
describe('RepluggableAppDebug', () => { | ||
describe('getRootUnreadyAPI', () => { | ||
it('should not report any issues in case there are no entry points', async () => { | ||
createAppHost([]) | ||
|
||
const unreadyAPIs = await getUnreadyAPIs() | ||
|
||
expect(unreadyAPIs).toEqual([]) | ||
}) | ||
|
||
it('should not report any issues in case all entry points are loaded', async () => { | ||
createAppHost([ | ||
{ | ||
name: 'entryPoint', | ||
declareAPIs: () => [] | ||
} | ||
]) | ||
|
||
const unreadyAPIs = await getUnreadyAPIs() | ||
|
||
expect(unreadyAPIs).toEqual([]) | ||
}) | ||
|
||
it('should return an API if its not ready', async () => { | ||
createAppHost([ | ||
{ | ||
name: 'entryPoint', | ||
getDependencyAPIs: () => [unreadAPI] | ||
} | ||
]) | ||
|
||
const unreadyAPIs = await getUnreadyAPIs() | ||
|
||
expect(unreadyAPIs).toEqual([{ name: 'unreadyAPI' }]) | ||
}) | ||
|
||
it('should return the root unready API when there are multiple entry points that depend on the same API', async () => { | ||
createAppHost([ | ||
{ | ||
name: 'entryPoint A', | ||
getDependencyAPIs: () => [unreadAPI] | ||
}, | ||
{ | ||
name: 'entryPoint B', | ||
getDependencyAPIs: () => [unreadAPI] | ||
}, | ||
{ | ||
name: 'entryPoint C', | ||
getDependencyAPIs: () => [unreadAPI] | ||
} | ||
]) | ||
|
||
const unreadyAPIs = await getUnreadyAPIs() | ||
|
||
expect(unreadyAPIs).toEqual([{ name: 'unreadyAPI' }]) | ||
}) | ||
|
||
it('should return the root unready API when there is a graph of dependencies', async () => { | ||
createAppHost([ | ||
{ | ||
name: 'entryPoint A', | ||
declareAPIs: () => [{ name: 'API A' }], | ||
getDependencyAPIs: () => [{ name: 'API B' }] | ||
}, | ||
{ | ||
name: 'entryPoint B', | ||
declareAPIs: () => [{ name: 'API B' }], | ||
getDependencyAPIs: () => [{ name: 'API C' }] | ||
}, | ||
{ | ||
name: 'entryPoint C', | ||
declareAPIs: () => [{ name: 'API C' }], | ||
getDependencyAPIs: () => [unreadAPI] | ||
} | ||
]) | ||
|
||
const unreadyAPIs = await getUnreadyAPIs() | ||
|
||
expect(unreadyAPIs).toEqual([{ name: 'unreadyAPI' }, { name: 'API C' }, { name: 'API B' }]) | ||
}) | ||
|
||
it('should return the root unready API when there is a graph of dependencies (declation order is reversed)', async () => { | ||
createAppHost( | ||
[ | ||
{ | ||
name: 'entryPoint A', | ||
declareAPIs: () => [{ name: 'API A' }], | ||
getDependencyAPIs: () => [{ name: 'API B' }] | ||
}, | ||
{ | ||
name: 'entryPoint B', | ||
declareAPIs: () => [{ name: 'API B' }], | ||
getDependencyAPIs: () => [{ name: 'API C' }] | ||
}, | ||
{ | ||
name: 'entryPoint C', | ||
declareAPIs: () => [{ name: 'API C' }], | ||
getDependencyAPIs: () => [unreadAPI] | ||
} | ||
].reverse() | ||
) | ||
|
||
const unreadyAPIs = await getUnreadyAPIs() | ||
// because we take the first unready entry point, and in this case its the root, | ||
// we don't get the rest of the unready APIs | ||
expect(unreadyAPIs).toEqual([{ name: 'unreadyAPI' }]) | ||
}) | ||
}) | ||
}) |