Skip to content

Commit

Permalink
test: adjust tests after the bump (#33171)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people committed Sep 14, 2021
1 parent b622b22 commit 4712acc
Show file tree
Hide file tree
Showing 20 changed files with 126 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -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
Expand Down
Expand Up @@ -90,7 +90,9 @@ Array [
"availableFlags": Array [
"GATSBY_MAJOR",
],
"flags": Object {},
"flags": Object {
"GATSBY_MAJOR": "4",
},
},
],
]
Expand All @@ -109,7 +111,9 @@ Array [
"availableFlags": Array [
"MAJOR",
],
"flags": Object {},
"flags": Object {
"GATSBY_MAJOR": "4",
},
},
],
]
Expand Down Expand Up @@ -176,7 +180,9 @@ Array [
"availableFlags": Array [
"GATSBY_MAJOR",
],
"flags": Object {},
"flags": Object {
"GATSBY_MAJOR": "4",
},
},
],
]
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-preset-gatsby-package/package.json
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-cli/src/index.ts
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-plugin-mdx/__tests__/gatsby-node.js
Expand Up @@ -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`,
Expand Down
6 changes: 5 additions & 1 deletion packages/gatsby-plugin-mdx/utils/__tests__/gen-mdx.js
Expand Up @@ -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`,
Expand All @@ -37,7 +38,10 @@ describe(`find imports`, () => {
options: {
remarkPlugins: [],
gatsbyRemarkPlugins: [
{ resolve: path.join(__dirname, `fixtures`, `test-plugin`) },
{
resolve: testPluginModulePath,
module: require(testPluginModulePath),
},
],
},
getNode: () => null,
Expand Down
30 changes: 29 additions & 1 deletion packages/gatsby-plugin-utils/src/test-plugin-options-schema.ts
Expand Up @@ -12,7 +12,35 @@ export async function testPluginOptionsSchema(
pluginSchemaFunction: Exclude<GatsbyNode["pluginOptionsSchema"], undefined>,
pluginOptions: IPluginInfoOptions
): Promise<ITestPluginOptionsSchemaReturnType> {
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)
Expand Down
Expand Up @@ -1143,6 +1143,7 @@ It's easier than you may imagine`,
showLineNumbers: false,
noInlineHighlight: false,
},
module: require(`gatsby-remark-prismjs`),
},
],
},
Expand Down Expand Up @@ -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`),
},
],
},
Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby/scripts/__tests__/api.js
Expand Up @@ -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 {},
Expand All @@ -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",
},
Expand Down
Expand Up @@ -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`, () => {
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/bootstrap/__tests__/requires-writer.js
Expand Up @@ -10,6 +10,7 @@ const generatePagesState = pages => {
state.set(page.path, {
component: ``,
componentChunkName: ``,
mode: `SSG`,
...page,
})
})
Expand Down

0 comments on commit 4712acc

Please sign in to comment.