Skip to content

Commit

Permalink
test(integration): add module federation test
Browse files Browse the repository at this point in the history
Cherry-picked from webpack#2723.

Co-authored-by: Loonride <knagaitsev1@gmail.com>
  • Loading branch information
ylemkimon and knagaitsev committed Nov 17, 2020
1 parent 5f0f747 commit d5089ec
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/fixtures/module-federation-config/entry1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = 'entry1';
3 changes: 3 additions & 0 deletions test/fixtures/module-federation-config/entry2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = 'entry2';
15 changes: 15 additions & 0 deletions test/fixtures/module-federation-config/webpack.config.js
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 test/fixtures/module-federation-config/webpack.multi.config.js
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',
},
},
];
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',
},
};
55 changes: 55 additions & 0 deletions test/integration/ModuleFederation.test.js
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');
});
}
});
});
1 change: 1 addition & 0 deletions test/ports-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const portsList = {
'static-publicPath-option': 1,
'contentBasePublicPath-option': 1,
bundle: 1,
ModuleFederation: 1,
};

let startPort = 8089;
Expand Down

0 comments on commit d5089ec

Please sign in to comment.