Skip to content

Commit

Permalink
Add docs and tests for new config
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed May 13, 2018
1 parent 998485b commit e91dad8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
13 changes: 12 additions & 1 deletion README.md
Expand Up @@ -138,7 +138,7 @@ to add one — start with [Travis CI](https://github.com/dwyl/learn-travis).

## Config

Size Limits supports 2 ways to define config.
Size Limits supports 3 ways to define config.

1. `size-limit` section to `package.json`:

Expand All @@ -162,6 +162,17 @@ Size Limits supports 2 ways to define config.
]
```

3. or more flexible `.size-limit.js` config file:

```js
module.exports = [
{
path: "index.js",
limit: "9 KB"
}
]
```

Each section in config could have options:

* **path**: relative paths to files. The only mandatory option.
Expand Down
2 changes: 1 addition & 1 deletion cli.js
Expand Up @@ -177,7 +177,7 @@ function getConfig () {
searchPlaces: [
'package.json',
'.size-limit',
'size-limit.config.js'
'.size-limit.js'
]
})
return explorer
Expand Down
11 changes: 11 additions & 0 deletions test/cli.test.js
Expand Up @@ -114,6 +114,17 @@ it('uses .size-limit file config', () => {
})
})

it('uses .size-limit.js file config', () => {
return run([], { cwd: fixture('js') }).then(result => {
expect(result.out).toEqual('\n' +
' Package size: 19 B\n' +
' Size limit: 1 KB\n' +
' With all dependencies, minified and gzipped\n' +
'\n')
expect(result.code).toEqual(0)
})
})

it('overrides config by limit argument', () => {
return run(['--limit', '18B'], { cwd: fixture('config') }).then(result => {
expect(result.out).toContain('Size limit: 18 B\n')
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/js/.size-limit.js
@@ -0,0 +1,6 @@
module.exports = [
{
path: "index.js",
limit: "1 KB"
}
]
3 changes: 3 additions & 0 deletions test/fixtures/js/index.js
@@ -0,0 +1,3 @@
'use strict'

console.log(2)

0 comments on commit e91dad8

Please sign in to comment.