Skip to content

Commit

Permalink
tests: add test cases for --ignore-warnings (#2294)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Jan 3, 2021
1 parent fd4fb41 commit 764036b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/core-flags/ignore-warnings/ignore-warnings-flag.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

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

describe('ignore-warnings', () => {
it('should ignore the warning emitted', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--ignore-warnings', /Generated Warning/]);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).not.toContain('Module Warning (from ./my-warning-loader.js):');
expect(stdout).not.toContain('Generated Warning');
});

it('should reset options.ignoreWarnings', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--ignore-warnings', /Generated Warning/, '--ignore-warnings-reset']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain('Module Warning (from ./my-warning-loader.js):');
expect(stdout).toContain('Generated Warning');
});

it('should throw error for an invalid value', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--ignore-warnings', 'abc']);

expect(exitCode).toBe(2);
expect(stderr).toContain(`Invalid value 'abc' for the '--ignore-warnings' option`);
expect(stderr).toContain(`Expected: 'regular expression (example: /ab?c*/)'`);
expect(stdout).toBeFalsy();
});
});
5 changes: 5 additions & 0 deletions test/core-flags/ignore-warnings/my-warning-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = function loader(source) {
const { emitWarning } = this;
emitWarning('Generated Warning');
return source;
};
1 change: 1 addition & 0 deletions test/core-flags/ignore-warnings/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Entry');
24 changes: 24 additions & 0 deletions test/core-flags/ignore-warnings/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const path = require('path');

module.exports = {
mode: 'development',
entry: './src/main.js',
module: {
rules: [
{
test: /.(js|jsx)?$/,
loader: 'my-warning-loader',
include: [path.resolve(__dirname, 'src')],
exclude: [/node_modules/],
},
],
},
resolveLoader: {
alias: {
'my-warning-loader': require.resolve('./my-warning-loader'),
},
},
performance: {
hints: 'warning',
},
};

0 comments on commit 764036b

Please sign in to comment.