Skip to content

Commit 7451d2f

Browse files
authored
fix: support node 22 (#39349)
* test(gatsby-cli): tolerate varying stack traces * test: import mocked module the same way it's used This mismatch stopped working after node 18. * test: use more specific snapshot for res headers Some of the connection header defaults depend on the node.js major version wip this is a fix for the headers one * test: skip unstable GC tests on node 20+ * test: adjust assertion to work on node 22 locally See inline comment * test: fix sharp build error in lmdb-regeneration fixture The `lmdb-regeneration` integration test fixture had an `.npmrc` file forcing all packages to be built from source, which caused sharp to fail compilation in Node 20+ CircleCI images (Ubuntu Noble) due to... who knows what, honestly. Since this fixture specifically needs lmdb built from source but not sharp (it's testing something specific to this), this replaces the global `.npmrc` `build-from-source` flag with a targeted `postinstall` script that only rebuilds lmdb from source, allowing sharp to use prebuilt binaries. This resolves the "cannot find -l:libvips-cpp.so.42" linker errors that were blocking integration tests on Node 20+ while preserving the fixture's intended lmdb compilation testing. AFAICT this was... basically the only solution. Whew * fix(gatsby): bump `webpack-virtual-modules` to get this bug fix: sysgears/webpack-virtual-modules#172 causing this, unclear when: ``` TypeError: Cannot read properties of null (reading 'fileWatchers') ``` * ci: test against Node 18, 20, 22 - run unit tests against all three - run integration tests against earliest and latest - make sure to separate npm cache by node version * ci: test against node 22.13 to avoid bug for now
1 parent c3708b0 commit 7451d2f

File tree

14 files changed

+524
-442
lines changed

14 files changed

+524
-442
lines changed

.circleci/config.yml

Lines changed: 197 additions & 62 deletions
Large diffs are not rendered by default.

integration-tests/functions/__tests__/__snapshots__/functions-dev.js.snap

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,27 +80,17 @@ Object {
8080

8181
exports[`develop response formats returns json correctly 2`] = `
8282
Object {
83-
"access-control-allow-origin": "*",
84-
"connection": "close",
8583
"content-length": "16",
8684
"content-type": "application/json; charset=utf-8",
87-
"etag": "W/\\"10-R6td1pV+B+Xz9CJkNeaEI2kP+QY\\"",
88-
"vary": "Accept-Encoding",
89-
"x-powered-by": "Express",
9085
}
9186
`;
9287

9388
exports[`develop response formats returns text correctly 1`] = `"I am typescript"`;
9489

9590
exports[`develop response formats returns text correctly 2`] = `
9691
Object {
97-
"access-control-allow-origin": "*",
98-
"connection": "close",
9992
"content-length": "15",
10093
"content-type": "text/html; charset=utf-8",
101-
"etag": "W/\\"f-zwggT56l/fnWBm4dI0PkA4E3i4E\\"",
102-
"vary": "Accept-Encoding",
103-
"x-powered-by": "Express",
10494
}
10595
`;
10696

integration-tests/functions/__tests__/__snapshots__/functions-prod.js.snap

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,17 @@ Object {
8080

8181
exports[`production response formats returns json correctly 2`] = `
8282
Object {
83-
"connection": "close",
8483
"content-length": "16",
8584
"content-type": "application/json; charset=utf-8",
86-
"etag": "W/\\"10-R6td1pV+B+Xz9CJkNeaEI2kP+QY\\"",
87-
"x-powered-by": "Express",
8885
}
8986
`;
9087

9188
exports[`production response formats returns text correctly 1`] = `"I am typescript"`;
9289

9390
exports[`production response formats returns text correctly 2`] = `
9491
Object {
95-
"connection": "close",
9692
"content-length": "15",
9793
"content-type": "text/html; charset=utf-8",
98-
"etag": "W/\\"f-zwggT56l/fnWBm4dI0PkA4E3i4E\\"",
99-
"x-powered-by": "Express",
10094
}
10195
`;
10296

integration-tests/functions/test-helpers.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,23 @@ export function runTests(env, host) {
164164
const res = await fetchWithRetry(`${host}/api/i-am-json`)
165165
const result = await res.json()
166166

167-
const { date, ...headers } = Object.fromEntries(res.headers)
167+
const relevantHeaders = {
168+
'content-type': res.headers.get('content-type'),
169+
'content-length': res.headers.get('content-length')
170+
}
168171
expect(result).toMatchSnapshot()
169-
expect(headers).toMatchSnapshot()
172+
expect(relevantHeaders).toMatchSnapshot()
170173
})
171174
test(`returns text correctly`, async () => {
172175
const res = await fetchWithRetry(`${host}/api/i-am-typescript`)
173176
const result = await res.text()
174177

175-
const { date, ...headers } = Object.fromEntries(res.headers)
178+
const relevantHeaders = {
179+
'content-type': res.headers.get('content-type'),
180+
'content-length': res.headers.get('content-length')
181+
}
176182
expect(result).toMatchSnapshot()
177-
expect(headers).toMatchSnapshot()
183+
expect(relevantHeaders).toMatchSnapshot()
178184
})
179185
})
180186

integration-tests/lmdb-regeneration/.npmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

integration-tests/lmdb-regeneration/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"scripts": {
99
"build": "gatsby build",
1010
"clean": "gatsby clean",
11+
"postinstall": "npm rebuild --build-from-source lmdb",
1112
"test": "jest --runInBand"
1213
},
1314
"dependencies": {

integration-tests/ssr/__tests__/ssr.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ describe(`SSR`, () => {
129129
it(
130130
title,
131131
async () => {
132-
const src = path.join(__dirname, `/fixtures/`, fixture)
132+
const src = path.join(__dirname, `fixtures`, fixture)
133133
const dest = getSrcLoc(fixture)
134134
fs.copySync(src, dest)
135135

packages/gatsby-cli/src/reporter/__tests__/__snapshots__/index.ts.snap

Lines changed: 5 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Object {
3838
},
3939
"docsUrl": "https://gatsby.dev/issue-how-to",
4040
"level": "ERROR",
41-
"stack": Array [],
41+
"stack": Any<Array>,
4242
"text": "Error created in Jest",
4343
"type": "UNKNOWN",
4444
}
@@ -69,80 +69,7 @@ Object {
6969
"error": [Error: Message from new Error],
7070
"level": "ERROR",
7171
"pluginName": "gatsby-plugin-foo-bar",
72-
"stack": Array [
73-
Object {
74-
"columnNumber": 7,
75-
"fileName": "<PROJECT_ROOT>/packages/gatsby-cli/src/reporter/__tests__/index.ts",
76-
"functionName": null,
77-
"lineNumber": 100,
78-
},
79-
Object {
80-
"columnNumber": 28,
81-
"fileName": "<PROJECT_ROOT>/node_modules/jest-circus/build/utils.js",
82-
"functionName": "Promise.then.completed",
83-
"lineNumber": 293,
84-
},
85-
Object {
86-
"columnNumber": 10,
87-
"fileName": "<PROJECT_ROOT>/node_modules/jest-circus/build/utils.js",
88-
"functionName": "callAsyncCircusFn",
89-
"lineNumber": 226,
90-
},
91-
Object {
92-
"columnNumber": 40,
93-
"fileName": "<PROJECT_ROOT>/node_modules/jest-circus/build/run.js",
94-
"functionName": "_callCircusTest",
95-
"lineNumber": 297,
96-
},
97-
Object {
98-
"columnNumber": 3,
99-
"fileName": "<PROJECT_ROOT>/node_modules/jest-circus/build/run.js",
100-
"functionName": "_runTest",
101-
"lineNumber": 233,
102-
},
103-
Object {
104-
"columnNumber": 9,
105-
"fileName": "<PROJECT_ROOT>/node_modules/jest-circus/build/run.js",
106-
"functionName": "_runTestsForDescribeBlock",
107-
"lineNumber": 135,
108-
},
109-
Object {
110-
"columnNumber": 9,
111-
"fileName": "<PROJECT_ROOT>/node_modules/jest-circus/build/run.js",
112-
"functionName": "_runTestsForDescribeBlock",
113-
"lineNumber": 130,
114-
},
115-
Object {
116-
"columnNumber": 3,
117-
"fileName": "<PROJECT_ROOT>/node_modules/jest-circus/build/run.js",
118-
"functionName": "run",
119-
"lineNumber": 68,
120-
},
121-
Object {
122-
"columnNumber": 21,
123-
"fileName": "<PROJECT_ROOT>/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js",
124-
"functionName": "runAndTransformResultsToJestFormat",
125-
"lineNumber": 122,
126-
},
127-
Object {
128-
"columnNumber": 19,
129-
"fileName": "<PROJECT_ROOT>/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js",
130-
"functionName": "jestAdapter",
131-
"lineNumber": 79,
132-
},
133-
Object {
134-
"columnNumber": 16,
135-
"fileName": "<PROJECT_ROOT>/node_modules/jest-runner/build/runTest.js",
136-
"functionName": "runTestInternal",
137-
"lineNumber": 367,
138-
},
139-
Object {
140-
"columnNumber": 34,
141-
"fileName": "<PROJECT_ROOT>/node_modules/jest-runner/build/runTest.js",
142-
"functionName": "runTest",
143-
"lineNumber": 444,
144-
},
145-
],
72+
"stack": Any<Array>,
14673
"text": "Error string passed to reporter Message from new Error",
14774
"type": "UNKNOWN",
14875
}
@@ -157,7 +84,7 @@ Object {
15784
},
15885
"docsUrl": "https://gatsby.dev/debug-html",
15986
"level": "ERROR",
160-
"stack": Array [],
87+
"stack": Any<Array>,
16188
"text": "\\"navigator\\" is not available during server-side rendering. Enable \\"DEV_SSR\\" to debug this during \\"gatsby develop\\".",
16289
"type": "HTML.COMPILATION",
16390
}
@@ -171,7 +98,7 @@ Object {
17198
},
17299
"docsUrl": "https://www.gatsbyjs.com/docs/gatsby-cli/#new",
173100
"level": "ERROR",
174-
"stack": Array [],
101+
"stack": Any<Array>,
175102
"text": "Error text is test123",
176103
"type": "PLUGIN",
177104
}
@@ -186,7 +113,7 @@ Object {
186113
"docsUrl": "https://www.gatsbyjs.com/docs/gatsby-cli/#new",
187114
"level": "ERROR",
188115
"pluginName": "gatsby-plugin-foo-bar",
189-
"stack": Array [],
116+
"stack": Any<Array>,
190117
"text": "Error text is test123",
191118
"type": "PLUGIN",
192119
}

packages/gatsby-cli/src/reporter/__tests__/index.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,19 @@ describe(`report.error`, () => {
8383
const generatedError = getErrorMessages(
8484
reporterActions.createLog as jest.Mock
8585
)[0]
86-
expect(generatedError).toMatchSnapshot()
86+
expect(generatedError).toMatchSnapshot({
87+
stack: expect.any(Array),
88+
})
8789
})
8890

8991
it(`handles "String" signature correctly`, () => {
9092
reporter.error(`Error created in Jest`)
9193
const generatedError = getErrorMessages(
9294
reporterActions.createLog as jest.Mock
9395
)[0]
94-
expect(generatedError).toMatchSnapshot()
96+
expect(generatedError).toMatchSnapshot({
97+
stack: expect.any(Array),
98+
})
9599
})
96100

97101
it(`handles "String, Error, pluginName" signature correctly`, () => {
@@ -103,7 +107,9 @@ describe(`report.error`, () => {
103107
const generatedError = getErrorMessages(
104108
reporterActions.createLog as jest.Mock
105109
)[0]
106-
expect(generatedError).toMatchSnapshot()
110+
expect(generatedError).toMatchSnapshot({
111+
stack: expect.any(Array),
112+
})
107113
})
108114

109115
it(`sets an error map if setErrorMap is called`, () => {
@@ -136,7 +142,9 @@ describe(`report.error`, () => {
136142
const generatedError = getErrorMessages(
137143
reporterActions.createLog as jest.Mock
138144
)[0]
139-
expect(generatedError).toMatchSnapshot()
145+
expect(generatedError).toMatchSnapshot({
146+
stack: expect.any(Array),
147+
})
140148
})
141149

142150
// This is how it's potentially called from api-runner-node.js
@@ -163,6 +171,8 @@ describe(`report.error`, () => {
163171
const generatedError = getErrorMessages(
164172
reporterActions.createLog as jest.Mock
165173
)[0]
166-
expect(generatedError).toMatchSnapshot()
174+
expect(generatedError).toMatchSnapshot({
175+
stack: expect.any(Array),
176+
})
167177
})
168178
})

packages/gatsby-source-contentful/src/__tests__/gatsby-plugin-image.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import _ from "lodash"
88
import { resolve } from "path"
99
import { setFieldsOnGraphQLNodeType } from "../extend-node-type"
1010
import { generateImageSource } from "../gatsby-plugin-image"
11-
import * as gatsbyCoreUtils from "gatsby-core-utils"
11+
import * as fetchRemoteFileModule from "gatsby-core-utils/fetch-remote-file"
1212
import * as pluginSharp from "gatsby-plugin-sharp"
1313

1414
const FIXTURES = resolve(__dirname, `..`, `__fixtures__`)
@@ -20,7 +20,7 @@ jest
2020
.spyOn(pluginSharp, `getDominantColor`)
2121
.mockImplementation(() => Promise.resolve(`#mocked`))
2222
jest
23-
.spyOn(gatsbyCoreUtils, `fetchRemoteFile`)
23+
.spyOn(fetchRemoteFileModule, `fetchRemoteFile`)
2424
.mockImplementation(() =>
2525
Promise.resolve(`${FIXTURES}/contentful-logo-256.png`)
2626
)

0 commit comments

Comments
 (0)