Skip to content

Commit 4712acc

Browse files
piehwardpeetvladar
authoredSep 14, 2021
test: adjust tests after the bump (#33171)
* just checking * test failures * fix joi.subPlugins in gatsby-plugin-utils plugin options schema tester * Revert "just checking" This reverts commit 4d7a20c. * drop unused arg * add missing dev dep * fix build-utils pages mock * test(data-tracking): mock readFileSync * test(redux/index): mock readFileSync * test(babel-preset-gatsby-package): update snapshot * test(redirects-writer): mock readFileSync * test(gen-mdx): set module on subplugin entry * test(create-pages): add readFileSync mock * fix split tests * test(requires-writer): set default mode on pages * test(get-page-data): set default mode on pages * fix src/redux/__tests__/pages.ts * test(api): update snapshot * test(remark/extend-node-type): add module fields to mocked subplugins in plugin options * fix circle Co-authored-by: Ward Peeters <ward@coding-tech.com> Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>
1 parent b622b22 commit 4712acc

File tree

20 files changed

+126
-46
lines changed

20 files changed

+126
-46
lines changed
 

‎.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ aliases:
8383
yarn why lmdb-store
8484
- run:
8585
name: Run tests
86-
command: yarn jest --ci --runInBand $(yarn jest --listTests | sed 's/\/root\/project//g' | circleci tests split --split-by=timings)
86+
command: yarn jest --ci --runInBand $(yarn -s jest --listTests | sed 's/\/home\/circleci\/project\///g' | circleci tests split)
8787
environment:
8888
NODE_OPTIONS: --max-old-space-size=2048
8989
GENERATE_JEST_REPORT: true

‎packages/babel-preset-gatsby-package/lib/__tests__/__snapshots__/index.js.snap

+9-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ Array [
9090
"availableFlags": Array [
9191
"GATSBY_MAJOR",
9292
],
93-
"flags": Object {},
93+
"flags": Object {
94+
"GATSBY_MAJOR": "4",
95+
},
9496
},
9597
],
9698
]
@@ -109,7 +111,9 @@ Array [
109111
"availableFlags": Array [
110112
"MAJOR",
111113
],
112-
"flags": Object {},
114+
"flags": Object {
115+
"GATSBY_MAJOR": "4",
116+
},
113117
},
114118
],
115119
]
@@ -176,7 +180,9 @@ Array [
176180
"availableFlags": Array [
177181
"GATSBY_MAJOR",
178182
],
179-
"flags": Object {},
183+
"flags": Object {
184+
"GATSBY_MAJOR": "4",
185+
},
180186
},
181187
],
182188
]

‎packages/babel-preset-gatsby-package/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"@babel/core": "^7.15.5",
2727
"@babel/helper-plugin-test-runner": "7.14.5",
2828
"@babel/plugin-transform-modules-commonjs": "^7.15.4",
29-
"@types/babel__core": "^7.1.15"
29+
"@types/babel__core": "^7.1.15",
30+
"cross-env": "^7.0.3"
3031
},
3132
"peerDependencies": {
3233
"@babel/core": "^7.11.6"

‎packages/gatsby-cli/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if (os.platform() === `win32`) {
2323
// Check if update is available
2424
updateNotifier({ pkg }).notify({ isGlobal: true })
2525

26-
const MIN_NODE_VERSION = `12.13.0`
26+
const MIN_NODE_VERSION = `14.15.0`
2727
// const NEXT_MIN_NODE_VERSION = `10.13.0`
2828

2929
const { version } = process

‎packages/gatsby-plugin-mdx/__tests__/gatsby-node.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ describe(`pluginOptionsSchema`, () => {
88
`"extensions[1]" must be a string`,
99
`"extensions[2]" must be a string`,
1010
`"defaultLayouts" must be of type object`,
11-
`"gatsbyRemarkPlugins[0]" does not match any of the allowed types`,
12-
`"gatsbyRemarkPlugins[1]" does not match any of the allowed types`,
11+
`"gatsbyRemarkPlugins[0]" must be one of [string, object]`,
12+
`"gatsbyRemarkPlugins[1].not" is not allowed`,
1313
`"remarkPlugins" must be an array`,
1414
`"rehypePlugins" must be an array`,
1515
`"plugins[0]" does not match any of the allowed types`,

‎packages/gatsby-plugin-mdx/utils/__tests__/gen-mdx.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ console.log('hello world')
1616

1717
describe(`find imports`, () => {
1818
it(`allows injecting imports via plugins`, async () => {
19+
const testPluginModulePath = path.join(__dirname, `fixtures`, `test-plugin`)
1920
const results = await findImports({
2021
node: {
2122
id: `bbffffbb-bfff-bfff-bfff-dededededede`,
@@ -37,7 +38,10 @@ describe(`find imports`, () => {
3738
options: {
3839
remarkPlugins: [],
3940
gatsbyRemarkPlugins: [
40-
{ resolve: path.join(__dirname, `fixtures`, `test-plugin`) },
41+
{
42+
resolve: testPluginModulePath,
43+
module: require(testPluginModulePath),
44+
},
4145
],
4246
},
4347
getNode: () => null,

‎packages/gatsby-plugin-utils/src/test-plugin-options-schema.ts

+29-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,35 @@ export async function testPluginOptionsSchema(
1212
pluginSchemaFunction: Exclude<GatsbyNode["pluginOptionsSchema"], undefined>,
1313
pluginOptions: IPluginInfoOptions
1414
): Promise<ITestPluginOptionsSchemaReturnType> {
15-
const pluginSchema = pluginSchemaFunction({ Joi })
15+
const pluginSchema = pluginSchemaFunction({
16+
Joi: Joi.extend(joi => {
17+
return {
18+
base: joi.any(),
19+
type: `subPlugins`,
20+
args: (): any =>
21+
joi
22+
.array()
23+
.items(
24+
joi
25+
.alternatives(
26+
joi.string(),
27+
joi.object({
28+
resolve: Joi.string(),
29+
options: Joi.object({}).unknown(true),
30+
})
31+
)
32+
.custom(value => {
33+
if (typeof value === `string`) {
34+
value = { resolve: value }
35+
}
36+
37+
return value
38+
}, `Gatsby specific subplugin validation`)
39+
)
40+
.default([]),
41+
}
42+
}),
43+
})
1644

1745
try {
1846
await validateOptionsSchema(pluginSchema, pluginOptions)

‎packages/gatsby-transformer-remark/src/__tests__/extend-node.js

+2
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,7 @@ It's easier than you may imagine`,
11431143
showLineNumbers: false,
11441144
noInlineHighlight: false,
11451145
},
1146+
module: require(`gatsby-remark-prismjs`),
11461147
},
11471148
],
11481149
},
@@ -1335,6 +1336,7 @@ describe(`Headings are generated correctly from schema`, () => {
13351336
{
13361337
resolve: require.resolve(`gatsby-remark-autolink-headers/src`),
13371338
pluginOptions: {},
1339+
module: require(`gatsby-remark-autolink-headers/src`),
13381340
},
13391341
],
13401342
},

‎packages/gatsby/scripts/__tests__/api.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ it("generates the expected api output", done => {
4444
"onCreateNode": Object {},
4545
"onCreatePage": Object {},
4646
"onCreateWebpackConfig": Object {},
47+
"onPluginInit": Object {
48+
"version": "3.9.0",
49+
},
4750
"onPostBootstrap": Object {},
4851
"onPostBuild": Object {},
4952
"onPreBootstrap": Object {},
@@ -57,9 +60,6 @@ it("generates the expected api output", done => {
5760
"resolvableExtensions": Object {},
5861
"setFieldsOnGraphQLNodeType": Object {},
5962
"sourceNodes": Object {},
60-
"onPluginInit": Object {
61-
"version": "3.9.0",
62-
},
6363
"unstable_shouldOnCreateNode": Object {
6464
"version": "2.24.80",
6565
},

‎packages/gatsby/src/bootstrap/__tests__/redirects-writer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { store } from "../../redux"
55
import { actions } from "../../redux/actions"
66

77
jest.mock(`fs-extra`, () => {
8-
return { writeFile: jest.fn() }
8+
return { writeFile: jest.fn(), readFileSync: jest.fn(() => `foo`) }
99
})
1010

1111
jest.mock(`gatsby-cli/lib/reporter`, () => {

‎packages/gatsby/src/bootstrap/__tests__/requires-writer.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const generatePagesState = pages => {
1010
state.set(page.path, {
1111
component: ``,
1212
componentChunkName: ``,
13+
mode: `SSG`,
1314
...page,
1415
})
1516
})

‎packages/gatsby/src/bootstrap/load-plugins/__tests__/__snapshots__/load-plugins.ts.snap

+27-27
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Array [
110110
"nodeAPIs": Array [
111111
"createPagesStatefully",
112112
"setFieldsOnGraphQLNodeType",
113-
"unstable_onPluginInit",
113+
"onPluginInit",
114114
],
115115
"pluginOptions": Object {
116116
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/dev-404-page/src/pages",
@@ -131,7 +131,7 @@ Array [
131131
"nodeAPIs": Array [
132132
"createPagesStatefully",
133133
"setFieldsOnGraphQLNodeType",
134-
"unstable_onPluginInit",
134+
"onPluginInit",
135135
],
136136
"pluginOptions": Object {
137137
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/load-babel-config/src/pages",
@@ -152,7 +152,7 @@ Array [
152152
"nodeAPIs": Array [
153153
"createPagesStatefully",
154154
"setFieldsOnGraphQLNodeType",
155-
"unstable_onPluginInit",
155+
"onPluginInit",
156156
],
157157
"pluginOptions": Object {
158158
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/internal-data-bridge/src/pages",
@@ -173,7 +173,7 @@ Array [
173173
"nodeAPIs": Array [
174174
"createPagesStatefully",
175175
"setFieldsOnGraphQLNodeType",
176-
"unstable_onPluginInit",
176+
"onPluginInit",
177177
],
178178
"pluginOptions": Object {
179179
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/prod-404/src/pages",
@@ -194,7 +194,7 @@ Array [
194194
"nodeAPIs": Array [
195195
"createPagesStatefully",
196196
"setFieldsOnGraphQLNodeType",
197-
"unstable_onPluginInit",
197+
"onPluginInit",
198198
],
199199
"pluginOptions": Object {
200200
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/webpack-theme-component-shadowing/src/pages",
@@ -215,7 +215,7 @@ Array [
215215
"nodeAPIs": Array [
216216
"createPagesStatefully",
217217
"setFieldsOnGraphQLNodeType",
218-
"unstable_onPluginInit",
218+
"onPluginInit",
219219
],
220220
"pluginOptions": Object {
221221
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/bundle-optimisations/src/pages",
@@ -236,7 +236,7 @@ Array [
236236
"nodeAPIs": Array [
237237
"createPagesStatefully",
238238
"setFieldsOnGraphQLNodeType",
239-
"unstable_onPluginInit",
239+
"onPluginInit",
240240
],
241241
"pluginOptions": Object {
242242
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/functions/src/pages",
@@ -292,7 +292,7 @@ Array [
292292
"nodeAPIs": Array [
293293
"createPagesStatefully",
294294
"setFieldsOnGraphQLNodeType",
295-
"unstable_onPluginInit",
295+
"onPluginInit",
296296
],
297297
"pluginOptions": Object {
298298
"path": "/src/pages",
@@ -429,7 +429,7 @@ Array [
429429
"nodeAPIs": Array [
430430
"createPagesStatefully",
431431
"setFieldsOnGraphQLNodeType",
432-
"unstable_onPluginInit",
432+
"onPluginInit",
433433
],
434434
"pluginOptions": Object {
435435
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/dev-404-page/src/pages",
@@ -450,7 +450,7 @@ Array [
450450
"nodeAPIs": Array [
451451
"createPagesStatefully",
452452
"setFieldsOnGraphQLNodeType",
453-
"unstable_onPluginInit",
453+
"onPluginInit",
454454
],
455455
"pluginOptions": Object {
456456
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/load-babel-config/src/pages",
@@ -471,7 +471,7 @@ Array [
471471
"nodeAPIs": Array [
472472
"createPagesStatefully",
473473
"setFieldsOnGraphQLNodeType",
474-
"unstable_onPluginInit",
474+
"onPluginInit",
475475
],
476476
"pluginOptions": Object {
477477
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/internal-data-bridge/src/pages",
@@ -492,7 +492,7 @@ Array [
492492
"nodeAPIs": Array [
493493
"createPagesStatefully",
494494
"setFieldsOnGraphQLNodeType",
495-
"unstable_onPluginInit",
495+
"onPluginInit",
496496
],
497497
"pluginOptions": Object {
498498
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/prod-404/src/pages",
@@ -513,7 +513,7 @@ Array [
513513
"nodeAPIs": Array [
514514
"createPagesStatefully",
515515
"setFieldsOnGraphQLNodeType",
516-
"unstable_onPluginInit",
516+
"onPluginInit",
517517
],
518518
"pluginOptions": Object {
519519
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/webpack-theme-component-shadowing/src/pages",
@@ -534,7 +534,7 @@ Array [
534534
"nodeAPIs": Array [
535535
"createPagesStatefully",
536536
"setFieldsOnGraphQLNodeType",
537-
"unstable_onPluginInit",
537+
"onPluginInit",
538538
],
539539
"pluginOptions": Object {
540540
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/bundle-optimisations/src/pages",
@@ -555,7 +555,7 @@ Array [
555555
"nodeAPIs": Array [
556556
"createPagesStatefully",
557557
"setFieldsOnGraphQLNodeType",
558-
"unstable_onPluginInit",
558+
"onPluginInit",
559559
],
560560
"pluginOptions": Object {
561561
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/functions/src/pages",
@@ -576,7 +576,7 @@ Array [
576576
"nodeAPIs": Array [
577577
"createPagesStatefully",
578578
"setFieldsOnGraphQLNodeType",
579-
"unstable_onPluginInit",
579+
"onPluginInit",
580580
],
581581
"pluginOptions": Object {
582582
"path": "__TEST__/src/pages",
@@ -632,7 +632,7 @@ Array [
632632
"nodeAPIs": Array [
633633
"createPagesStatefully",
634634
"setFieldsOnGraphQLNodeType",
635-
"unstable_onPluginInit",
635+
"onPluginInit",
636636
],
637637
"pluginOptions": Object {
638638
"path": "/src/pages",
@@ -757,7 +757,7 @@ Array [
757757
"nodeAPIs": Array [
758758
"createPagesStatefully",
759759
"setFieldsOnGraphQLNodeType",
760-
"unstable_onPluginInit",
760+
"onPluginInit",
761761
],
762762
"pluginOptions": Object {
763763
"ignore": Array [
@@ -780,7 +780,7 @@ Array [
780780
"nodeAPIs": Array [
781781
"createPagesStatefully",
782782
"setFieldsOnGraphQLNodeType",
783-
"unstable_onPluginInit",
783+
"onPluginInit",
784784
],
785785
"pluginOptions": Object {
786786
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/dev-404-page/src/pages",
@@ -801,7 +801,7 @@ Array [
801801
"nodeAPIs": Array [
802802
"createPagesStatefully",
803803
"setFieldsOnGraphQLNodeType",
804-
"unstable_onPluginInit",
804+
"onPluginInit",
805805
],
806806
"pluginOptions": Object {
807807
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/load-babel-config/src/pages",
@@ -822,7 +822,7 @@ Array [
822822
"nodeAPIs": Array [
823823
"createPagesStatefully",
824824
"setFieldsOnGraphQLNodeType",
825-
"unstable_onPluginInit",
825+
"onPluginInit",
826826
],
827827
"pluginOptions": Object {
828828
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/internal-data-bridge/src/pages",
@@ -843,7 +843,7 @@ Array [
843843
"nodeAPIs": Array [
844844
"createPagesStatefully",
845845
"setFieldsOnGraphQLNodeType",
846-
"unstable_onPluginInit",
846+
"onPluginInit",
847847
],
848848
"pluginOptions": Object {
849849
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/prod-404/src/pages",
@@ -864,7 +864,7 @@ Array [
864864
"nodeAPIs": Array [
865865
"createPagesStatefully",
866866
"setFieldsOnGraphQLNodeType",
867-
"unstable_onPluginInit",
867+
"onPluginInit",
868868
],
869869
"pluginOptions": Object {
870870
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/webpack-theme-component-shadowing/src/pages",
@@ -885,7 +885,7 @@ Array [
885885
"nodeAPIs": Array [
886886
"createPagesStatefully",
887887
"setFieldsOnGraphQLNodeType",
888-
"unstable_onPluginInit",
888+
"onPluginInit",
889889
],
890890
"pluginOptions": Object {
891891
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/bundle-optimisations/src/pages",
@@ -906,7 +906,7 @@ Array [
906906
"nodeAPIs": Array [
907907
"createPagesStatefully",
908908
"setFieldsOnGraphQLNodeType",
909-
"unstable_onPluginInit",
909+
"onPluginInit",
910910
],
911911
"pluginOptions": Object {
912912
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/functions/src/pages",
@@ -927,7 +927,7 @@ Array [
927927
"nodeAPIs": Array [
928928
"createPagesStatefully",
929929
"setFieldsOnGraphQLNodeType",
930-
"unstable_onPluginInit",
930+
"onPluginInit",
931931
],
932932
"pluginOptions": Object {
933933
"path": "<PROJECT_ROOT>/packages/gatsby-plugin-page-creator/src/pages",
@@ -983,7 +983,7 @@ Array [
983983
"nodeAPIs": Array [
984984
"createPagesStatefully",
985985
"setFieldsOnGraphQLNodeType",
986-
"unstable_onPluginInit",
986+
"onPluginInit",
987987
],
988988
"pluginOptions": Object {
989989
"path": "/src/pages",

‎packages/gatsby/src/commands/__tests__/build-utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ describe(`calcDirtyHtmlFiles`, () => {
5656
// eslint-disable-next-line @typescript-eslint/naming-convention
5757
pluginCreator___NODE: `foo`,
5858
updatedAt: 1,
59+
mode: `SSG`,
5960
})
6061
}
6162

‎packages/gatsby/src/query/__tests__/data-tracking.js

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jest.mock(`fs-extra`, () => {
3131
return {
3232
outputFile: jest.fn(),
3333
ensureDir: jest.fn(),
34+
readFileSync: jest.fn(() => `foo`), // createPage action reads the page template file trying to find `getServerData`
3435
}
3536
})
3637

‎packages/gatsby/src/redux/__tests__/__snapshots__/index.js.snap

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Object {
7474
"internalComponentName": "Component/my-sweet-new-page/",
7575
"isCreatedByStatefulCreatePages": false,
7676
"matchPath": undefined,
77+
"mode": "SSG",
7778
"path": "/my-sweet-new-page/",
7879
"pluginCreatorId": "",
7980
"pluginCreator___NODE": "",

‎packages/gatsby/src/redux/__tests__/__snapshots__/pages.ts.snap

+9
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Map {
5454
"internalComponentName": "Component/hi/",
5555
"isCreatedByStatefulCreatePages": false,
5656
"matchPath": undefined,
57+
"mode": "SSG",
5758
"path": "/hi/",
5859
"pluginCreatorId": "test",
5960
"pluginCreator___NODE": "test",
@@ -66,6 +67,7 @@ Map {
6667
"internalComponentName": "Component/hi/pizza/",
6768
"isCreatedByStatefulCreatePages": false,
6869
"matchPath": undefined,
70+
"mode": "SSG",
6971
"path": "/hi/pizza/",
7072
"pluginCreatorId": "test",
7173
"pluginCreator___NODE": "test",
@@ -84,6 +86,7 @@ Object {
8486
"internalComponentName": "Component/hi/",
8587
"isCreatedByStatefulCreatePages": false,
8688
"matchPath": undefined,
89+
"mode": "SSG",
8790
"path": "/hi/",
8891
"pluginCreatorId": "test",
8992
"pluginCreator___NODE": "test",
@@ -106,6 +109,7 @@ Map {
106109
"internalComponentName": "Component/hi/",
107110
"isCreatedByStatefulCreatePages": false,
108111
"matchPath": undefined,
112+
"mode": "SSG",
109113
"path": "/hi/",
110114
"pluginCreatorId": "test",
111115
"pluginCreator___NODE": "test",
@@ -126,6 +130,7 @@ Object {
126130
"internalComponentName": "Component/hi/",
127131
"isCreatedByStatefulCreatePages": false,
128132
"matchPath": undefined,
133+
"mode": "SSG",
129134
"path": "/hi/",
130135
"pluginCreatorId": "test",
131136
"pluginCreator___NODE": "test",
@@ -150,6 +155,7 @@ Map {
150155
"internalComponentName": "Component/hi/",
151156
"isCreatedByStatefulCreatePages": false,
152157
"matchPath": undefined,
158+
"mode": "SSG",
153159
"path": "/hi/",
154160
"pluginCreatorId": "test",
155161
"pluginCreator___NODE": "test",
@@ -168,6 +174,7 @@ Object {
168174
"internalComponentName": "Component/hi/",
169175
"isCreatedByStatefulCreatePages": false,
170176
"matchPath": "/hi-from-somewhere-else/",
177+
"mode": "SSG",
171178
"path": "/hi/",
172179
"pluginCreatorId": "test",
173180
"pluginCreator___NODE": "test",
@@ -190,6 +197,7 @@ Map {
190197
"internalComponentName": "Component/hi/",
191198
"isCreatedByStatefulCreatePages": false,
192199
"matchPath": "/hi-from-somewhere-else/",
200+
"mode": "SSG",
193201
"path": "/hi/",
194202
"pluginCreatorId": "test",
195203
"pluginCreator___NODE": "test",
@@ -209,6 +217,7 @@ Map {
209217
"internalComponentName": "Component/hi/",
210218
"isCreatedByStatefulCreatePages": false,
211219
"matchPath": undefined,
220+
"mode": "SSG",
212221
"path": "/hi/",
213222
"pluginCreatorId": "test",
214223
"pluginCreator___NODE": "test",

‎packages/gatsby/src/redux/__tests__/index.js

+23-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const {
2121
actions: { createPage, createNode },
2222
} = require(`../actions`)
2323

24+
const pageTemplatePath = `/Users/username/dev/site/src/templates/my-sweet-new-page.js`
2425
const mockWrittenContent = new Map()
2526
const mockCompatiblePath = path
2627
jest.mock(`fs-extra`, () => {
@@ -131,7 +132,7 @@ describe(`redux db`, () => {
131132
const defaultPage = {
132133
path: `/my-sweet-new-page/`,
133134
// seems like jest serializer doesn't play nice with Maps on Windows
134-
component: `/Users/username/dev/site/src/templates/my-sweet-new-page.js`,
135+
component: pageTemplatePath,
135136
// The context is passed as props to the component as well
136137
// as into the component's GraphQL query.
137138
context: {
@@ -146,6 +147,7 @@ describe(`redux db`, () => {
146147
})
147148
writeToCache.mockClear()
148149
mockWrittenContent.clear()
150+
mockWrittenContent.set(pageTemplatePath, `foo`)
149151
reporterWarn.mockClear()
150152
reporterInfo.mockClear()
151153
})
@@ -530,8 +532,16 @@ describe(`redux db`, () => {
530532
it(`saves with correct filename (with defaults)`, () => {
531533
savePartialStateToDisk([`pages`])
532534

533-
const savedFile = mockWrittenContent.keys().next().value
534-
const basename = path.basename(savedFile)
535+
let basename
536+
// get first non page template mocked fs write
537+
for (const savedFile of mockWrittenContent.keys()) {
538+
if (savedFile === pageTemplatePath) {
539+
continue
540+
}
541+
542+
basename = path.basename(savedFile)
543+
break
544+
}
535545

536546
expect(basename.startsWith(`redux.worker.slices__`)).toBe(true)
537547
})
@@ -549,8 +559,16 @@ describe(`redux db`, () => {
549559
it(`respects optionalPrefix`, () => {
550560
savePartialStateToDisk([`pages`], `custom-prefix`)
551561

552-
const savedFile = mockWrittenContent.keys().next().value
553-
const basename = path.basename(savedFile)
562+
let basename
563+
// get first non page template mocked fs write
564+
for (const savedFile of mockWrittenContent.keys()) {
565+
if (savedFile === pageTemplatePath) {
566+
continue
567+
}
568+
569+
basename = path.basename(savedFile)
570+
break
571+
}
554572

555573
expect(basename.startsWith(`redux.worker.slices_custom-prefix_`)).toBe(
556574
true

‎packages/gatsby/src/redux/__tests__/pages.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { readFile } from "fs-extra"
33
jest.mock(`fs-extra`, () => {
44
return {
55
readFile: jest.fn(() => `contents`),
6+
readFileSync: jest.fn(() => `foo`), // createPage action reads the page template file trying to find `getServerData`
67
}
78
})
89
import glob from "glob"

‎packages/gatsby/src/services/__tests__/create-pages.ts

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ jest.mock(`../../utils/js-chunk-names`, () => {
1010
return { generateComponentChunkName: (): string => `--mocked--` }
1111
})
1212

13+
jest.mock(`fs-extra`, () => {
14+
return {
15+
readFileSync: jest.fn(() => `foo`), // createPage action reads the page template file trying to find `getServerData`
16+
}
17+
})
18+
1319
let mockAPIs = {}
1420

1521
const component = path.join(process.cwd(), `wat`)

‎packages/gatsby/src/utils/__tests__/get-page-data.ts

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ describe(`get-page-data-util`, () => {
9595
path: `/foo`,
9696
componentPath: `/foo.js`,
9797
component: `/foo.js`,
98+
mode: `SSG`, // TODO: need to test other modes in non-build environment
9899
},
99100
}
100101

0 commit comments

Comments
 (0)
Please sign in to comment.