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

test(gatsby-plugin-feed): don't snapshot test platform specific #8836

Merged
merged 2 commits into from
Oct 8, 2018
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
Original file line number Diff line number Diff line change
@@ -1,84 +1,5 @@
// 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 1`] = `"<?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>"`;

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 {},
},
],
}
`;
exports[`Test plugin feed default settings work properly 1`] = `"<?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>"`;
134 changes: 73 additions & 61 deletions packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require(`fs`)
const path = require(`path`)
const { onPostBuild } = require(`../gatsby-node`)
const internals = require(`../internals`)
jest.mock(`fs`)
Expand All @@ -8,7 +9,6 @@ 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)
Expand All @@ -17,62 +17,86 @@ describe(`Test plugin feed`, 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/`,
graphql.mockResolvedValue({
data: {
site: {
siteMetadata: {
title: `a sample title`,
description: `a description`,
siteUrl: `http://dummy.url/`,
},
},
},
allMarkdownRemark: {
edges: [
{ node: {
fields: {
slug: `a-slug`,
allMarkdownRemark: {
edges: [
{
node: {
fields: {
slug: `a-slug`,
},
excerpt: `post description`,
},
},
excerpt: `post description`,
} },
],
],
},
},
} })
})
await onPostBuild({ graphql }, {})
expect(internals.writeFile).toMatchSnapshot()
const [filePath, contents] = internals.writeFile.mock.calls[0]
expect(filePath).toEqual(path.join(`public`, `rss.xml`))
expect(contents).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/`,
graphql.mockResolvedValue({
data: {
site: {
siteMetadata: {
title: `a sample title`,
description: `a description`,
siteUrl: `http://dummy.url/`,
},
},
},
allMarkdownRemark: {
edges: [
{
node: {
frontmatter: {
path: `a-custom-path`,
allMarkdownRemark: {
edges: [
{
node: {
frontmatter: {
path: `a-custom-path`,
},
excerpt: `post description`,
},
excerpt: `post description`,
},
},
{
node: {
frontmatter: {
path: `another-custom-path`,
{
node: {
frontmatter: {
path: `another-custom-path`,
},
excerpt: `post description`,
},
excerpt: `post description`,
},
},
],
],
},
},
} })
})
const customQuery = `
{
allMarkdownRemark(
limit: 1000,
) {
edges {
node {
frontmatter {
path
}
excerpt
}
}
}
}
`
const options = {
feeds: [
{
Expand All @@ -84,27 +108,15 @@ describe(`Test plugin feed`, async () => {
description: edge.node.excerpt,
url: site.siteMetadata.siteUrl + edge.node.frontmatter.path,
}
}),
query: `
{
allMarkdownRemark(
limit: 1000,
) {
edges {
node {
frontmatter {
path
}
excerpt
}
}
}
}
`,
}],
}),
query: customQuery,
},
],
}
await onPostBuild({ graphql }, options)
expect(internals.writeFile).toMatchSnapshot()
expect(graphql).toMatchSnapshot()
const [filePath, contents] = internals.writeFile.mock.calls[0]
expect(filePath).toEqual(path.join(`public`, `rss_new.xml`))
expect(contents).toMatchSnapshot()
expect(graphql).toBeCalledWith(customQuery)
})
})