Skip to content

Commit

Permalink
refactor: config group to pure function and move away from group desi…
Browse files Browse the repository at this point in the history
…gn (#1811)

* chore: remove default value from config/entry flag
* refactor: ConfigGroup remove from group design
  • Loading branch information
anshumanv committed Sep 21, 2020
1 parent 6140b24 commit 242d2ec
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 196 deletions.
2 changes: 0 additions & 2 deletions packages/serve/__tests__/__snapshots__/parseArgs.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Object {
},
"webpackArgs": Object {
"color": true,
"config": Array [],
"hot": true,
"mode": "production",
},
Expand Down Expand Up @@ -41,7 +40,6 @@ Object {
},
"webpackArgs": Object {
"color": true,
"config": Array [],
"mode": "development",
},
}
Expand Down
15 changes: 5 additions & 10 deletions packages/webpack-cli/__tests__/ConfigGroup/ConfigGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const promiseConfig = require('./webpack.promise.config.cjs');

describe('ConfigGroup', function () {
it('should handle merge properly', async () => {
const group = new ConfigGroup([
const result = await ConfigGroup([
{
merge: true,
},
Expand All @@ -16,7 +16,6 @@ describe('ConfigGroup', function () {
},
]);

const result = await group.run();
const expectedOptions = {
output: { filename: './dist-commonjs.js', libraryTarget: 'commonjs' },
entry: './a.js',
Expand All @@ -30,35 +29,31 @@ describe('ConfigGroup', function () {
});

it('should return array for multiple config', async () => {
const group = new ConfigGroup([
const result = await ConfigGroup([
{ config: [resolve(__dirname, './webpack.config1.cjs'), resolve(__dirname, './webpack.config2.cjs')] },
]);
const result = await group.run();
const expectedOptions = [config1, config2];
expect(result.options).toEqual(expectedOptions);
expect(result.outputOptions).toEqual({});
});

it('should return config object for single config', async () => {
const group = new ConfigGroup([{ config: [resolve(__dirname, './webpack.config1.cjs')] }]);
const result = await group.run();
const result = await ConfigGroup([{ config: [resolve(__dirname, './webpack.config1.cjs')] }]);
expect(result.options).toEqual(config1);
expect(result.outputOptions).toEqual({});
});

it('should return resolved config object for promise config', async () => {
const group = new ConfigGroup([{ config: [resolve(__dirname, './webpack.promise.config.cjs')] }]);
const result = await group.run();
const result = await ConfigGroup([{ config: [resolve(__dirname, './webpack.promise.config.cjs')] }]);
const expectedOptions = await promiseConfig();
expect(result.options).toEqual(expectedOptions);
expect(result.outputOptions).toEqual({});
});

it('should handle configs returning different types', async () => {
const group = new ConfigGroup([
const result = await ConfigGroup([
{ config: [resolve(__dirname, './webpack.promise.config.cjs'), resolve(__dirname, './webpack.config.cjs')] },
]);
const result = await group.run();
const resolvedPromiseConfig = await promiseConfig();
const expectedOptions = [resolvedPromiseConfig, ...arrayConfig];
expect(result.options).toEqual(expectedOptions);
Expand Down
9 changes: 0 additions & 9 deletions packages/webpack-cli/__tests__/GroupHelper.test.js

This file was deleted.

Loading

0 comments on commit 242d2ec

Please sign in to comment.