Skip to content

Commit 9c1c96e

Browse files
committed
Fix typecheck and pre-existing test failures
- cli/src/pre-init/tree-sitter-wasm.ts: silence TS error for the bun-only `with { type: 'file' }` import (TS resolves the .wasm via the package's exports map and has no loader for binary assets). - cli/src/__tests__/integration-tmux.test.ts: explicitly clear FREEBUFF_MODE from the tmux global env before running. A prior freebuff build or `bun run dev:freebuff` in the same tmux server leaves it set, which made the help-output test see the freebuff CLI variant (no `--agent` flag) instead of codebuff. - web/jest.config.cjs: fix react/react-dom moduleNameMapper paths — they pointed at `web/node_modules/react` but bun hoists react to the workspace root. - web/jest.setup.js: polyfill TextEncoder/TextDecoder, ReadableStream, Request/Response/Headers/fetch from Node + undici. JSDOM lacks these globals, and undici (loaded transitively via `next/server`) needs them at module-load time.
1 parent e814093 commit 9c1c96e

4 files changed

Lines changed: 33 additions & 2 deletions

File tree

cli/src/__tests__/integration-tmux.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ describe.skipIf(!tmuxAvailable || !sdkBuilt)(
6969
}),
7070
),
7171
)
72+
// Clear FREEBUFF_MODE from the tmux global env. A previous freebuff
73+
// build or `bun run dev:freebuff` invocation in the same tmux server
74+
// can leave it set globally, which would make this test see the
75+
// freebuff CLI variant (which has no `--agent` flag).
76+
await tmux(['set-environment', '-gu', 'FREEBUFF_MODE']).catch(() => {})
7277
}
7378
})
7479

cli/src/pre-init/tree-sitter-wasm.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// per the package's split `import`/`require` exports map — returns the build-time
88
// absolute path of `tree-sitter.cjs` and fails on user machines.
99

10+
// @ts-expect-error - Bun's `with { type: 'file' }` returns a string path; TS resolves
11+
// the .wasm file via web-tree-sitter's exports map and has no loader for it.
1012
import treeSitterWasmPath from 'web-tree-sitter/tree-sitter.wasm' with {
1113
type: 'file',
1214
}

web/jest.config.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const config = {
1313
'^@codebuff/internal/env$': '<rootDir>/../packages/internal/src/env.ts',
1414
'^@codebuff/internal/xml-parser$': '<rootDir>/src/test-stubs/xml-parser.ts',
1515
'^bun:test$': '<rootDir>/src/test-stubs/bun-test.ts',
16-
'^react$': '<rootDir>/node_modules/react',
17-
'^react-dom$': '<rootDir>/node_modules/react-dom',
16+
'^react$': '<rootDir>/../node_modules/react',
17+
'^react-dom$': '<rootDir>/../node_modules/react-dom',
1818
},
1919
// Bun-specific tests that use top-level await or bun:test features
2020
testPathIgnorePatterns: [

web/jest.setup.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,25 @@
11
import '@testing-library/jest-dom'
2+
import { TextDecoder, TextEncoder } from 'node:util'
3+
import { ReadableStream, WritableStream, TransformStream } from 'node:stream/web'
4+
5+
// JSDOM lacks Node's Web API globals — undici (loaded transitively via
6+
// `next/server` and `openai`) needs these at module-load time.
7+
if (typeof globalThis.TextEncoder === 'undefined') {
8+
globalThis.TextEncoder = TextEncoder
9+
}
10+
if (typeof globalThis.TextDecoder === 'undefined') {
11+
globalThis.TextDecoder = TextDecoder
12+
}
13+
if (typeof globalThis.ReadableStream === 'undefined') {
14+
globalThis.ReadableStream = ReadableStream
15+
globalThis.WritableStream = WritableStream
16+
globalThis.TransformStream = TransformStream
17+
}
18+
if (typeof globalThis.Request === 'undefined') {
19+
const undici = require('undici')
20+
globalThis.Request = undici.Request
21+
globalThis.Response = undici.Response
22+
globalThis.Headers = undici.Headers
23+
globalThis.fetch = undici.fetch
24+
globalThis.FormData = undici.FormData
25+
}

0 commit comments

Comments
 (0)