Skip to content

Commit 5a89430

Browse files
committed
test: resolve function-form next config in browser-stubs test
withPostHogConfig wraps the export as a config function, so the test must resolve it to the object form before accessing .webpack.
1 parent 405e455 commit 5a89430

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

tests/integration/e2b-browser-stubs.test.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { NextConfig } from 'next'
2+
import { PHASE_PRODUCTION_BUILD } from 'next/constants'
13
import { describe, expect, it } from 'vitest'
24
import 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+
1730
describe('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

Comments
 (0)