Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(serve): supplying help or version as an arg should throw #1694

Merged
merged 4 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/serve/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export default function serve(...args: string[]): void {
parsedWebpackArgs.unknownArgs
.filter((e) => e)
.forEach((unknown) => {
logger.warn('Unknown argument:', unknown);
logger.error('Unknown argument:', unknown);
});
return;
process.exit(2);
}

cli.getCompiler(webpackArgs, core).then((compiler): void => {
Expand Down
11 changes: 11 additions & 0 deletions test/help/help-commands.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ const { run } = require('../utils/test-utils');
const helpHeader = 'The build tool for modern web applications';

describe('commands help', () => {
it('throws error if supplied as an argument for subcommands', () => {
const { stderr } = run(__dirname, ['serve', 'help'], false);
jamesgeorge007 marked this conversation as resolved.
Show resolved Hide resolved
expect(stderr).toContain('Unknown argument: help');
});

it('shows help information with subcommands as an arg', () => {
const { stdout, stderr } = run(__dirname, ['help', 'serve'], false);
expect(stdout).toContain('webpack s | serve');
expect(stderr).toHaveLength(0);
});

it('throws error for invalid command with --help flag', () => {
const { stderr } = run(__dirname, ['--help', 'myCommand'], false);
expect(stderr).toContain(`You provided an invalid command 'myCommand'`);
Expand Down
12 changes: 12 additions & 0 deletions test/serve/basic/serve-basic.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
'use strict';

const { yellow, options } = require('colorette');
const path = require('path');
const getPort = require('get-port');
const { runServe } = require('../../utils/test-utils');

const testPath = path.resolve(__dirname);

const usageText = 'webpack s | serve';
const descriptionText = 'Run the webpack Dev Server';

describe('basic serve usage', () => {
let port;

Expand All @@ -23,6 +27,14 @@ describe('basic serve usage', () => {
console.warn('TODO: fix `serve` test on windows');
});
} else {
it('should respect the --no-color flag', async () => {
const { stdout, stderr } = await runServe(['--help', '--no-color'], __dirname);
options.enabled = true;
expect(stdout).not.toContain(yellow(usageText));
expect(stdout).toContain(descriptionText);
expect(stderr).toHaveLength(0);
});

it('should not invoke info subcommand', async () => {
const { stdout, stderr } = await runServe(['--client-log-level', 'info'], testPath);
expect(stdout).toContain('main.js');
Expand Down