forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add option to configure default image quality
Fixes gatsbyjs#4873
- Loading branch information
Showing
3 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/gatsby-transformer-sharp/src/__tests__/extend-node-type.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const extendNodeType = require(`../extend-node-type`) | ||
const { __DEFAULT_QUALITY__ } = extendNodeType | ||
|
||
const getOptions = (options = {}) => {return { | ||
type: { | ||
name: `ImageSharp`, | ||
}, | ||
pathPrefix: `/`, | ||
getNodeAndSavePathDependency: jest.fn(), | ||
reporter: jest.fn(), | ||
...options, | ||
}} | ||
|
||
describe(`basic functionality`, () => { | ||
it(`returns empty object if not ImageSharp type`, () => { | ||
const options = getOptions({ type: `MarkdownRemark` }) | ||
|
||
expect(extendNodeType(options)).toEqual({}) | ||
}) | ||
|
||
it(`returns expected image operations`, () => { | ||
const expected = [`fixed`, `resolutions`, `fluid`, `sizes`, `original`, `resize`] | ||
.reduce((merged, key) => { | ||
merged[key] = expect.any(Object) | ||
return merged | ||
}, {}) | ||
|
||
expect(extendNodeType(getOptions())).toEqual(expected) | ||
}) | ||
}) | ||
|
||
describe(`quality`, () => { | ||
const options = getOptions() | ||
|
||
it(`uses fallback quality if not passed`, () => { | ||
const node = extendNodeType(options); | ||
|
||
[node.fixed, node.fluid] | ||
.forEach(type => { | ||
expect(type.args.quality.defaultValue).toBe(__DEFAULT_QUALITY__) | ||
}) | ||
}) | ||
|
||
it(`allows for configuration of quality`, () => { | ||
const defaultQuality = 100 | ||
const node = extendNodeType(options, { defaultQuality }); | ||
|
||
[node.fixed, node.fluid] | ||
.forEach(type => { | ||
expect(type.args.quality.defaultValue).toBe(defaultQuality) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters