-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(module-loader): cover all exported function with tests
- Loading branch information
Showing
22 changed files
with
1,232 additions
and
64 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
build | ||
coverage |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
src | ||
build/tsconfig.tsbuildinfo | ||
__tests__ | ||
.turbo | ||
coverage |
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
74 changes: 74 additions & 0 deletions
74
packages/arui-scripts-modules/src/module-loader/__tests__/create-module-fetcher.tests.ts
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,74 @@ | ||
import { createModuleFetcher } from '../create-module-fetcher'; | ||
import { fetchAppManifest } from '../utils/fetch-app-manifest'; | ||
|
||
jest.mock('../utils/fetch-app-manifest'); | ||
|
||
describe('createModuleFetcher', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should fetch the app manifest and return module resources', async () => { | ||
const mockManifest = { | ||
__metadata__: { | ||
version: '1.0', | ||
name: 'Test App', | ||
}, | ||
module1: { | ||
js: 'module1.js', | ||
css: 'module1.css', | ||
mode: 'compat', | ||
}, | ||
}; | ||
|
||
(fetchAppManifest as jest.Mock).mockResolvedValue(mockManifest); | ||
|
||
const baseUrl = 'http://example.com'; | ||
const assetsUrl = '/assets/webpack-assets.json'; | ||
const moduleFetcher = createModuleFetcher({ baseUrl, assetsUrl }); | ||
|
||
const moduleId = 'module1'; | ||
const hostAppId = 'app1'; | ||
|
||
const expectedModuleResources = { | ||
scripts: ['module1.js'], | ||
styles: ['module1.css'], | ||
moduleVersion: '1.0', | ||
appName: 'Test App', | ||
mountMode: 'compat', | ||
moduleState: { | ||
baseUrl: 'http://example.com', | ||
hostAppId: 'app1', | ||
}, | ||
}; | ||
|
||
const moduleResources = await moduleFetcher({ moduleId, hostAppId, params: undefined }); | ||
|
||
expect(fetchAppManifest).toHaveBeenCalledWith('http://example.com/assets/webpack-assets.json'); | ||
expect(moduleResources).toEqual(expectedModuleResources); | ||
}); | ||
|
||
it('should throw an error if module is not found in the manifest', async () => { | ||
const mockManifest = { | ||
__metadata__: { | ||
version: '1.0', | ||
name: 'Test App', | ||
}, | ||
}; | ||
|
||
(fetchAppManifest as jest.Mock).mockResolvedValue(mockManifest); | ||
|
||
const baseUrl = 'http://example.com'; | ||
const assetsUrl = '/assets/webpack-assets.json'; | ||
const moduleFetcher = createModuleFetcher({ baseUrl, assetsUrl }); | ||
|
||
const moduleId = 'module1'; | ||
const hostAppId = 'app1'; | ||
|
||
await expect(moduleFetcher({ moduleId, hostAppId, params: undefined })).rejects.toThrow( | ||
'Module module1 not found in manifest from http://example.com/assets/webpack-assets.json' | ||
); | ||
|
||
expect(fetchAppManifest).toHaveBeenCalledWith('http://example.com/assets/webpack-assets.json'); | ||
}); | ||
}); |
Oops, something went wrong.