Skip to content

Commit

Permalink
fix: the --progress option with the serve command (#2265)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Dec 26, 2020
1 parent e6f9943 commit 952a188
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 62 deletions.
34 changes: 0 additions & 34 deletions packages/serve/__tests__/mergeOptions.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/serve/src/index.ts
Expand Up @@ -51,7 +51,7 @@ class ServeCommand {
const processors: Array<(opts: Record<string, any>) => void> = [];

for (const optionName in options) {
if (optionName === 'hot' || optionName === 'progress') {
if (optionName === 'hot') {
devServerOptions[optionName] = options[optionName];
webpackOptions[optionName] = options[optionName];
} else {
Expand Down
24 changes: 0 additions & 24 deletions packages/serve/src/mergeOptions.ts

This file was deleted.

17 changes: 14 additions & 3 deletions packages/serve/src/startDevServer.ts
@@ -1,6 +1,4 @@
import { utils } from 'webpack-cli';

import mergeOptions from './mergeOptions';
import { devServerOptionsType } from './types';

/**
*
Expand Down Expand Up @@ -48,6 +46,19 @@ export default async function startDevServer(compiler, cliOptions, logger): Prom

const servers = [];
const usedPorts: number[] = [];
const mergeOptions = (cliOptions: devServerOptionsType, devServerOptions: devServerOptionsType): devServerOptionsType => {
// CLI options should take precedence over devServer options,
// and CLI options should have no default values included
const options = { ...devServerOptions, ...cliOptions };

if (devServerOptions.client && cliOptions.client) {
// the user could set some client options in their devServer config,
// then also specify client options on the CLI
options.client = { ...devServerOptions.client, ...cliOptions.client };
}

return options;
};

for (const devServerOpts of devServerOptions) {
const options = mergeOptions(cliOptions, devServerOpts);
Expand Down
16 changes: 16 additions & 0 deletions test/serve/basic/serve-basic.test.js
Expand Up @@ -61,6 +61,22 @@ describe('basic serve usage', () => {
expect(stdout).not.toContain('HotModuleReplacementPlugin');
});

it('should work with the "--progress" option', async () => {
const { stderr, stdout } = await runServe(['--progress'], __dirname);

expect(stderr).toContain('webpack.Progress');
expect(stdout).toContain('main.js');
expect(stdout).not.toContain('HotModuleReplacementPlugin');
});

it('should work with the "--progress" option using the "profile" value', async () => {
const { stderr, stdout } = await runServe(['--progress', 'profile'], __dirname);

expect(stderr).toContain('webpack.Progress');
expect(stdout).toContain('main.js');
expect(stdout).not.toContain('HotModuleReplacementPlugin');
});

it('should work with flags', async () => {
const { stderr, stdout } = await runServe(['--hot'], __dirname);

Expand Down

0 comments on commit 952a188

Please sign in to comment.