-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f0cbb0
commit 8f33287
Showing
25 changed files
with
403 additions
and
65 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 |
---|---|---|
|
@@ -3,4 +3,5 @@ node_modules | |
npm-debug.log | ||
.idea | ||
/test/bundle.test.js | ||
/federated/dist/ | ||
dist/ | ||
dist-test/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import Form from "./form"; | ||
|
||
const App = () => { | ||
return ( | ||
<div> | ||
<p>hello world</p> | ||
<Form/> | ||
</div> | ||
) | ||
} | ||
|
||
export default App |
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,4 @@ | ||
import React from "react"; | ||
import ReactDOM from "react-dom" | ||
import App from './App' | ||
ReactDOM.render(<App/>, document.getElementById('app')) |
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,15 @@ | ||
import React from "react"; | ||
import lazy from 'react-lazy-ssr'; | ||
const Button = lazy(()=>import('federated/Button'),{chunkId:"federated/Button"}) | ||
// const Button = process.env.NODE_ENV === 'test' ? require('federated/Button').default : React.lazy(()=>import('federated/Button')) | ||
// const Suspense = process.env.NODE_ENV === 'test' ? ({children})=>children : React.Suspense | ||
const Suspense = React.Suspense | ||
const Form = () =>( | ||
<form> | ||
<input type="text"/> | ||
<Suspense fallback={"failed"} loading={"loading"}> | ||
<Button/> | ||
</Suspense> | ||
</form> | ||
) | ||
export default Form |
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 @@ | ||
import("./bootstrap") |
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,49 @@ | ||
const path = require('path'); | ||
const glob = require('glob'); | ||
const webpack = require("webpack") | ||
const {ModuleFederationPlugin} = webpack.container | ||
const HTMLPlugin = require('html-webpack-plugin') | ||
const deps = require('../package.json') | ||
module.exports = { | ||
entry: require.resolve('./index.js'), | ||
output: { | ||
path: path.resolve(__dirname, "./dist"), | ||
publicPath: "auto" | ||
}, | ||
cache:false, | ||
target: "web", | ||
resolve: { | ||
fallback: { | ||
path: false | ||
} | ||
}, | ||
mode: "none", | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.js$/, | ||
exclude: /node_modules/, | ||
loader: 'babel-loader' | ||
}, | ||
] | ||
}, | ||
plugins: [ | ||
new ModuleFederationPlugin({ | ||
name: 'fed_consumer', | ||
filename:"remoteEntry.js", | ||
remotes: { | ||
"federated": "federated@http://localhost:3001/remoteEntry.js" | ||
}, | ||
shared: { | ||
react: deps.devDependencies.react, | ||
"react-dom": deps.devDependencies["react-dom"] | ||
} | ||
}), | ||
new HTMLPlugin({ | ||
templateContent:'<div id="app"></div>' | ||
}), | ||
new webpack.DefinePlugin({ | ||
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || "development"), | ||
}) | ||
] | ||
}; |
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,49 @@ | ||
const path = require('path'); | ||
const glob = require('glob'); | ||
const webpack = require("webpack") | ||
const {ModuleFederationPlugin} = webpack.container | ||
const HTMLPlugin = require('html-webpack-plugin') | ||
const deps = require('../package.json') | ||
const reunited = require('../index') | ||
module.exports = { | ||
entry: require.resolve('./index.js'), | ||
output: { | ||
path: path.resolve(__dirname, "./dist-test"), | ||
}, | ||
target: "node", | ||
resolve: { | ||
fallback: { | ||
path: false | ||
} | ||
}, | ||
mode: "none", | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.js$/, | ||
exclude: /node_modules/, | ||
loader: 'babel-loader' | ||
}, | ||
] | ||
}, | ||
plugins: [ | ||
new ModuleFederationPlugin({ | ||
name: 'fed_consumer', | ||
filename: "remoteEntry.js", | ||
library: {type: "commonjs-module", name: "fed_consumer"}, | ||
remotes: { | ||
"federated": reunited(path.resolve(__dirname, '../federated-test/dist-test/remoteEntry.js'), "federated") | ||
}, | ||
exposes: { | ||
"./Form": "./federated-cross-test/form.js" | ||
}, | ||
shared: { | ||
react: deps.devDependencies.react, | ||
"react-dom": deps.devDependencies["react-dom"] | ||
} | ||
}), | ||
new webpack.DefinePlugin({ | ||
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || "test"), | ||
}) | ||
] | ||
}; |
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,15 @@ | ||
{ | ||
"presets": [ | ||
"@babel/preset-react", | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"node": "current" | ||
} | ||
} | ||
] | ||
], | ||
"plugins": [ | ||
] | ||
} |
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,3 @@ | ||
import React from "react"; | ||
const Button =()=> (<button>I am button</button>) | ||
export default Button |
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
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,45 @@ | ||
const path = require('path'); | ||
const glob = require('glob'); | ||
const webpack = require('webpack') | ||
const {ModuleFederationPlugin} = webpack.container | ||
const deps = require('../package.json') | ||
|
||
module.exports = { | ||
entry: require.resolve('./index.js'), | ||
output: { | ||
path: path.resolve(__dirname, "./dist-test"), | ||
}, | ||
target: "node", | ||
resolve: { | ||
fallback: { | ||
path: false | ||
} | ||
}, | ||
mode: "none", | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.js$/, | ||
exclude: /node_modules/, | ||
loader: 'babel-loader' | ||
}, | ||
] | ||
}, | ||
plugins: [ | ||
new ModuleFederationPlugin({ | ||
name: 'federated', | ||
filename: "remoteEntry.js", | ||
library: {type: "commonjs-module", name: "federated"}, | ||
exposes: { | ||
"./Button": "./federated-test/Button.js" | ||
}, | ||
shared: { | ||
react: deps.devDependencies.react, | ||
"react-dom": deps.devDependencies["react-dom"] | ||
} | ||
}), | ||
new webpack.DefinePlugin({ | ||
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || "test"), | ||
}) | ||
] | ||
}; |
This file was deleted.
Oops, something went wrong.
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,30 @@ | ||
module.exports = function(remotePath,name) { | ||
return `promise new Promise(res => { | ||
let remote | ||
const remotePath = "${remotePath}" | ||
try { | ||
remote = require(remotePath)['${name}'] | ||
} catch (e) { | ||
delete require.cache[remotePath] | ||
remote = require(remotePath)['${name}'] | ||
} | ||
if(!remote || !remote.get) { | ||
return new Promise(function(delayResolve){ | ||
var interval = setInterval(function(){ | ||
delete require.cache[remotePath] | ||
remote = require(remotePath); | ||
if(require(remotePath)) { | ||
delayResolve(require(remotePath)['${name}']); | ||
clearInterval(interval); | ||
} | ||
}, 100) | ||
}).then(function(){ | ||
setTimeout(function(){res(remote)},0) | ||
}) | ||
} | ||
const proxy = {get:(request)=> remote.get(request),init:(arg)=>{try {return remote.init(arg)} catch(e){console.log('remote container already initialized')}}} | ||
res(proxy) | ||
})` | ||
} |
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,25 @@ | ||
process.env.TZ = 'UTC'; | ||
|
||
module.exports = { | ||
moduleNameMapper: { | ||
// moduleNameMapper: { | ||
// '^react-dom$': compat, | ||
// '^react$': compat, | ||
// }, | ||
'\\.(css|scss|png|ico)$': 'identity-obj-proxy', | ||
'\\.(svg|jpg|png)': '<rootDir>/jest /file-mock.js', | ||
}, | ||
testPathIgnorePatterns: ['/node_modules/'], | ||
transformIgnorePatterns: [ | ||
], | ||
setupFiles: [ | ||
'./jest/jestSetup.js', | ||
], | ||
snapshotSerializers: ['enzyme-to-json/serializer'], | ||
// Used to run Garbage Collection after each describe block | ||
// This will reduce our memory used in CI | ||
// https://dev.to/pustovalov_p/reducing-jest-memory-usage-1ina | ||
setupFilesAfterEnv: [ | ||
'./jest/force-gc.js', | ||
], | ||
}; |
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 @@ | ||
export default ""; |
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,16 @@ | ||
|
||
global.testRuns = 0; | ||
|
||
// Used to run Garbage Collection after each describe block | ||
// This will reduce our memory used in CI | ||
// We limit it to run after every 10 decribe blocks to | ||
// maintain the speed of testing all test files | ||
// https://dev.to/pustovalov_p/reducing-jest-memory-usage-1ina | ||
afterEach(() => { | ||
global.testRuns++; | ||
|
||
if (global.testRuns < 10) return null; | ||
if (global.gc) global.gc(); | ||
|
||
global.testRuns = 0; | ||
}); |
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,6 @@ | ||
import Enzyme, { shallow, render, mount } from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
|
||
// React 16 Enzyme adapter | ||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.