Skip to content

Commit bde7394

Browse files
author
LB
authored
Address todos for major release (#29413)
* Address todos for major release * fix tests * remove default test since we've removed defaults * another trackingId test fix * changed the wrong test * remove obsolete snapshot * undo * remove obsolete test, the right one this time * add warn * no comment
1 parent 478cf68 commit bde7394

File tree

6 files changed

+40
-68
lines changed

6 files changed

+40
-68
lines changed

packages/babel-preset-gatsby/src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ export function loadCachedConfig() {
3232
export default function preset(_, options = {}) {
3333
let { targets = null } = options
3434

35-
// TODO(v3): Remove process.env.GATSBY_BUILD_STAGE, needs to be passed as an option
36-
const stage = options.stage || process.env.GATSBY_BUILD_STAGE || `test`
35+
const stage = options.stage || `test`
3736
const pluginBabelConfig = loadCachedConfig()
3837
let isBrowser
3938
// unused because of cloud builds

packages/gatsby-plugin-feed/src/__tests__/__snapshots__/gatsby-node.js.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ exports[`Test plugin feed custom properties work properly 1`] = `"<?xml version=
44
55
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[my feed]]></title><description><![CDATA[a description]]></description><link>http://github.com/dylang/node-rss</link><generator>GatsbyJS</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>"`;
66
7-
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>GatsbyJS</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>"`;

packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,6 @@ describe(`Test plugin feed`, () => {
1515
fs.mkdirp = jest.fn().mockResolvedValue()
1616
})
1717

18-
it(`default settings work properly`, async () => {
19-
fs.writeFile = jest.fn()
20-
fs.writeFile.mockResolvedValue(true)
21-
const graphql = jest.fn()
22-
graphql.mockResolvedValue({
23-
data: {
24-
site: {
25-
siteMetadata: {
26-
title: `a sample title`,
27-
description: `a description`,
28-
siteUrl: `http://dummy.url/`,
29-
},
30-
},
31-
allMarkdownRemark: {
32-
edges: [
33-
{
34-
node: {
35-
fields: {
36-
slug: `a-slug`,
37-
},
38-
excerpt: `post description`,
39-
},
40-
},
41-
],
42-
},
43-
},
44-
})
45-
await onPostBuild({ graphql }, {})
46-
const [filePath, contents] = fs.writeFile.mock.calls[0]
47-
expect(filePath).toEqual(path.join(`public`, `rss.xml`))
48-
expect(contents).toMatchSnapshot()
49-
})
50-
5118
it(`custom properties work properly`, async () => {
5219
fs.writeFile = jest.fn()
5320
fs.writeFile.mockResolvedValue(true)
@@ -243,6 +210,12 @@ describe(`Test plugin feed`, () => {
243210
{
244211
output: `rss.xml`,
245212
query: `{ firstMarkdownQuery }`,
213+
serialize: ({ query: { allMarkdownRemark } }) =>
214+
allMarkdownRemark.edges.map(edge => {
215+
return {
216+
...edge.node.frontmatter,
217+
}
218+
}),
246219
},
247220
],
248221
}

packages/gatsby-plugin-feed/src/gatsby-node.js

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,7 @@ const publicPath = `./public`
1010

1111
exports.pluginOptionsSchema = pluginOptionsSchema
1212

13-
// TODO: remove in the next major release
14-
// A default function to transform query data into feed entries.
15-
const serialize = ({ query: { site, allMarkdownRemark } }) =>
16-
allMarkdownRemark.edges.map(edge => {
17-
return {
18-
...edge.node.frontmatter,
19-
description: edge.node.excerpt,
20-
url: site.siteMetadata.siteUrl + edge.node.fields.slug,
21-
guid: site.siteMetadata.siteUrl + edge.node.fields.slug,
22-
custom_elements: [{ "content:encoded": edge.node.html }],
23-
}
24-
})
25-
26-
exports.onPostBuild = async ({ graphql }, pluginOptions) => {
13+
exports.onPostBuild = async ({ graphql, reporter }, pluginOptions) => {
2714
/*
2815
* Run the site settings query to gather context, then
2916
* then run the corresponding feed for each query.
@@ -47,21 +34,22 @@ exports.onPostBuild = async ({ graphql }, pluginOptions) => {
4734
...feed,
4835
}
4936

50-
const serializer =
51-
feed.serialize && typeof feed.serialize === `function`
52-
? feed.serialize
53-
: serialize
54-
55-
const rssFeed = (await serializer(locals)).reduce((merged, item) => {
56-
merged.item(item)
57-
return merged
58-
}, new RSS(setup(locals)))
59-
60-
const outputPath = path.join(publicPath, feed.output)
61-
const outputDir = path.dirname(outputPath)
62-
if (!(await fs.exists(outputDir))) {
63-
await fs.mkdirp(outputDir)
37+
if (!feed.serialize || typeof feed.serialize !== `function`) {
38+
reporter.warn(
39+
`You did not pass in a valid serialize function. Your feed will not be generated.`
40+
)
41+
} else {
42+
const rssFeed = (await feed.serialize(locals)).reduce((merged, item) => {
43+
merged.item(item)
44+
return merged
45+
}, new RSS(setup(locals)))
46+
47+
const outputPath = path.join(publicPath, feed.output)
48+
const outputDir = path.dirname(outputPath)
49+
if (!(await fs.exists(outputDir))) {
50+
await fs.mkdirp(outputDir)
51+
}
52+
await fs.writeFile(outputPath, rssFeed.xml())
6453
}
65-
await fs.writeFile(outputPath, rssFeed.xml())
6654
}
6755
}

packages/gatsby-plugin-google-analytics/src/gatsby-node.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
exports.pluginOptionsSchema = ({ Joi }) =>
22
// TODO: make sure that trackingId gets required() when releasing a major version
33
Joi.object({
4-
trackingId: Joi.string().description(
5-
`The property ID; the tracking code won't be generated without it`
6-
),
4+
trackingId: Joi.string()
5+
.description(
6+
`The property ID; the tracking code won't be generated without it`
7+
)
8+
.required(),
79
head: Joi.boolean()
810
.default(false)
911
.description(

packages/gatsby/src/bootstrap/load-plugins/__tests__/load-plugins.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,17 @@ describe(`Load plugins`, () => {
267267
"configDir": null,
268268
"pluginName": "gatsby-plugin-google-analytics",
269269
"validationErrors": Array [
270+
Object {
271+
"context": Object {
272+
"key": "trackingId",
273+
"label": "trackingId",
274+
},
275+
"message": "\\"trackingId\\" is required",
276+
"path": Array [
277+
"trackingId",
278+
],
279+
"type": "any.required",
280+
},
270281
Object {
271282
"context": Object {
272283
"key": "anonymize",

0 commit comments

Comments
 (0)