diff --git a/.circleci/config.yml b/.circleci/config.yml index 87f6d0cc9c24f..f3d00641a0510 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -83,7 +83,7 @@ aliases: yarn why lmdb-store - run: name: Run tests - command: yarn jest --ci --runInBand $(yarn jest --listTests | sed 's/\/root\/project//g' | circleci tests split --split-by=timings) + command: yarn jest --ci --runInBand $(yarn -s jest --listTests | sed 's/\/home\/circleci\/project\///g' | circleci tests split) environment: NODE_OPTIONS: --max-old-space-size=2048 GENERATE_JEST_REPORT: true diff --git a/packages/babel-preset-gatsby-package/lib/__tests__/__snapshots__/index.js.snap b/packages/babel-preset-gatsby-package/lib/__tests__/__snapshots__/index.js.snap index fe740e23f89f9..9e149bc763efa 100644 --- a/packages/babel-preset-gatsby-package/lib/__tests__/__snapshots__/index.js.snap +++ b/packages/babel-preset-gatsby-package/lib/__tests__/__snapshots__/index.js.snap @@ -90,7 +90,9 @@ Array [ "availableFlags": Array [ "GATSBY_MAJOR", ], - "flags": Object {}, + "flags": Object { + "GATSBY_MAJOR": "4", + }, }, ], ] @@ -109,7 +111,9 @@ Array [ "availableFlags": Array [ "MAJOR", ], - "flags": Object {}, + "flags": Object { + "GATSBY_MAJOR": "4", + }, }, ], ] @@ -176,7 +180,9 @@ Array [ "availableFlags": Array [ "GATSBY_MAJOR", ], - "flags": Object {}, + "flags": Object { + "GATSBY_MAJOR": "4", + }, }, ], ] diff --git a/packages/babel-preset-gatsby-package/package.json b/packages/babel-preset-gatsby-package/package.json index 36d0dc9975a2c..197bbbad4332b 100644 --- a/packages/babel-preset-gatsby-package/package.json +++ b/packages/babel-preset-gatsby-package/package.json @@ -26,7 +26,8 @@ "@babel/core": "^7.15.5", "@babel/helper-plugin-test-runner": "7.14.5", "@babel/plugin-transform-modules-commonjs": "^7.15.4", - "@types/babel__core": "^7.1.15" + "@types/babel__core": "^7.1.15", + "cross-env": "^7.0.3" }, "peerDependencies": { "@babel/core": "^7.11.6" diff --git a/packages/gatsby-cli/src/index.ts b/packages/gatsby-cli/src/index.ts index d69fa34dde30e..d6b4321b56d6a 100755 --- a/packages/gatsby-cli/src/index.ts +++ b/packages/gatsby-cli/src/index.ts @@ -23,7 +23,7 @@ if (os.platform() === `win32`) { // Check if update is available updateNotifier({ pkg }).notify({ isGlobal: true }) -const MIN_NODE_VERSION = `12.13.0` +const MIN_NODE_VERSION = `14.15.0` // const NEXT_MIN_NODE_VERSION = `10.13.0` const { version } = process diff --git a/packages/gatsby-plugin-mdx/__tests__/gatsby-node.js b/packages/gatsby-plugin-mdx/__tests__/gatsby-node.js index 0c7bacc5ae648..df7deffbfa0ba 100644 --- a/packages/gatsby-plugin-mdx/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-mdx/__tests__/gatsby-node.js @@ -8,8 +8,8 @@ describe(`pluginOptionsSchema`, () => { `"extensions[1]" must be a string`, `"extensions[2]" must be a string`, `"defaultLayouts" must be of type object`, - `"gatsbyRemarkPlugins[0]" does not match any of the allowed types`, - `"gatsbyRemarkPlugins[1]" does not match any of the allowed types`, + `"gatsbyRemarkPlugins[0]" must be one of [string, object]`, + `"gatsbyRemarkPlugins[1].not" is not allowed`, `"remarkPlugins" must be an array`, `"rehypePlugins" must be an array`, `"plugins[0]" does not match any of the allowed types`, diff --git a/packages/gatsby-plugin-mdx/utils/__tests__/gen-mdx.js b/packages/gatsby-plugin-mdx/utils/__tests__/gen-mdx.js index fe7341f21eaa9..457dfcb1205e4 100644 --- a/packages/gatsby-plugin-mdx/utils/__tests__/gen-mdx.js +++ b/packages/gatsby-plugin-mdx/utils/__tests__/gen-mdx.js @@ -16,6 +16,7 @@ console.log('hello world') describe(`find imports`, () => { it(`allows injecting imports via plugins`, async () => { + const testPluginModulePath = path.join(__dirname, `fixtures`, `test-plugin`) const results = await findImports({ node: { id: `bbffffbb-bfff-bfff-bfff-dededededede`, @@ -37,7 +38,10 @@ describe(`find imports`, () => { options: { remarkPlugins: [], gatsbyRemarkPlugins: [ - { resolve: path.join(__dirname, `fixtures`, `test-plugin`) }, + { + resolve: testPluginModulePath, + module: require(testPluginModulePath), + }, ], }, getNode: () => null, diff --git a/packages/gatsby-plugin-utils/src/test-plugin-options-schema.ts b/packages/gatsby-plugin-utils/src/test-plugin-options-schema.ts index 81c949b5bc2f2..da006fcce75f0 100644 --- a/packages/gatsby-plugin-utils/src/test-plugin-options-schema.ts +++ b/packages/gatsby-plugin-utils/src/test-plugin-options-schema.ts @@ -12,7 +12,35 @@ export async function testPluginOptionsSchema( pluginSchemaFunction: Exclude, pluginOptions: IPluginInfoOptions ): Promise { - const pluginSchema = pluginSchemaFunction({ Joi }) + const pluginSchema = pluginSchemaFunction({ + Joi: Joi.extend(joi => { + return { + base: joi.any(), + type: `subPlugins`, + args: (): any => + joi + .array() + .items( + joi + .alternatives( + joi.string(), + joi.object({ + resolve: Joi.string(), + options: Joi.object({}).unknown(true), + }) + ) + .custom(value => { + if (typeof value === `string`) { + value = { resolve: value } + } + + return value + }, `Gatsby specific subplugin validation`) + ) + .default([]), + } + }), + }) try { await validateOptionsSchema(pluginSchema, pluginOptions) diff --git a/packages/gatsby-transformer-remark/src/__tests__/extend-node.js b/packages/gatsby-transformer-remark/src/__tests__/extend-node.js index 6a6f004a3db89..dcdd02922add3 100644 --- a/packages/gatsby-transformer-remark/src/__tests__/extend-node.js +++ b/packages/gatsby-transformer-remark/src/__tests__/extend-node.js @@ -1143,6 +1143,7 @@ It's easier than you may imagine`, showLineNumbers: false, noInlineHighlight: false, }, + module: require(`gatsby-remark-prismjs`), }, ], }, @@ -1335,6 +1336,7 @@ describe(`Headings are generated correctly from schema`, () => { { resolve: require.resolve(`gatsby-remark-autolink-headers/src`), pluginOptions: {}, + module: require(`gatsby-remark-autolink-headers/src`), }, ], }, diff --git a/packages/gatsby/scripts/__tests__/api.js b/packages/gatsby/scripts/__tests__/api.js index 593059e8ce43b..a1b6e3bd2bf6d 100644 --- a/packages/gatsby/scripts/__tests__/api.js +++ b/packages/gatsby/scripts/__tests__/api.js @@ -44,6 +44,9 @@ it("generates the expected api output", done => { "onCreateNode": Object {}, "onCreatePage": Object {}, "onCreateWebpackConfig": Object {}, + "onPluginInit": Object { + "version": "3.9.0", + }, "onPostBootstrap": Object {}, "onPostBuild": Object {}, "onPreBootstrap": Object {}, @@ -57,9 +60,6 @@ it("generates the expected api output", done => { "resolvableExtensions": Object {}, "setFieldsOnGraphQLNodeType": Object {}, "sourceNodes": Object {}, - "onPluginInit": Object { - "version": "3.9.0", - }, "unstable_shouldOnCreateNode": Object { "version": "2.24.80", }, diff --git a/packages/gatsby/src/bootstrap/__tests__/redirects-writer.ts b/packages/gatsby/src/bootstrap/__tests__/redirects-writer.ts index b1db0ed179bde..ada1749be3398 100644 --- a/packages/gatsby/src/bootstrap/__tests__/redirects-writer.ts +++ b/packages/gatsby/src/bootstrap/__tests__/redirects-writer.ts @@ -5,7 +5,7 @@ import { store } from "../../redux" import { actions } from "../../redux/actions" jest.mock(`fs-extra`, () => { - return { writeFile: jest.fn() } + return { writeFile: jest.fn(), readFileSync: jest.fn(() => `foo`) } }) jest.mock(`gatsby-cli/lib/reporter`, () => { diff --git a/packages/gatsby/src/bootstrap/__tests__/requires-writer.js b/packages/gatsby/src/bootstrap/__tests__/requires-writer.js index dd772a3fab652..945c8a53c818a 100644 --- a/packages/gatsby/src/bootstrap/__tests__/requires-writer.js +++ b/packages/gatsby/src/bootstrap/__tests__/requires-writer.js @@ -10,6 +10,7 @@ const generatePagesState = pages => { state.set(page.path, { component: ``, componentChunkName: ``, + mode: `SSG`, ...page, }) }) diff --git a/packages/gatsby/src/bootstrap/load-plugins/__tests__/__snapshots__/load-plugins.ts.snap b/packages/gatsby/src/bootstrap/load-plugins/__tests__/__snapshots__/load-plugins.ts.snap index 1140f0072e9b6..c28c6f35d04de 100644 --- a/packages/gatsby/src/bootstrap/load-plugins/__tests__/__snapshots__/load-plugins.ts.snap +++ b/packages/gatsby/src/bootstrap/load-plugins/__tests__/__snapshots__/load-plugins.ts.snap @@ -110,7 +110,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/dev-404-page/src/pages", @@ -131,7 +131,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/load-babel-config/src/pages", @@ -152,7 +152,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/internal-data-bridge/src/pages", @@ -173,7 +173,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/prod-404/src/pages", @@ -194,7 +194,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/webpack-theme-component-shadowing/src/pages", @@ -215,7 +215,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/bundle-optimisations/src/pages", @@ -236,7 +236,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/functions/src/pages", @@ -292,7 +292,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/src/pages", @@ -429,7 +429,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/dev-404-page/src/pages", @@ -450,7 +450,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/load-babel-config/src/pages", @@ -471,7 +471,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/internal-data-bridge/src/pages", @@ -492,7 +492,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/prod-404/src/pages", @@ -513,7 +513,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/webpack-theme-component-shadowing/src/pages", @@ -534,7 +534,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/bundle-optimisations/src/pages", @@ -555,7 +555,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/functions/src/pages", @@ -576,7 +576,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "__TEST__/src/pages", @@ -632,7 +632,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/src/pages", @@ -757,7 +757,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "ignore": Array [ @@ -780,7 +780,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/dev-404-page/src/pages", @@ -801,7 +801,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/load-babel-config/src/pages", @@ -822,7 +822,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/internal-data-bridge/src/pages", @@ -843,7 +843,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/prod-404/src/pages", @@ -864,7 +864,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/webpack-theme-component-shadowing/src/pages", @@ -885,7 +885,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/bundle-optimisations/src/pages", @@ -906,7 +906,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby/src/internal-plugins/functions/src/pages", @@ -927,7 +927,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/packages/gatsby-plugin-page-creator/src/pages", @@ -983,7 +983,7 @@ Array [ "nodeAPIs": Array [ "createPagesStatefully", "setFieldsOnGraphQLNodeType", - "unstable_onPluginInit", + "onPluginInit", ], "pluginOptions": Object { "path": "/src/pages", diff --git a/packages/gatsby/src/commands/__tests__/build-utils.ts b/packages/gatsby/src/commands/__tests__/build-utils.ts index 9fccdde11da4b..b5609acf8db58 100644 --- a/packages/gatsby/src/commands/__tests__/build-utils.ts +++ b/packages/gatsby/src/commands/__tests__/build-utils.ts @@ -56,6 +56,7 @@ describe(`calcDirtyHtmlFiles`, () => { // eslint-disable-next-line @typescript-eslint/naming-convention pluginCreator___NODE: `foo`, updatedAt: 1, + mode: `SSG`, }) } diff --git a/packages/gatsby/src/query/__tests__/data-tracking.js b/packages/gatsby/src/query/__tests__/data-tracking.js index 92ad2cd01c100..ad5f58e8ab987 100644 --- a/packages/gatsby/src/query/__tests__/data-tracking.js +++ b/packages/gatsby/src/query/__tests__/data-tracking.js @@ -31,6 +31,7 @@ jest.mock(`fs-extra`, () => { return { outputFile: jest.fn(), ensureDir: jest.fn(), + readFileSync: jest.fn(() => `foo`), // createPage action reads the page template file trying to find `getServerData` } }) diff --git a/packages/gatsby/src/redux/__tests__/__snapshots__/index.js.snap b/packages/gatsby/src/redux/__tests__/__snapshots__/index.js.snap index 5d1c5abb60fcb..586089419a3b0 100644 --- a/packages/gatsby/src/redux/__tests__/__snapshots__/index.js.snap +++ b/packages/gatsby/src/redux/__tests__/__snapshots__/index.js.snap @@ -74,6 +74,7 @@ Object { "internalComponentName": "Component/my-sweet-new-page/", "isCreatedByStatefulCreatePages": false, "matchPath": undefined, + "mode": "SSG", "path": "/my-sweet-new-page/", "pluginCreatorId": "", "pluginCreator___NODE": "", diff --git a/packages/gatsby/src/redux/__tests__/__snapshots__/pages.ts.snap b/packages/gatsby/src/redux/__tests__/__snapshots__/pages.ts.snap index 0f69a6cf7fb09..4e7b2140fdc3e 100644 --- a/packages/gatsby/src/redux/__tests__/__snapshots__/pages.ts.snap +++ b/packages/gatsby/src/redux/__tests__/__snapshots__/pages.ts.snap @@ -54,6 +54,7 @@ Map { "internalComponentName": "Component/hi/", "isCreatedByStatefulCreatePages": false, "matchPath": undefined, + "mode": "SSG", "path": "/hi/", "pluginCreatorId": "test", "pluginCreator___NODE": "test", @@ -66,6 +67,7 @@ Map { "internalComponentName": "Component/hi/pizza/", "isCreatedByStatefulCreatePages": false, "matchPath": undefined, + "mode": "SSG", "path": "/hi/pizza/", "pluginCreatorId": "test", "pluginCreator___NODE": "test", @@ -84,6 +86,7 @@ Object { "internalComponentName": "Component/hi/", "isCreatedByStatefulCreatePages": false, "matchPath": undefined, + "mode": "SSG", "path": "/hi/", "pluginCreatorId": "test", "pluginCreator___NODE": "test", @@ -106,6 +109,7 @@ Map { "internalComponentName": "Component/hi/", "isCreatedByStatefulCreatePages": false, "matchPath": undefined, + "mode": "SSG", "path": "/hi/", "pluginCreatorId": "test", "pluginCreator___NODE": "test", @@ -126,6 +130,7 @@ Object { "internalComponentName": "Component/hi/", "isCreatedByStatefulCreatePages": false, "matchPath": undefined, + "mode": "SSG", "path": "/hi/", "pluginCreatorId": "test", "pluginCreator___NODE": "test", @@ -150,6 +155,7 @@ Map { "internalComponentName": "Component/hi/", "isCreatedByStatefulCreatePages": false, "matchPath": undefined, + "mode": "SSG", "path": "/hi/", "pluginCreatorId": "test", "pluginCreator___NODE": "test", @@ -168,6 +174,7 @@ Object { "internalComponentName": "Component/hi/", "isCreatedByStatefulCreatePages": false, "matchPath": "/hi-from-somewhere-else/", + "mode": "SSG", "path": "/hi/", "pluginCreatorId": "test", "pluginCreator___NODE": "test", @@ -190,6 +197,7 @@ Map { "internalComponentName": "Component/hi/", "isCreatedByStatefulCreatePages": false, "matchPath": "/hi-from-somewhere-else/", + "mode": "SSG", "path": "/hi/", "pluginCreatorId": "test", "pluginCreator___NODE": "test", @@ -209,6 +217,7 @@ Map { "internalComponentName": "Component/hi/", "isCreatedByStatefulCreatePages": false, "matchPath": undefined, + "mode": "SSG", "path": "/hi/", "pluginCreatorId": "test", "pluginCreator___NODE": "test", diff --git a/packages/gatsby/src/redux/__tests__/index.js b/packages/gatsby/src/redux/__tests__/index.js index 15deb515c44f1..ee58c77282a68 100644 --- a/packages/gatsby/src/redux/__tests__/index.js +++ b/packages/gatsby/src/redux/__tests__/index.js @@ -21,6 +21,7 @@ const { actions: { createPage, createNode }, } = require(`../actions`) +const pageTemplatePath = `/Users/username/dev/site/src/templates/my-sweet-new-page.js` const mockWrittenContent = new Map() const mockCompatiblePath = path jest.mock(`fs-extra`, () => { @@ -131,7 +132,7 @@ describe(`redux db`, () => { const defaultPage = { path: `/my-sweet-new-page/`, // seems like jest serializer doesn't play nice with Maps on Windows - component: `/Users/username/dev/site/src/templates/my-sweet-new-page.js`, + component: pageTemplatePath, // The context is passed as props to the component as well // as into the component's GraphQL query. context: { @@ -146,6 +147,7 @@ describe(`redux db`, () => { }) writeToCache.mockClear() mockWrittenContent.clear() + mockWrittenContent.set(pageTemplatePath, `foo`) reporterWarn.mockClear() reporterInfo.mockClear() }) @@ -530,8 +532,16 @@ describe(`redux db`, () => { it(`saves with correct filename (with defaults)`, () => { savePartialStateToDisk([`pages`]) - const savedFile = mockWrittenContent.keys().next().value - const basename = path.basename(savedFile) + let basename + // get first non page template mocked fs write + for (const savedFile of mockWrittenContent.keys()) { + if (savedFile === pageTemplatePath) { + continue + } + + basename = path.basename(savedFile) + break + } expect(basename.startsWith(`redux.worker.slices__`)).toBe(true) }) @@ -549,8 +559,16 @@ describe(`redux db`, () => { it(`respects optionalPrefix`, () => { savePartialStateToDisk([`pages`], `custom-prefix`) - const savedFile = mockWrittenContent.keys().next().value - const basename = path.basename(savedFile) + let basename + // get first non page template mocked fs write + for (const savedFile of mockWrittenContent.keys()) { + if (savedFile === pageTemplatePath) { + continue + } + + basename = path.basename(savedFile) + break + } expect(basename.startsWith(`redux.worker.slices_custom-prefix_`)).toBe( true diff --git a/packages/gatsby/src/redux/__tests__/pages.ts b/packages/gatsby/src/redux/__tests__/pages.ts index dd42d4c73cc76..60d5b7dd25db6 100644 --- a/packages/gatsby/src/redux/__tests__/pages.ts +++ b/packages/gatsby/src/redux/__tests__/pages.ts @@ -3,6 +3,7 @@ import { readFile } from "fs-extra" jest.mock(`fs-extra`, () => { return { readFile: jest.fn(() => `contents`), + readFileSync: jest.fn(() => `foo`), // createPage action reads the page template file trying to find `getServerData` } }) import glob from "glob" diff --git a/packages/gatsby/src/services/__tests__/create-pages.ts b/packages/gatsby/src/services/__tests__/create-pages.ts index 20d8087a4e0eb..4ec43929473d0 100644 --- a/packages/gatsby/src/services/__tests__/create-pages.ts +++ b/packages/gatsby/src/services/__tests__/create-pages.ts @@ -10,6 +10,12 @@ jest.mock(`../../utils/js-chunk-names`, () => { return { generateComponentChunkName: (): string => `--mocked--` } }) +jest.mock(`fs-extra`, () => { + return { + readFileSync: jest.fn(() => `foo`), // createPage action reads the page template file trying to find `getServerData` + } +}) + let mockAPIs = {} const component = path.join(process.cwd(), `wat`) diff --git a/packages/gatsby/src/utils/__tests__/get-page-data.ts b/packages/gatsby/src/utils/__tests__/get-page-data.ts index 796a037e54963..b32368866d4ea 100644 --- a/packages/gatsby/src/utils/__tests__/get-page-data.ts +++ b/packages/gatsby/src/utils/__tests__/get-page-data.ts @@ -95,6 +95,7 @@ describe(`get-page-data-util`, () => { path: `/foo`, componentPath: `/foo.js`, component: `/foo.js`, + mode: `SSG`, // TODO: need to test other modes in non-build environment }, }