Skip to content

Commit

Permalink
fix: serve recognizes color flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgeorge007 committed Jul 20, 2020
1 parent f43481e commit 98636a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/serve/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export default function serve(...args: string[]): void {
const core = cli.getCoreFlags();

const parsedDevServerArgs = cli.argParser(devServer, args, true);
if (parsedDevServerArgs.unknownArgs.some((arg) => ['help', 'version', 'color'].includes(arg))) return;

const devServerArgs = parsedDevServerArgs.opts;
const parsedWebpackArgs = cli.argParser(core, parsedDevServerArgs.unknownArgs, true, process.title);
const webpackArgs = parsedWebpackArgs.opts;
Expand Down
14 changes: 14 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 chalk = require('chalk');
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,16 @@ describe('basic serve usage', () => {
console.warn('TODO: fix `serve` test on windows');
});
} else {
it('should respect the --color=false flag', async () => {
const { stdout, stderr } = await runServe(['help', '--color=false'], __dirname);
chalk.enabled = true;
chalk.level = 3;
const orange = chalk.keyword('orange');
expect(stdout).not.toContain(orange(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

0 comments on commit 98636a9

Please sign in to comment.