-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Improve coverage #8580
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
Merged
Merged
Improve coverage #8580
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9c809f4
Add tests for hash function
oorestisime 024e88e
Add tests for gatsby-plugin-remove-trailing-slashes
oorestisime 01df0e2
Add tests for plugin feed
oorestisime c87b2b5
Update coverage threshold
oorestisime 263f609
Fix trailing comma eslint warning
oorestisime f047a3a
Add a snapshot to verify graphql was called with custom query
oorestisime File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
84 changes: 84 additions & 0 deletions
84
packages/gatsby-plugin-feed/src/__tests__/__snapshots__/gatsby-node.js.snap
This file contains hidden or 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,84 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Test plugin feed custom query runs 1`] = ` | ||
[MockFunction] { | ||
"calls": Array [ | ||
Array [ | ||
"public/rss_new.xml", | ||
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><rss xmlns:dc=\\"http://purl.org/dc/elements/1.1/\\" xmlns:content=\\"http://purl.org/rss/1.0/modules/content/\\" xmlns:atom=\\"http://www.w3.org/2005/Atom\\" version=\\"2.0\\"><channel><title><![CDATA[a sample title]]></title><description><![CDATA[a description]]></description><link>http://github.com/dylang/node-rss</link><generator>RSS for Node</generator><lastBuildDate>Mon, 01 Jan 2018 00:00:00 GMT</lastBuildDate><item><title><![CDATA[No title]]></title><description><![CDATA[post description]]></description><link>http://dummy.url/a-custom-path</link><guid isPermaLink=\\"true\\">http://dummy.url/a-custom-path</guid></item><item><title><![CDATA[No title]]></title><description><![CDATA[post description]]></description><link>http://dummy.url/another-custom-path</link><guid isPermaLink=\\"true\\">http://dummy.url/another-custom-path</guid></item></channel></rss>", | ||
], | ||
], | ||
"results": Array [ | ||
Object { | ||
"isThrow": false, | ||
"value": Promise {}, | ||
}, | ||
], | ||
} | ||
`; | ||
|
||
exports[`Test plugin feed custom query runs 2`] = ` | ||
[MockFunction] { | ||
"calls": Array [ | ||
Array [ | ||
" | ||
{ | ||
site { | ||
siteMetadata { | ||
title | ||
description | ||
siteUrl | ||
site_url: siteUrl | ||
} | ||
} | ||
} | ||
", | ||
], | ||
Array [ | ||
" | ||
{ | ||
allMarkdownRemark( | ||
limit: 1000, | ||
) { | ||
edges { | ||
node { | ||
frontmatter { | ||
path | ||
} | ||
excerpt | ||
} | ||
} | ||
} | ||
} | ||
", | ||
], | ||
], | ||
"results": Array [ | ||
Object { | ||
"isThrow": false, | ||
"value": Promise {}, | ||
}, | ||
Object { | ||
"isThrow": false, | ||
"value": Promise {}, | ||
}, | ||
], | ||
} | ||
`; | ||
|
||
exports[`Test plugin feed default settings work properly 1`] = ` | ||
[MockFunction] { | ||
"calls": Array [ | ||
Array [ | ||
"public/rss.xml", | ||
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><rss xmlns:dc=\\"http://purl.org/dc/elements/1.1/\\" xmlns:content=\\"http://purl.org/rss/1.0/modules/content/\\" xmlns:atom=\\"http://www.w3.org/2005/Atom\\" version=\\"2.0\\"><channel><title><![CDATA[a sample title]]></title><description><![CDATA[a description]]></description><link>http://github.com/dylang/node-rss</link><generator>RSS for Node</generator><lastBuildDate>Mon, 01 Jan 2018 00:00:00 GMT</lastBuildDate><item><title><![CDATA[No title]]></title><description><![CDATA[post description]]></description><link>http://dummy.url/a-slug</link><guid isPermaLink=\\"false\\">http://dummy.url/a-slug</guid><content:encoded></content:encoded></item></channel></rss>", | ||
], | ||
], | ||
"results": Array [ | ||
Object { | ||
"isThrow": false, | ||
"value": Promise {}, | ||
}, | ||
], | ||
} | ||
`; |
110 changes: 110 additions & 0 deletions
110
packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js
This file contains hidden or 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,110 @@ | ||
const fs = require(`fs`) | ||
const { onPostBuild } = require(`../gatsby-node`) | ||
const internals = require(`../internals`) | ||
jest.mock(`fs`) | ||
const DATE_TO_USE = new Date(`2018`) | ||
const _Date = Date | ||
global.Date = jest.fn(() => DATE_TO_USE) | ||
global.Date.UTC = _Date.UTC | ||
global.Date.now = _Date.now | ||
|
||
|
||
describe(`Test plugin feed`, async () => { | ||
fs.existsSync = jest.fn() | ||
fs.existsSync.mockReturnValue(true) | ||
|
||
it(`default settings work properly`, async () => { | ||
internals.writeFile = jest.fn() | ||
internals.writeFile.mockResolvedValue(true) | ||
const graphql = jest.fn() | ||
graphql.mockResolvedValue({ data: { | ||
site : { | ||
siteMetadata: { | ||
title: `a sample title`, | ||
description: `a description`, | ||
siteUrl: `http://dummy.url/`, | ||
}, | ||
}, | ||
allMarkdownRemark: { | ||
edges: [ | ||
{ node: { | ||
fields: { | ||
slug: `a-slug`, | ||
}, | ||
excerpt: `post description`, | ||
} }, | ||
], | ||
}, | ||
} }) | ||
await onPostBuild({ graphql }, {}) | ||
expect(internals.writeFile).toMatchSnapshot() | ||
}) | ||
|
||
it(`custom query runs`, async () => { | ||
internals.writeFile = jest.fn() | ||
internals.writeFile.mockResolvedValue(true) | ||
const graphql = jest.fn() | ||
graphql.mockResolvedValue({ data: { | ||
site : { | ||
siteMetadata: { | ||
title: `a sample title`, | ||
description: `a description`, | ||
siteUrl: `http://dummy.url/`, | ||
}, | ||
}, | ||
allMarkdownRemark: { | ||
edges: [ | ||
{ | ||
node: { | ||
frontmatter: { | ||
path: `a-custom-path`, | ||
}, | ||
excerpt: `post description`, | ||
}, | ||
}, | ||
{ | ||
node: { | ||
frontmatter: { | ||
path: `another-custom-path`, | ||
}, | ||
excerpt: `post description`, | ||
}, | ||
}, | ||
], | ||
}, | ||
} }) | ||
const options = { | ||
feeds: [ | ||
{ | ||
output: `rss_new.xml`, | ||
serialize: ({ query: { site, allMarkdownRemark } }) => | ||
allMarkdownRemark.edges.map(edge => { | ||
return { | ||
...edge.node.frontmatter, | ||
description: edge.node.excerpt, | ||
url: site.siteMetadata.siteUrl + edge.node.frontmatter.path, | ||
} | ||
}), | ||
query: ` | ||
{ | ||
allMarkdownRemark( | ||
limit: 1000, | ||
) { | ||
edges { | ||
node { | ||
frontmatter { | ||
path | ||
} | ||
excerpt | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
}], | ||
} | ||
await onPostBuild({ graphql }, options) | ||
expect(internals.writeFile).toMatchSnapshot() | ||
expect(graphql).toMatchSnapshot() | ||
}) | ||
}) |
This file contains hidden or 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
20 changes: 20 additions & 0 deletions
20
packages/gatsby-plugin-remove-trailing-slashes/src/__tests__/gatsby-node.js
This file contains hidden or 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,20 @@ | ||
const { onCreatePage } = require(`../gatsby-node`) | ||
|
||
describe(`gatsby-plugin-remove-trailing-slashes`, () => { | ||
const actions = { | ||
createPage: jest.fn(), | ||
deletePage: jest.fn(), | ||
} | ||
|
||
it(`correctly keeps index /`, () => { | ||
onCreatePage({ actions, page: { page: `/` } }) | ||
expect(actions.createPage).not.toBeCalled() | ||
expect(actions.deletePage).not.toBeCalled() | ||
}) | ||
|
||
it(`correctly removes slash and recreated page`, () => { | ||
onCreatePage({ actions, page: { path: `/home/` } }) | ||
expect(actions.deletePage).toBeCalledWith({ path: `/home/` }) | ||
expect(actions.createPage).toBeCalledWith({ path: `/home` }) | ||
}) | ||
}) |
5 changes: 5 additions & 0 deletions
5
packages/gatsby/src/utils/__tests__/__snapshots__/get-hash-fn.js.snap
This file contains hidden or 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,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Test hashing function default parameters 1`] = `174577032270956`; | ||
|
||
exports[`Test hashing function guards against collisions 1`] = `[Error: Hash collision at f(my input) = 174577032270956]`; |
This file contains hidden or 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,16 @@ | ||
const getHashFn = require(`../get-hash-fn`) | ||
|
||
describe(`Test hashing function`, () => { | ||
it(`default parameters`, () => { | ||
const hash = getHashFn({})(`my input`) | ||
expect(hash).toMatchSnapshot() | ||
}) | ||
it(`guards against collisions`, () => { | ||
const hash = getHashFn({})(`my input`) | ||
try { | ||
getHashFn({ cache: new Set([hash]) })(`my input`) | ||
} catch(err) { | ||
expect(err).toMatchSnapshot() | ||
} | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.