Skip to content

Commit

Permalink
Add --hide-passed flag to only output failed checks (#199)
Browse files Browse the repository at this point in the history
* Add `--quiet` flag to only output failed checks

* Rename `--quiet` -> `--hide-passed`
  • Loading branch information
koddsson committed Sep 7, 2020
1 parent 84d9d87 commit edb7d99
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/size-limit/create-reporter.js
Expand Up @@ -67,6 +67,8 @@ function createHumanReporter (process) {
results (plugins, config) {
print('')
for (let check of config.checks) {
if (check.passed && config.hidePassed) continue

let unlimited = typeof check.passed === 'undefined'
let rows = []

Expand Down
6 changes: 5 additions & 1 deletion packages/size-limit/get-config.js
Expand Up @@ -18,7 +18,8 @@ let OPTIONS = {
gzip: ['webpack', 'file'],
running: 'time',
disableModuleConcatenation: 'webpack',
brotli: 'webpack'
brotli: 'webpack',
hidePassed: false
}

function isStrings (value) {
Expand Down Expand Up @@ -87,6 +88,9 @@ module.exports = async function getConfig (plugins, process, args, pkg) {
if (args.cleanDir) {
config.cleanDir = args.cleanDir
}
if (args.hidePassed) {
config.hidePassed = args.hidePassed
}

if (args.files.length > 0) {
config.checks = [{ files: args.files }]
Expand Down
2 changes: 2 additions & 0 deletions packages/size-limit/parse-args.js
Expand Up @@ -26,6 +26,8 @@ module.exports = function parseArgs (plugins, argv) {
)
}
args.cleanDir = true
} else if (arg === '--hide-passed') {
args.hidePassed = true
} else if (arg === '--why') {
if (!plugins.has('webpack')) {
throw new SizeLimitError('argWithoutWebpack', 'why')
Expand Down
@@ -1,5 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`only renders failed results with --hide-passed flag 1`] = `
"
small fail
Package size limit has exceeded by 1 B
Size limit: 102400 B
Size: 102401 B gzipped
big fail
Package size limit has exceeded by 100 B
Size limit: 100 KB
Size: 100.1 KB gzipped
Try to reduce size or increase limit in \\"size-limit\\" section of package.json
"
`;

exports[`renders JSON results 1`] = `
"[
{
Expand Down
30 changes: 30 additions & 0 deletions packages/size-limit/test/create-reporter.test.js
Expand Up @@ -84,6 +84,36 @@ it('renders failed results', () => {
).toMatchSnapshot()
})

it('only renders failed results with --hide-passed flag', () => {
expect(
results(['file'], {
checks: [
{
name: 'ok',
size: 102400,
sizeLimit: 102400,
passed: true
},
{
name: 'small fail',
size: 102401,
sizeLimit: 102400,
passed: false
},
{
name: 'big fail',
size: 102500,
sizeLimit: 102400,
passed: false
}
],
hidePassed: true,
failed: true,
configPath: 'package.json'
})
).toMatchSnapshot()
})

it('renders single result', () => {
expect(
results(['file'], {
Expand Down
3 changes: 2 additions & 1 deletion packages/size-limit/test/get-config.test.js
Expand Up @@ -100,12 +100,13 @@ it('overrides limit by CLI arg', async () => {
})

it('normalizes bundle and webpack arguments', async () => {
let args = ['--why', '--save-bundle', 'out', '--clean-dir']
let args = ['--why', '--save-bundle', 'out', '--clean-dir', '--hide-passed']
expect(await check('webpack', args)).toEqual({
configPath: 'package.json',
cwd: fixture('webpack'),
why: true,
project: 'webpack',
hidePassed: true,
saveBundle: fixture('webpack', 'out'),
cleanDir: true,
checks: [
Expand Down

0 comments on commit edb7d99

Please sign in to comment.