You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Seems next/jest.js calls some sort of internal environmental setup function for http/https "agents" that ends up changing the nature of the Request object; specifically: spreading the Request object functions differently. This occurs when calling nextJest in const createJestConfig = nextJest({ dir: './' }) where nextJest is defined as import nextJest from 'next/jest.js'. When the dir option is omitted, the discussed error does not occur.
Drilling into what the function returned by calling createJestConfig in const jestConfig = await createJestConfig(config)() is actually doing, we get the following stack:
constjestConfig=awaitcreateJestConfig(config)()
constcreateJestConfig=nextJest({// Provide the path to your Next.js app to load next.config.js and .env files in your test environmentdir: './'});
functionnextJest(options={}){// createJestConfigreturn(customJestConfig)=>{// Function that is provided as the module.exports of jest.config.js// Will be called and awaited by Jestreturnasync()=>{
...
if(options.dir){constresolvedDir=(0,_path.resolve)(options.dir);constpackageConfig=loadClosestPackageJson(resolvedDir);isEsmProject=packageConfig.type==="module";nextConfig=awaitgetConfig(resolvedDir);
...
This is the function that, once executed, somehow subtly changes what @whatwg-node/server's createServerAdapter() returns:
functionsetHttpClientAndAgentOptions(config){if(globalThis.__NEXT_HTTP_AGENT){// We only need to assign once because we want// to reuse the same agent for all requests.return;}if(!config){thrownewError("Expected config.httpAgentOptions to be an object");}globalThis.__NEXT_HTTP_AGENT_OPTIONS=config.httpAgentOptions;globalThis.__NEXT_HTTP_AGENT=new_http.Agent(config.httpAgentOptions);globalThis.__NEXT_HTTPS_AGENT=new_https.Agent(config.httpAgentOptions);}
Rather than investigate this further, it seems whatever is going on is not really an NTARH issue. The solution here is to just explicitly declare/reference each valid property in the Request constructor's options parameter instead of trying to spread the Request instance to grab its properties.
The text was updated successfully, but these errors were encountered:
Xunnamius
changed the title
NTARH is incompatible with next/jest.js (and/or SWC)
Potential NTARH incompatibility with next/jest.js (and/or SWC)
Mar 2, 2024
Xunnamius
changed the title
Potential NTARH incompatibility with next/jest.js (and/or SWC)
Potential NTARH incompatibility with next/jest.jsMar 2, 2024
As discussed in #983.
Seems
next/jest.js
calls some sort of internal environmental setup function for http/https "agents" that ends up changing the nature of theRequest
object; specifically: spreading the Request object functions differently. This occurs when callingnextJest
inconst createJestConfig = nextJest({ dir: './' })
wherenextJest
is defined asimport nextJest from 'next/jest.js'
. When thedir
option is omitted, the discussed error does not occur.Drilling into what the function returned by calling
createJestConfig
inconst jestConfig = await createJestConfig(config)()
is actually doing, we get the following stack:This is the function that, once executed, somehow subtly changes what
@whatwg-node/server
'screateServerAdapter()
returns:Rather than investigate this further, it seems whatever is going on is not really an NTARH issue. The solution here is to just explicitly declare/reference each valid property in the
Request
constructor'soptions
parameter instead of trying to spread theRequest
instance to grab its properties.The text was updated successfully, but these errors were encountered: