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
420 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
test:$6FrCaT/v0dwE:autocreated 2020-03-25T19:10:50.254Z | ||
colum:QozHQ9ck9zOe2:autocreated 2022-03-10T12:13:00.712Z |
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
101 changes: 101 additions & 0 deletions
101
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,101 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`withModuleFederation should create a host config correctly 1`] = ` | ||
Object { | ||
"experiments": Object { | ||
"outputModule": true, | ||
}, | ||
"optimization": Object { | ||
"runtimeChunk": false, | ||
}, | ||
"output": Object { | ||
"publicPath": "auto", | ||
"uniqueName": "host", | ||
}, | ||
"plugins": 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": /\\./, | ||
}, | ||
], | ||
"resolve": Object { | ||
"alias": Object { | ||
"shared": "/Users/columferry/dev/nrwl/nx/libs/shared/src/index.ts", | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`withModuleFederation should create a remote config correctly 1`] = ` | ||
Object { | ||
"experiments": Object { | ||
"outputModule": true, | ||
}, | ||
"optimization": Object { | ||
"runtimeChunk": false, | ||
}, | ||
"output": Object { | ||
"publicPath": "auto", | ||
"uniqueName": "remote1", | ||
}, | ||
"plugins": 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": /\\./, | ||
}, | ||
], | ||
"resolve": Object { | ||
"alias": Object { | ||
"shared": "/Users/columferry/dev/nrwl/nx/libs/shared/src/index.ts", | ||
}, | ||
}, | ||
} | ||
`; |
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).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).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.