-
Notifications
You must be signed in to change notification settings - Fork 170
✅ [RUM-14696] Improve microfrontend e2e test - plugin + module federation #4220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
amortemousque
wants to merge
2
commits into
main
Choose a base branch
from
aymeric/e2e-test-microfrontend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,450
−329
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,3 @@ | ||
| dist | ||
| node_modules | ||
| .yarn/* |
This file contains hidden or 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,3 @@ | ||
| import { createApp } from './common' | ||
|
|
||
| createApp('app1', 'App 1 (mfe-app1-service v1.0.0)', 'blue') |
This file contains hidden or 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,3 @@ | ||
| import { createApp } from './common' | ||
|
|
||
| createApp('app2', 'App 2 (mfe-app2-service v0.2.0)', 'green') |
This file contains hidden or 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,2 @@ | ||
| // @ts-ignore The dynamic import keeps shell.ts out of the entry chunk, | ||
| void import('./shell') |
This file contains hidden or 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 @@ | ||
| function createContainer(id: string, title: string, borderColor: string) { | ||
| const container = document.createElement('div') | ||
| container.id = id | ||
| container.style.flex = '1' | ||
| container.style.border = `2px solid ${borderColor}` | ||
| container.style.padding = '10px' | ||
|
|
||
| const appTitle = document.createElement('h2') | ||
| appTitle.textContent = title | ||
| container.appendChild(appTitle) | ||
| document.body.appendChild(container) | ||
| return container | ||
| } | ||
|
|
||
| function createButton(container: HTMLElement, eventType: string, clickHandler: () => void) { | ||
| const button = document.createElement('button') | ||
| button.id = `${container.id}-${eventType}` | ||
| button.textContent = `${container.id}-${eventType}` | ||
| button.onclick = clickHandler | ||
| container.appendChild(button) | ||
| } | ||
|
|
||
| export function createApp(id: string, title: string, borderColor: string) { | ||
| const container = createContainer(id, title, borderColor) | ||
|
|
||
| createButton(container, 'fetch', () => { | ||
| void fetch('/ok') | ||
| }) | ||
|
|
||
| createButton(container, 'xhr', () => { | ||
| const xhr = new XMLHttpRequest() | ||
| xhr.open('GET', '/ok') | ||
| xhr.send() | ||
| }) | ||
|
|
||
| createButton(container, 'error', () => { | ||
| window.DD_RUM.addError(new Error(`${id}-error`)) | ||
| }) | ||
|
|
||
| createButton(container, 'console-error', () => { | ||
| console.error(`${id}-console-error`) | ||
| }) | ||
|
|
||
| createButton(container, 'runtime-error', () => { | ||
| throw new Error(`${id}-runtime-error`) | ||
| }) | ||
|
|
||
| createButton(container, 'loaf', () => { | ||
| const end = performance.now() + 55 | ||
| while (performance.now() < end) { | ||
| // block the handler for ~55ms to trigger a long task | ||
| } | ||
| }) | ||
|
|
||
| createButton(container, 'custom-action', () => { | ||
| window.DD_RUM.addAction(`${id}-action`) | ||
| }) | ||
|
|
||
| createButton(container, 'vital', () => { | ||
| const ref = window.DD_RUM.startDurationVital(`${id}-vital`) | ||
| window.DD_RUM.stopDurationVital(ref) | ||
| }) | ||
|
|
||
| createButton(container, 'view', () => { | ||
| window.DD_RUM.startView({ name: `${id}-view` }) | ||
| }) | ||
| } |
This file contains hidden or 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,15 @@ | ||
| { | ||
| "name": "microfrontend-test-app", | ||
| "private": true, | ||
| "scripts": { | ||
| "build": "webpack --config webpack.app1.js && webpack --config webpack.app2.js && webpack --config webpack.shell.js" | ||
| }, | ||
| "devDependencies": { | ||
| "@datadog/webpack-plugin": "^3.1.0", | ||
| "@module-federation/enhanced": "^2.0.1", | ||
| "ts-loader": "9.5.4", | ||
| "typescript": "5.9.3", | ||
| "webpack": "5.105.2", | ||
| "webpack-cli": "^6.0.1" | ||
| } | ||
| } | ||
This file contains hidden or 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,6 @@ | ||
| async function initShell() { | ||
| // @ts-ignore Module Federation remote entries | ||
| await Promise.all([import('app1/app1'), import('app2/app2')]) | ||
| } | ||
|
|
||
| void initShell() |
This file contains hidden or 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,10 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ES2018", | ||
| "module": "esnext", | ||
| "lib": ["ES2018", "DOM"], | ||
| "moduleResolution": "node", | ||
| "esModuleInterop": true, | ||
| "skipLibCheck": true | ||
| } | ||
| } |
This file contains hidden or 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,12 @@ | ||
| // declare module 'app1/app1' | ||
| // declare module 'app2/app2' | ||
amortemousque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| interface Window { | ||
| DD_RUM: { | ||
| addError: (error: Error) => void | ||
| addAction: (name: string, context?: any) => void | ||
| startDurationVital: (name: string) => any | ||
| stopDurationVital: (ref: any) => void | ||
| startView: (options: { name: string }) => void | ||
| } | ||
| } | ||
This file contains hidden or 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,38 @@ | ||
| const path = require('node:path') | ||
| const { datadogWebpackPlugin } = require('@datadog/webpack-plugin') | ||
| const { ModuleFederationPlugin } = require('@module-federation/enhanced/webpack') | ||
|
|
||
| module.exports = { | ||
| mode: 'development', | ||
| devtool: 'source-map', | ||
| module: { | ||
| rules: [{ test: /\.ts$/, use: 'ts-loader' }], | ||
| }, | ||
| resolve: { | ||
| extensions: ['.ts', '.js'], | ||
| }, | ||
| output: { | ||
| path: path.resolve(__dirname, 'dist'), | ||
| filename: 'app1.js', | ||
| chunkFilename: 'chunks/[name]-[contenthash]-app1.js', | ||
| publicPath: 'auto', | ||
| }, | ||
| plugins: [ | ||
| new ModuleFederationPlugin({ | ||
| name: 'app1', | ||
| filename: 'app1Entry.js', | ||
| exposes: { | ||
| './app1': './app1.ts', | ||
| }, | ||
| }), | ||
| datadogWebpackPlugin({ | ||
| rum: { | ||
| enable: true, | ||
| sourceCodeContext: { | ||
| service: 'mfe-app1-service', | ||
| version: '1.0.0', | ||
| }, | ||
| }, | ||
| }), | ||
| ], | ||
amortemousque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or 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,38 @@ | ||
| const path = require('node:path') | ||
| const { datadogWebpackPlugin } = require('@datadog/webpack-plugin') | ||
| const { ModuleFederationPlugin } = require('@module-federation/enhanced/webpack') | ||
|
|
||
| module.exports = { | ||
| mode: 'development', | ||
| devtool: 'source-map', | ||
| module: { | ||
| rules: [{ test: /\.ts$/, use: 'ts-loader' }], | ||
| }, | ||
| resolve: { | ||
| extensions: ['.ts', '.js'], | ||
| }, | ||
| output: { | ||
| path: path.resolve(__dirname, 'dist'), | ||
| filename: 'app2.js', | ||
| chunkFilename: 'chunks/[name]-[contenthash]-app2.js', | ||
| publicPath: 'auto', | ||
| }, | ||
| plugins: [ | ||
| new ModuleFederationPlugin({ | ||
| name: 'app2', | ||
| filename: 'app2Entry.js', | ||
| exposes: { | ||
| './app2': './app2.ts', | ||
| }, | ||
| }), | ||
| datadogWebpackPlugin({ | ||
| rum: { | ||
| enable: true, | ||
| sourceCodeContext: { | ||
| service: 'mfe-app2-service', | ||
| version: '0.2.0', | ||
| }, | ||
| }, | ||
| }), | ||
| ], | ||
| } |
This file contains hidden or 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,39 @@ | ||
| const path = require('node:path') | ||
| const { datadogWebpackPlugin } = require('@datadog/webpack-plugin') | ||
| const { ModuleFederationPlugin } = require('@module-federation/enhanced/webpack') | ||
|
|
||
| module.exports = { | ||
| mode: 'development', | ||
| entry: './bootstrap.ts', | ||
| devtool: 'source-map', | ||
| module: { | ||
| rules: [{ test: /\.ts$/, use: 'ts-loader' }], | ||
| }, | ||
| resolve: { | ||
| extensions: ['.ts', '.js'], | ||
| }, | ||
| output: { | ||
| path: path.resolve(__dirname, 'dist'), | ||
| filename: 'shell.js', | ||
| chunkFilename: 'chunks/[name]-[contenthash]-shell.js', | ||
| publicPath: 'auto', | ||
| }, | ||
| plugins: [ | ||
| new ModuleFederationPlugin({ | ||
| name: 'shell', | ||
| remotes: { | ||
| app1: 'app1@/microfrontend/app1Entry.js', | ||
| app2: 'app2@/microfrontend/app2Entry.js', | ||
| }, | ||
| }), | ||
| datadogWebpackPlugin({ | ||
| rum: { | ||
| enable: true, | ||
| sourceCodeContext: { | ||
| service: 'mf-shell-service', | ||
| version: '2.0.0', | ||
| }, | ||
| }, | ||
| }), | ||
| ], | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.