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

add message option #376

Merged
merged 1 commit into from
Nov 10, 2024
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,9 @@ Each section in the config can have these options:
Format: `100 B`, `10 kB`, `500 ms`, `1 s`.
* **name**: the name of the current section. It will only be useful
if you have multiple sections.
* **message**: an optional custom message to display additional information,
such as guidance for resolving errors, relevant links, or instructions
for next steps when a limit is exceeded.
* **entry**: when using a custom webpack config, a webpack entry could be given.
It could be a string or an array of strings.
By default, the total size of all entry points will be checked.
Expand Down
3 changes: 3 additions & 0 deletions packages/size-limit/create-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ function createHumanReporter(process, isSilentMode = false) {
}
let diff = formatBytes(check.size - check.sizeLimit)
print(red(`Package size limit has exceeded by ${diff}`))
if (check.message) {
print(check.message)
}
} else if (check.highlightLess && check.size < check.sizeLimit) {
let diff = formatBytes(check.sizeLimit - check.size)
print(bgGreen(black(`Package size is ${diff} less than limit`)))
Expand Down
1 change: 1 addition & 0 deletions packages/size-limit/get-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ let OPTIONS = {
ignore: ['webpack', 'esbuild'],
import: ['webpack', 'esbuild'],
limit: true,
message: true,
modifyEsbuildConfig: 'esbuild',
modifyWebpackConfig: 'webpack',
module: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ exports[`renders config-less result 1`] = `
"
`;

exports[`renders custom message 1`] = `
"
Package size limit has exceeded by 1 B
see docs for additional instructions
Size limit: 100 B
Size: 101 B brotlied

Try to reduce size or increase limit at .size-limit.json
"
`;

exports[`renders failed results 1`] = `
"
ok
Expand Down
18 changes: 18 additions & 0 deletions packages/size-limit/test/create-reporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,24 @@ it('renders single result', () => {
).toMatchSnapshot()
})

it('renders custom message', () => {
expect(
results(['file'], {
checks: [
{
message: 'see docs for additional instructions',
name: 'big fail',
passed: false,
size: 101,
sizeLimit: 100
}
],
configPath: '.size-limit.json',
failed: true
})
).toMatchSnapshot()
})

it('renders config-less result', () => {
expect(
results(['time'], {
Expand Down