Skip to content

Commit f0fb80c

Browse files
refactor: code
1 parent 763f3ff commit f0fb80c

File tree

2 files changed

+38
-20
lines changed

2 files changed

+38
-20
lines changed

test/__snapshots__/loader.test.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,9 @@ Object {
275275

276276
exports[`loader should work multiple commonjs exports: warnings 1`] = `Array []`;
277277

278-
exports[`loader should work multiple name from one library: errors 1`] = `Array []`;
278+
exports[`loader should work multiple name from one package: errors 1`] = `Array []`;
279279

280-
exports[`loader should work multiple name from one library: module 1`] = `
280+
exports[`loader should work multiple name from one package: module 1`] = `
281281
"const globalObject4 = { foo: 'bar' };
282282
283283
module.exports = globalObject4;
@@ -290,7 +290,7 @@ ___EXPOSE_LOADER_GLOBAL_THIS___[\\"myGlobal\\"] = ___EXPOSE_LOADER_IMPORT___;
290290
"
291291
`;
292292

293-
exports[`loader should work multiple name from one library: result 1`] = `
293+
exports[`loader should work multiple name from one package: result 1`] = `
294294
Object {
295295
"ExposeLoader": Object {
296296
"foo": "bar",
@@ -304,7 +304,7 @@ Object {
304304
}
305305
`;
306306

307-
exports[`loader should work multiple name from one library: warnings 1`] = `Array []`;
307+
exports[`loader should work multiple name from one package: warnings 1`] = `Array []`;
308308

309309
exports[`loader should work multiple syntax to array: errors 1`] = `Array []`;
310310

test/loader.test.js

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,6 @@ describe('loader', () => {
6262
expect(getWarnings(stats)).toMatchSnapshot('warnings');
6363
});
6464

65-
it('should work multiple name from one library', async () => {
66-
const compiler = getCompiler('simple-commonjs2-single-export.js', {
67-
exposes: ['myOtherGlobal', 'myGlobal'],
68-
});
69-
const stats = await compile(compiler);
70-
71-
expect(
72-
getModuleSource('./global-commonjs2-single-export.js-exposed', stats)
73-
).toMatchSnapshot('module');
74-
expect(
75-
execute(readAsset('main.bundle.js', compiler, stats))
76-
).toMatchSnapshot('result');
77-
expect(getErrors(stats)).toMatchSnapshot('errors');
78-
expect(getWarnings(stats)).toMatchSnapshot('warnings');
79-
});
80-
8165
it('should work for a nested property for a global object', async () => {
8266
const compiler = getCompiler('simple-commonjs2-single-export.js', {
8367
exposes: 'myGlobal.nested',
@@ -267,6 +251,40 @@ describe('loader', () => {
267251
expect(getWarnings(stats)).toMatchSnapshot('warnings');
268252
});
269253

254+
it('should work multiple name from one package', async () => {
255+
const compiler = getCompiler(
256+
'simple-commonjs2-single-export.js',
257+
{
258+
exposes: ['myOtherGlobal', 'myGlobal'],
259+
},
260+
{
261+
output: {
262+
path: path.resolve(__dirname, './outputs'),
263+
filename: '[name]-[contenthash:8].bundle.js',
264+
chunkFilename: '[name]-[contenthash:8].chunk.js',
265+
library: 'ExposeLoader',
266+
libraryTarget: 'var',
267+
},
268+
}
269+
);
270+
const stats = await compile(compiler);
271+
272+
const webpack4Filename = 'main-bd1693c3.bundle.js';
273+
const webpack5Filename = 'main-b4700c39.bundle.js';
274+
const bundleName =
275+
webpack.version[0] === '5' ? webpack5Filename : webpack4Filename;
276+
277+
expect(
278+
getModuleSource('./global-commonjs2-single-export.js-exposed', stats)
279+
).toMatchSnapshot('module');
280+
expect(Object.keys(stats.compilation.assets)[0]).toBe(bundleName);
281+
expect(execute(readAsset(bundleName, compiler, stats))).toMatchSnapshot(
282+
'result'
283+
);
284+
expect(getErrors(stats)).toMatchSnapshot('errors');
285+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
286+
});
287+
270288
it('should match hashes on all operating systems', async () => {
271289
const compiler = getCompiler(
272290
'inline-import-2.js',

0 commit comments

Comments
 (0)