1+ import type { NextConfig } from 'next'
2+ import { PHASE_PRODUCTION_BUILD } from 'next/constants'
13import { describe , expect , it } from 'vitest'
24import nextConfig from '../../next.config'
35
@@ -14,14 +16,26 @@ class MockNormalModuleReplacementPlugin {
1416 }
1517}
1618
19+ // withPostHogConfig wraps the config as a function; resolve it to the object form.
20+ type NextConfigFn = (
21+ phase : string ,
22+ ctx : { defaultConfig : NextConfig }
23+ ) => Promise < NextConfig >
24+
25+ const resolveNextConfig = ( ) =>
26+ ( nextConfig as unknown as NextConfigFn ) ( PHASE_PRODUCTION_BUILD , {
27+ defaultConfig : { } ,
28+ } )
29+
1730describe ( 'E2B browser module stubs' , ( ) => {
18- it ( 'aliases node built-ins after webpack strips node: scheme requests' , ( ) => {
31+ it ( 'aliases node built-ins after webpack strips node: scheme requests' , async ( ) => {
32+ const resolved = await resolveNextConfig ( )
1933 const webpackConfig = {
2034 resolve : { alias : { } as Record < string , string > } ,
2135 plugins : [ ] as MockNormalModuleReplacementPlugin [ ] ,
2236 }
2337
24- nextConfig . webpack ?.( webpackConfig , {
38+ resolved . webpack ?.( webpackConfig , {
2539 isServer : false ,
2640 webpack : {
2741 NormalModuleReplacementPlugin : MockNormalModuleReplacementPlugin ,
@@ -53,13 +67,14 @@ describe('E2B browser module stubs', () => {
5367 )
5468 } )
5569
56- it ( 'does not rewrite server webpack builds' , ( ) => {
70+ it ( 'does not rewrite server webpack builds' , async ( ) => {
71+ const resolved = await resolveNextConfig ( )
5772 const webpackConfig = {
5873 resolve : { alias : { } as Record < string , string > } ,
5974 plugins : [ ] as MockNormalModuleReplacementPlugin [ ] ,
6075 }
6176
62- nextConfig . webpack ?.( webpackConfig , {
77+ resolved . webpack ?.( webpackConfig , {
6378 isServer : true ,
6479 webpack : {
6580 NormalModuleReplacementPlugin : MockNormalModuleReplacementPlugin ,
0 commit comments