mirror of
https://github.com/bitbaum/orangecat.git
synced 2026-12-05 01:08:23 +01:00
The suite ran EVERY file in a jsdom environment. Its own numbers: Duration 1257s — environment 2285s, setup 465s, import 318s, tests 166s Actual test execution was 166 seconds. The dominant term was constructing a fake DOM for API-route, service and domain tests that never use one — 240 of 291 files. Now node by default; the 51 files that need a DOM declare it per-file with `// @vitest-environment jsdom`. Full suite after: 291 files, 2719 tests, 0 failures, environment 2285s -> 307s. A controlled A/B on one unchanged directory (23 files, 177 tests) isolates the effect from machine load: environment 178s -> 0.03s, wall 120s -> 84s. This runs on every push (the pre-push hook) and in CI, so it is paid constantly. NOT environmentMatchGlobs, which is the obvious one-line version: Vitest 4 ignores it SILENTLY — no warning, no error. It ran every component test under node and failed 20 of them, and the only reason that was caught is that a .tsx test was checked afterwards rather than trusting the clean config load. The config now says so, so the next person does not spend the same hour. vitest.setup.ts already guarded its DOM access behind IS_JSDOM, which is what made this safe to do at all. One file needed jsdom for a non-obvious reason and the full run is what caught it: rate-failure-cooldown.test.ts pins browser behaviour of rates.ts, which gates its fetch on `typeof window` — the test never mentions `window`, only the module under test does. Grepping the tests for DOM usage cannot see that; running them can. Claude-Session: https://claude.ai/code/session_019ns25hxd1ExZsmCJz9nNhe Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
73 lines
2.5 KiB
TypeScript
73 lines
2.5 KiB
TypeScript
// @vitest-environment jsdom
|
|
/**
|
|
* Input Component Tests — behavior, not class strings.
|
|
*
|
|
* Same story as Button: the earlier suite asserted "border-border-strong
|
|
* shadow-sm rounded-md" type strings that the design system has since
|
|
* changed. Rewritten 2026-06-03 to test what users care about.
|
|
*/
|
|
|
|
import React, { useState } from 'react';
|
|
import { render, screen, fireEvent } from '@testing-library/react';
|
|
import '@testing-library/jest-dom';
|
|
import Input from '@/components/ui/Input';
|
|
|
|
describe('Input', () => {
|
|
it('renders an input element', () => {
|
|
render(<Input placeholder="email" />);
|
|
expect(screen.getByPlaceholderText('email')).toBeInTheDocument();
|
|
});
|
|
|
|
it('passes className through', () => {
|
|
render(<Input className="my-class" placeholder="x" />);
|
|
expect(screen.getByPlaceholderText('x')).toHaveClass('my-class');
|
|
});
|
|
|
|
it('reflects the type prop', () => {
|
|
render(<Input type="email" placeholder="email" />);
|
|
expect(screen.getByPlaceholderText('email')).toHaveAttribute('type', 'email');
|
|
});
|
|
|
|
it('fires onChange and reflects the typed value', () => {
|
|
function Wrapper() {
|
|
const [v, setV] = useState('');
|
|
return <Input placeholder="x" value={v} onChange={e => setV(e.target.value)} />;
|
|
}
|
|
render(<Wrapper />);
|
|
const input = screen.getByPlaceholderText('x');
|
|
fireEvent.change(input, { target: { value: 'hello' } });
|
|
expect(input).toHaveValue('hello');
|
|
});
|
|
|
|
it('reflects disabled', () => {
|
|
render(<Input disabled placeholder="x" />);
|
|
expect(screen.getByPlaceholderText('x')).toBeDisabled();
|
|
});
|
|
|
|
it('reflects required', () => {
|
|
render(<Input required placeholder="x" />);
|
|
expect(screen.getByPlaceholderText('x')).toBeRequired();
|
|
});
|
|
|
|
it('reflects readOnly', () => {
|
|
render(<Input readOnly value="locked" placeholder="x" />);
|
|
expect(screen.getByPlaceholderText('x')).toHaveAttribute('readonly');
|
|
});
|
|
|
|
it('forwards refs to the underlying input element', () => {
|
|
const ref = React.createRef<HTMLInputElement>();
|
|
render(<Input ref={ref} placeholder="x" />);
|
|
expect(ref.current).toBeInstanceOf(HTMLInputElement);
|
|
});
|
|
|
|
it('renders an error message when provided', () => {
|
|
render(<Input placeholder="x" error="Required" />);
|
|
expect(screen.getByText('Required')).toBeInTheDocument();
|
|
});
|
|
|
|
it('forwards aria attributes for accessibility', () => {
|
|
render(<Input placeholder="x" aria-label="email address" />);
|
|
expect(screen.getByLabelText('email address')).toBeInTheDocument();
|
|
});
|
|
});
|