forked from webpack/webpack-dev-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(integration): add module federation test
Cherry-picked from webpack#2723. Co-authored-by: Loonride <knagaitsev1@gmail.com>
- Loading branch information
1 parent
5f0f747
commit d5089ec
Showing
7 changed files
with
112 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
module.exports = 'entry1'; |
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 @@ | ||
'use strict'; | ||
|
||
module.exports = 'entry2'; |
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 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
mode: 'development', | ||
target: 'node', | ||
context: __dirname, | ||
entry: ['./entry1.js', './entry2.js'], | ||
output: { | ||
path: '/', | ||
libraryTarget: 'umd', | ||
}, | ||
infrastructureLogging: { | ||
level: 'warn', | ||
}, | ||
}; |
17 changes: 17 additions & 0 deletions
17
test/fixtures/module-federation-config/webpack.multi.config.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,17 @@ | ||
'use strict'; | ||
|
||
module.exports = [ | ||
{ | ||
mode: 'development', | ||
target: 'node', | ||
context: __dirname, | ||
entry: ['./entry1.js', './entry2.js'], | ||
output: { | ||
path: '/', | ||
libraryTarget: 'umd', | ||
}, | ||
infrastructureLogging: { | ||
level: 'warn', | ||
}, | ||
}, | ||
]; |
18 changes: 18 additions & 0 deletions
18
test/fixtures/module-federation-config/webpack.object-entry.config.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,18 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
mode: 'development', | ||
target: 'node', | ||
context: __dirname, | ||
entry: { | ||
foo: './entry1.js', | ||
main: ['./entry1.js', './entry2.js'], | ||
}, | ||
output: { | ||
path: '/', | ||
libraryTarget: 'umd', | ||
}, | ||
infrastructureLogging: { | ||
level: 'warn', | ||
}, | ||
}; |
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,55 @@ | ||
'use strict'; | ||
|
||
const request = require('supertest'); | ||
const requireFromString = require('require-from-string'); | ||
const testServer = require('../helpers/test-server'); | ||
const simpleConfig = require('../fixtures/module-federation-config/webpack.config'); | ||
const objectEntryConfig = require('../fixtures/module-federation-config/webpack.object-entry.config'); | ||
const multiConfig = require('../fixtures/module-federation-config/webpack.multi.config'); | ||
const port = require('../ports-map').ModuleFederation; | ||
|
||
describe('module federation', () => { | ||
describe.each([ | ||
['simple multi-entry config', simpleConfig], | ||
['object multi-entry config', objectEntryConfig], | ||
['multi compiler config', multiConfig], | ||
])('%s', (title, config) => { | ||
let server; | ||
let req; | ||
|
||
beforeAll((done) => { | ||
server = testServer.start(config, { port }, done); | ||
req = request(server.app); | ||
}); | ||
|
||
afterAll(testServer.close); | ||
|
||
it('should use the last entry export', async () => { | ||
const { text, statusCode } = await req.get('/main.js'); | ||
expect(statusCode).toEqual(200); | ||
expect(text).toContain('entry1'); | ||
|
||
let exports; | ||
expect(() => { | ||
exports = requireFromString(text); | ||
}).not.toThrow(); | ||
|
||
expect(exports).toEqual('entry2'); | ||
}); | ||
|
||
if (title === 'object multi-entry config') { | ||
it('should support the named entry export', async () => { | ||
const { text, statusCode } = await req.get('/foo.js'); | ||
expect(statusCode).toEqual(200); | ||
expect(text).not.toContain('entry2'); | ||
|
||
let exports; | ||
expect(() => { | ||
exports = requireFromString(text); | ||
}).not.toThrow(); | ||
|
||
expect(exports).toEqual('entry1'); | ||
}); | ||
} | ||
}); | ||
}); |
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