-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #239
- Loading branch information
Showing
6 changed files
with
307 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from 'react'; | ||
import { graphql, useStaticQuery } from 'gatsby'; | ||
import { GatsbyImage, getImage } from 'gatsby-plugin-image'; | ||
|
||
const VariedDataPage = () => { | ||
const data = useStaticQuery(graphql` | ||
query { | ||
allVariedData { | ||
nodes { | ||
name | ||
expected | ||
gatsbyImageData( | ||
height: 200 | ||
backgroundColor: "#BADA55" | ||
logLevel: "error" | ||
) | ||
} | ||
} | ||
} | ||
`); | ||
|
||
return data.allVariedData.nodes.map((node, index) => { | ||
const gatsbyImage = getImage(node); | ||
|
||
return ( | ||
<> | ||
<h2>{node.name}</h2> | ||
<div> | ||
<strong>Expected:</strong> {node.expected} | ||
</div> | ||
{gatsbyImage ? ( | ||
<GatsbyImage key={index} image={gatsbyImage} alt={node.name} /> | ||
) : ( | ||
<div>No image for node with name: {node.name}</div> | ||
)} | ||
</> | ||
); | ||
}); | ||
}; | ||
|
||
export default VariedDataPage; |
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
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
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,25 @@ | ||
const LEVEL = { | ||
verbose: 0, | ||
info: 1, | ||
warn: 2, | ||
error: 3, | ||
panic: 4, | ||
panicOnBuild: 4, | ||
}; | ||
|
||
exports.resolverReporter = ({ reporter, logLevel }) => { | ||
const log = (level, message, ...rest) => { | ||
if (!logLevel || LEVEL[level] >= LEVEL[logLevel]) { | ||
reporter[level](message, ...rest); | ||
} | ||
}; | ||
|
||
return { | ||
verbose: (...args) => log('verbose', ...args), | ||
info: (...args) => log('info', ...args), | ||
warn: (...args) => log('warn', ...args), | ||
error: (...args) => log('error', ...args), | ||
panic: (...args) => log('panic', ...args), | ||
panicOnBuild: (...args) => log('panicOnBuild', ...args), | ||
}; | ||
}; |
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,143 @@ | ||
const { resolverReporter } = require('./resolver-reporter'); | ||
|
||
const gatsbyUtilsMocks = { | ||
reporter: { | ||
panicOnBuild: jest.fn(), | ||
panic: jest.fn(), | ||
error: jest.fn(), | ||
warn: jest.fn(), | ||
info: jest.fn(), | ||
verbose: jest.fn(), | ||
}, | ||
}; | ||
|
||
describe('resolverReporter', () => { | ||
it('reports only panic', () => { | ||
const reporter = resolverReporter({ | ||
reporter: gatsbyUtilsMocks.reporter, | ||
logLevel: 'panic', | ||
}); | ||
|
||
reporter.panicOnBuild('message'); | ||
reporter.panic('message'); | ||
reporter.error('message'); | ||
reporter.warn('message'); | ||
reporter.info('message'); | ||
reporter.verbose('message'); | ||
|
||
expect(gatsbyUtilsMocks.reporter.panic).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.panicOnBuild).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.error).toBeCalledTimes(0); | ||
expect(gatsbyUtilsMocks.reporter.warn).toBeCalledTimes(0); | ||
expect(gatsbyUtilsMocks.reporter.info).toBeCalledTimes(0); | ||
expect(gatsbyUtilsMocks.reporter.verbose).toBeCalledTimes(0); | ||
}); | ||
|
||
it('reports only errors and above', () => { | ||
const reporter = resolverReporter({ | ||
reporter: gatsbyUtilsMocks.reporter, | ||
logLevel: 'error', | ||
}); | ||
|
||
reporter.panicOnBuild('message'); | ||
reporter.panic('message'); | ||
reporter.error('message'); | ||
reporter.warn('message'); | ||
reporter.info('message'); | ||
reporter.verbose('message'); | ||
|
||
expect(gatsbyUtilsMocks.reporter.panic).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.panicOnBuild).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.error).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.warn).toBeCalledTimes(0); | ||
expect(gatsbyUtilsMocks.reporter.info).toBeCalledTimes(0); | ||
expect(gatsbyUtilsMocks.reporter.verbose).toBeCalledTimes(0); | ||
}); | ||
|
||
it('reports only warnings and above', () => { | ||
const reporter = resolverReporter({ | ||
reporter: gatsbyUtilsMocks.reporter, | ||
logLevel: 'warn', | ||
}); | ||
|
||
reporter.panicOnBuild('message'); | ||
reporter.panic('message'); | ||
reporter.error('message'); | ||
reporter.warn('message'); | ||
reporter.info('message'); | ||
reporter.verbose('message'); | ||
|
||
expect(gatsbyUtilsMocks.reporter.panic).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.panicOnBuild).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.error).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.warn).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.info).toBeCalledTimes(0); | ||
expect(gatsbyUtilsMocks.reporter.verbose).toBeCalledTimes(0); | ||
}); | ||
|
||
it('reports only info and above', () => { | ||
const reporter = resolverReporter({ | ||
reporter: gatsbyUtilsMocks.reporter, | ||
logLevel: 'info', | ||
}); | ||
|
||
reporter.panicOnBuild('message'); | ||
reporter.panic('message'); | ||
reporter.error('message'); | ||
reporter.warn('message'); | ||
reporter.info('message'); | ||
reporter.verbose('message'); | ||
|
||
expect(gatsbyUtilsMocks.reporter.panic).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.panicOnBuild).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.error).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.warn).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.info).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.verbose).toBeCalledTimes(0); | ||
}); | ||
|
||
describe('reports all', () => { | ||
it('when log level is verbose', () => { | ||
const reporter = resolverReporter({ | ||
reporter: gatsbyUtilsMocks.reporter, | ||
logLevel: 'verbose', | ||
}); | ||
|
||
reporter.panicOnBuild('message'); | ||
reporter.panic('message'); | ||
reporter.error('message'); | ||
reporter.warn('message'); | ||
reporter.info('message'); | ||
reporter.verbose('message'); | ||
|
||
expect(gatsbyUtilsMocks.reporter.panic).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.panic).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.panicOnBuild).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.error).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.warn).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.info).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.verbose).toBeCalledWith('message'); | ||
}); | ||
|
||
it('when log level is undefined', () => { | ||
const reporter = resolverReporter({ | ||
reporter: gatsbyUtilsMocks.reporter, | ||
}); | ||
|
||
reporter.panicOnBuild('message'); | ||
reporter.panic('message'); | ||
reporter.error('message'); | ||
reporter.warn('message'); | ||
reporter.info('message'); | ||
reporter.verbose('message'); | ||
|
||
expect(gatsbyUtilsMocks.reporter.panic).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.panic).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.panicOnBuild).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.error).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.warn).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.info).toBeCalledWith('message'); | ||
expect(gatsbyUtilsMocks.reporter.verbose).toBeCalledWith('message'); | ||
}); | ||
}); | ||
}); |
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