mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-23 00:35:51 +00:00
test: add spread+flag axios mock helper to stop CI mock pollution
Bare `mock.module('axios', () => ({ default: { stubs } }))` is
process-global last-write-wins and drops `axios.create`, `request`,
`isAxiosError`, etc. that real consumers need. In CI's alphabetical
file order, that produces dozens of polluted failures (AgentsPlatformView,
schedule API, memory-stores API, etc.) that don't reproduce on WSL2.
Introduce `tests/mocks/axios.ts` with `setupAxiosMock()` — `require('axios')`
inside the factory, spread real shape, route each verb through a per-suite
`useStubs` flag. beforeAll flips on, afterAll flips off; the spread
fall-through eliminates cross-file leakage.
Refactored 12 axios mockers in tests/, plus the bare `@anthropic/ink` mocks
in ultrareviewCommand and onboarding suites (same pollution pattern broke
AgentsPlatformView's Box/Text rendering).
Verified: 5339/5345 tests pass locally; remaining 6 failures are
pre-existing isolation issues unrelated to this change.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,18 @@
|
||||
import { afterEach, beforeEach, describe, expect, mock, test } from 'bun:test';
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, mock, test } from 'bun:test';
|
||||
import * as React from 'react';
|
||||
import { logMock } from '../../../../tests/mocks/log';
|
||||
import { debugMock } from '../../../../tests/mocks/debug';
|
||||
|
||||
// Pre-import real ink so we can fall through after this suite. Bun's
|
||||
// mock.module is process-global / last-write-wins; without delegation the
|
||||
// stub Box/Pane/Text/useTheme leak into other test files (e.g.
|
||||
// AgentsPlatformView.test.tsx) that need real ink components.
|
||||
const _realOnboardingInkMod = (await import('@anthropic/ink')) as Record<string, unknown>;
|
||||
let _useStubInkForOnboarding = true;
|
||||
afterAll(() => {
|
||||
_useStubInkForOnboarding = false;
|
||||
});
|
||||
|
||||
mock.module('bun:bundle', () => ({
|
||||
feature: (_name: string) => false,
|
||||
}));
|
||||
@@ -37,13 +47,20 @@ mock.module('src/utils/config.js', () => ({
|
||||
}));
|
||||
|
||||
// Stub heavy theme + ink imports — the launcher only references them for
|
||||
// the `theme` subcommand JSX render path.
|
||||
mock.module('@anthropic/ink', () => ({
|
||||
Box: ({ children }: { children?: React.ReactNode }) => React.createElement('box', null, children),
|
||||
Pane: ({ children }: { children?: React.ReactNode }) => React.createElement('pane', null, children),
|
||||
Text: ({ children }: { children?: React.ReactNode }) => React.createElement('text', null, children),
|
||||
useTheme: () => ['dark', (_t: string) => undefined],
|
||||
}));
|
||||
// the `theme` subcommand JSX render path. Spread real ink so when the flag
|
||||
// flips off in afterAll, later test files see real components.
|
||||
mock.module('@anthropic/ink', () => {
|
||||
if (_useStubInkForOnboarding) {
|
||||
return {
|
||||
..._realOnboardingInkMod,
|
||||
Box: ({ children }: { children?: React.ReactNode }) => React.createElement('box', null, children),
|
||||
Pane: ({ children }: { children?: React.ReactNode }) => React.createElement('pane', null, children),
|
||||
Text: ({ children }: { children?: React.ReactNode }) => React.createElement('text', null, children),
|
||||
useTheme: () => ['dark', (_t: string) => undefined],
|
||||
};
|
||||
}
|
||||
return _realOnboardingInkMod;
|
||||
});
|
||||
|
||||
mock.module('src/components/ThemePicker.js', () => ({
|
||||
ThemePicker: () => React.createElement('theme-picker'),
|
||||
|
||||
Reference in New Issue
Block a user