Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(angular): withModuleFederation helper
- Loading branch information
Showing
8 changed files
with
439 additions
and
13 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
67 changes: 67 additions & 0 deletions
67
packages/angular/src/utils/mfe/__snapshots__/with-module-federation.spec.ts.snap
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,67 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`withModuleFederation should create a host config correctly 1`] = ` | ||
Array [ | ||
ModuleFederationPlugin { | ||
"_options": Object { | ||
"exposes": undefined, | ||
"filename": "remoteEntry.mjs", | ||
"library": Object { | ||
"type": "module", | ||
}, | ||
"name": "host", | ||
"remotes": Object { | ||
"remote1": "http:/localhost:4201/remoteEntry.mjs", | ||
}, | ||
"shared": Object { | ||
"@angular/core": Object { | ||
"requiredVersion": "~13.2.0", | ||
"singleton": true, | ||
"strictVersion": true, | ||
}, | ||
"shared": Object { | ||
"eager": undefined, | ||
"requiredVersion": false, | ||
}, | ||
}, | ||
}, | ||
}, | ||
NormalModuleReplacementPlugin { | ||
"newResource": [Function], | ||
"resourceRegExp": /\\./, | ||
}, | ||
] | ||
`; | ||
|
||
exports[`withModuleFederation should create a remote config correctly 1`] = ` | ||
Array [ | ||
ModuleFederationPlugin { | ||
"_options": Object { | ||
"exposes": Object { | ||
"./Module": "apps/remote1/src/module.ts", | ||
}, | ||
"filename": "remoteEntry.mjs", | ||
"library": Object { | ||
"type": "module", | ||
}, | ||
"name": "remote1", | ||
"remotes": Object {}, | ||
"shared": Object { | ||
"@angular/core": Object { | ||
"requiredVersion": "~13.2.0", | ||
"singleton": true, | ||
"strictVersion": true, | ||
}, | ||
"shared": Object { | ||
"eager": undefined, | ||
"requiredVersion": false, | ||
}, | ||
}, | ||
}, | ||
}, | ||
NormalModuleReplacementPlugin { | ||
"newResource": [Function], | ||
"resourceRegExp": /\\./, | ||
}, | ||
] | ||
`; |
File renamed without changes.
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
107 changes: 107 additions & 0 deletions
107
packages/angular/src/utils/mfe/with-module-federation.spec.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,107 @@ | ||
jest.mock('fs'); | ||
jest.mock('@nrwl/workspace/src/core/project-graph'); | ||
jest.mock('@nrwl/workspace'); | ||
import * as graph from '@nrwl/workspace/src/core/project-graph'; | ||
import * as workspace from '@nrwl/workspace'; | ||
import * as fs from 'fs'; | ||
|
||
import { withModuleFederation } from './with-module-federation'; | ||
|
||
describe('withModuleFederation', () => { | ||
afterEach(() => jest.clearAllMocks()); | ||
it('should create a host config correctly', async () => { | ||
// ARRANGE | ||
(graph.createProjectGraphAsync as jest.Mock).mockReturnValue( | ||
Promise.resolve({ | ||
dependencies: { | ||
host: [ | ||
{ target: 'npm:@angular/core' }, | ||
{ target: 'npm:zone.js' }, | ||
{ target: 'shared' }, | ||
], | ||
}, | ||
}) | ||
); | ||
|
||
(workspace.readWorkspaceJson as jest.Mock).mockReturnValue({ | ||
projects: { | ||
remote1: { | ||
targets: { | ||
serve: { | ||
options: { | ||
publicHost: 'http://localhost:4201', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
(fs.existsSync as jest.Mock).mockReturnValue(true); | ||
(fs.readFileSync as jest.Mock).mockReturnValue( | ||
JSON.stringify({ | ||
dependencies: { | ||
'@angular/core': '~13.2.0', | ||
}, | ||
}) | ||
); | ||
|
||
(workspace.readTsConfig as jest.Mock).mockReturnValue({ | ||
options: { | ||
paths: { | ||
shared: ['/libs/shared/src/index.ts'], | ||
}, | ||
}, | ||
}); | ||
|
||
// ACT | ||
const config = await withModuleFederation({ | ||
name: 'host', | ||
remotes: ['remote1'], | ||
}); | ||
|
||
// ASSERT | ||
expect(config.plugins).toMatchSnapshot(); | ||
}); | ||
|
||
it('should create a remote config correctly', async () => { | ||
// ARRANGE | ||
(graph.createProjectGraphAsync as jest.Mock).mockReturnValue( | ||
Promise.resolve({ | ||
dependencies: { | ||
remote1: [ | ||
{ target: 'npm:@angular/core' }, | ||
{ target: 'npm:zone.js' }, | ||
{ target: 'shared' }, | ||
], | ||
}, | ||
}) | ||
); | ||
|
||
(fs.existsSync as jest.Mock).mockReturnValue(true); | ||
(fs.readFileSync as jest.Mock).mockReturnValue( | ||
JSON.stringify({ | ||
dependencies: { | ||
'@angular/core': '~13.2.0', | ||
}, | ||
}) | ||
); | ||
|
||
(workspace.readTsConfig as jest.Mock).mockReturnValue({ | ||
options: { | ||
paths: { | ||
shared: ['/libs/shared/src/index.ts'], | ||
}, | ||
}, | ||
}); | ||
|
||
// ACT | ||
const config = await withModuleFederation({ | ||
name: 'remote1', | ||
exposes: { './Module': 'apps/remote1/src/module.ts' }, | ||
}); | ||
|
||
// ASSERT | ||
expect(config.plugins).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.