Skip to content

Commit

Permalink
test: disable colors on CI by default (#2404)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Feb 15, 2021
1 parent ff3dcda commit 4c786e3
Show file tree
Hide file tree
Showing 30 changed files with 287 additions and 378 deletions.
6 changes: 6 additions & 0 deletions setupTest.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
/*global jasmine*/

jest.setTimeout(240000);

if (!jasmine.testPath.includes('colors.test.js')) {
process.env.NO_COLOR = true;
}
2 changes: 2 additions & 0 deletions smoketests/missing-packages/webpack-dev-server.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

const path = require('path');
const execa = require('execa');
const { renameSync } = require('fs');
Expand Down
2 changes: 2 additions & 0 deletions smoketests/missing-packages/webpack.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

const path = require('path');
const execa = require('execa');
const { renameSync } = require('fs');
Expand Down
5 changes: 2 additions & 3 deletions test/analyze/analyze-flag.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const stripAnsi = require('strip-ansi');
const { run, runAndGetWatchProc } = require('../utils/test-utils');

describe('--analyze flag', () => {
Expand All @@ -24,7 +23,7 @@ describe('--analyze flag', () => {

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stripAnsi(stdout)).toContain('Webpack Bundle Analyzer saved report to');
expect(stripAnsi(stdout).match(/Webpack Bundle Analyzer saved report to/g)).toHaveLength(1);
expect(stdout).toContain('Webpack Bundle Analyzer saved report to');
expect(stdout.match(/Webpack Bundle Analyzer saved report to/g)).toHaveLength(1);
});
});
3 changes: 1 addition & 2 deletions test/build-errors/errors.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const stripAnsi = require('strip-ansi');
const { run } = require('../utils/test-utils');
const { readFile } = require('fs');
const { resolve } = require('path');
Expand All @@ -12,7 +11,7 @@ describe('errors', () => {
expect(exitCode).toBe(1);
expect(stderr).toBeFalsy();
expect(stdout).toMatch(/ERROR/);
expect(stripAnsi(stdout)).toMatch(/Error: Can't resolve/);
expect(stdout).toMatch(/Error: Can't resolve/);
});

it('should output JSON with the "json" flag', () => {
Expand Down
3 changes: 1 addition & 2 deletions test/build-warnings/warnings.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const stripAnsi = require('strip-ansi');
const { run } = require('../utils/test-utils');
const { existsSync, readFile } = require('fs');
const { resolve } = require('path');
Expand All @@ -12,7 +11,7 @@ describe('warnings', () => {
expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toMatch(/WARNING/);
expect(stripAnsi(stdout)).toMatch(/Error: Can't resolve/);
expect(stdout).toMatch(/Error: Can't resolve/);
});

it('should output JSON with the "json" flag', () => {
Expand Down
10 changes: 3 additions & 7 deletions test/build/basic/basic.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const stripAnsi = require('strip-ansi');
const { resolve } = require('path');
const { run } = require('../../utils/test-utils');

Expand Down Expand Up @@ -148,12 +147,9 @@ describe('bundle command', () => {
const configPath = resolve(__dirname, './log.config.js');

expect(exitCode).toBe(0);

const pureStderr = stripAnsi(stderr);

expect(pureStderr).toContain('Compiler starting...');
expect(pureStderr).toContain(`Compiler is using config: '${configPath}'`);
expect(pureStderr).toContain('Compiler finished');
expect(stderr).toContain('Compiler starting...');
expect(stderr).toContain(`Compiler is using config: '${configPath}'`);
expect(stderr).toContain('Compiler finished');
expect(stdout).toBeTruthy();
});
});
18 changes: 9 additions & 9 deletions test/colors/colors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { run, isWebpack5 } = require('../utils/test-utils');
const { resolve } = require('path');

describe('colors related tests', () => {
describe('colors', () => {
it('should output by default', () => {
const { exitCode, stderr, stdout } = run(__dirname, [], { env: { FORCE_COLOR: true } });

Expand Down Expand Up @@ -46,23 +46,23 @@ describe('colors related tests', () => {
expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
});

it('should disable colored output with --no-color', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--stats=verbose', '--no-color']);
it('should work with the "stats" option and --color flags', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--stats=verbose', '--color']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).not.toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
expect(stdout).toContain(output);
expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
});

it('should work with the "stats" option and --color flags', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--stats=verbose', '--color']);
it('should disable colored output with --no-color', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--stats=verbose', '--no-color']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
expect(stdout).not.toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
expect(stdout).toContain(output);
});

it('should work with the "stats" option from the configuration', () => {
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('colors related tests', () => {
expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
});

it('should prioratize --no-color over colors in config', () => {
it('should prioritize --no-color over colors in config', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--config=colors-true.webpack.config.js', '--no-color']);

expect(exitCode).toBe(0);
Expand Down
8 changes: 4 additions & 4 deletions test/config/multiple/multiple-config.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const stripAnsi = require('strip-ansi');
'use strict';

const { run } = require('../../utils/test-utils');

describe('Multiple config flag: ', () => {
it('spawns multiple compilers for multiple configs', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['-c', 'webpack1.config.js', '-c', 'webpack2.config.js'], false);
const { exitCode, stderr, stdout } = run(__dirname, ['--config', 'webpack1.config.js', '--config', 'webpack2.config.js'], false);

// Should contain the correct exit code
expect(exitCode).toEqual(0);
expect(stderr).toBeFalsy();
// Should spawn multiple compilers
expect(stripAnsi(stdout)).toContain('amd:');
expect(stripAnsi(stdout)).toContain('commonjs:');
expect(stdout).toContain('amd:');
expect(stdout).toContain('commonjs:');
});
});
3 changes: 1 addition & 2 deletions test/core-flags/context-flag.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const stripAnsi = require('strip-ansi');
const { resolve } = require('path');
const { run, isWindows } = require('../utils/test-utils');

Expand All @@ -24,6 +23,6 @@ describe('--context flag', () => {

expect(exitCode).toBe(1);
expect(stderr).toBeFalsy();
expect(stripAnsi(stdout)).toContain(`Module not found: Error: Can't resolve './src/main.js'`);
expect(stdout).toContain(`Module not found: Error: Can't resolve './src/main.js'`);
});
});
3 changes: 1 addition & 2 deletions test/defaults/output-defaults.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const stripAnsi = require('strip-ansi');
const { existsSync } = require('fs');
const { resolve } = require('path');
const { run } = require('../utils/test-utils');
Expand All @@ -12,7 +11,7 @@ describe('output flag defaults', () => {
expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
// Should print warning about config fallback
expect(stripAnsi(stdout)).toContain('option has not been set, webpack will fallback to');
expect(stdout).toContain('option has not been set, webpack will fallback to');

expect(existsSync(resolve(__dirname, './binary/main.js'))).toBeTruthy();
});
Expand Down
3 changes: 1 addition & 2 deletions test/entry/defaults-empty/entry-single-arg.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const stripAnsi = require('strip-ansi');
const { run } = require('../../utils/test-utils');

describe('single entry flag empty project', () => {
Expand All @@ -9,6 +8,6 @@ describe('single entry flag empty project', () => {

expect(exitCode).toBe(1);
expect(stderr).toBeFalsy();
expect(stripAnsi(stdout)).toContain(`not found: Error: Can't resolve`);
expect(stdout).toContain(`not found: Error: Can't resolve`);
});
});
3 changes: 1 addition & 2 deletions test/entry/flag-entry/entry-with-flag.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const stripAnsi = require('strip-ansi');
const { run } = require('../../utils/test-utils');
const { existsSync, readFile } = require('fs');
const { resolve } = require('path');
Expand Down Expand Up @@ -40,6 +39,6 @@ describe('entry flag', () => {

expect(exitCode).toEqual(1);
expect(stderr).toBeFalsy();
expect(stripAnsi(stdout)).toContain("Module not found: Error: Can't resolve");
expect(stdout).toContain("Module not found: Error: Can't resolve");
});
});

0 comments on commit 4c786e3

Please sign in to comment.