Skip to content

Commit 0b6aa27

Browse files
committed
test: fix remaining vitest failures and async leaks; full suite green
- Workflow fixed 14 files: vi.mock default keys, constructor mocks, fake-timer rAF semantics (toFake), runTimersToTime->advanceTimersByTime, ESM mock shapes. - Convert leftover done()-callback async tests to Promise/async form (loadExternalData, useExternalData, withExternalData). - Harden rAF polyfill (window + global) for animejs; clean obsolete snapshots. Result: 93 files / 540 tests passing, 0 failures.
1 parent f08cfc9 commit 0b6aa27

47 files changed

Lines changed: 131 additions & 1138 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/behaviours/DragAndDrop/__mocks__/DragPreview.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
const position = vi.fn();
44
const cleanup = vi.fn();
55

6-
const DragPreview = vi.fn(() => ({
7-
position,
8-
cleanup,
9-
}));
6+
function DragPreviewMock() {
7+
return {
8+
position,
9+
cleanup,
10+
};
11+
}
12+
13+
const DragPreview = vi.fn(DragPreviewMock);
1014

1115
export {
1216
position,

src/behaviours/DragAndDrop/__tests__/DropObstacle.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import DropObstacle from '../DropObstacle';
88

99
vi.mock('../store');
1010
vi.mock('../reducer');
11-
vi.useFakeTimers();
11+
// Exclude requestAnimationFrame from the faked APIs so the global polyfill
12+
// (setTimeout(cb, 1)) drives the frame loop, matching the original Jest timing.
13+
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'Date'] });
1214

1315
const mockProps = {
1416
id: 'foo',
@@ -53,7 +55,7 @@ describe('DropObstacle', () => {
5355
});
5456

5557
it('upserts obstacle with UPSERT_OBSTACLE on interval', () => {
56-
vi.runTimersToTime(1000);
58+
vi.advanceTimersByTime(1000);
5759
expect(actions.upsertObstacle.mock.calls.length).toEqual(10); // 10 fps
5860
});
5961
});

src/behaviours/DragAndDrop/__tests__/DropTarget.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import DropTarget from '../DropTarget';
88

99
vi.mock('../store');
1010
vi.mock('../reducer');
11-
vi.useFakeTimers();
11+
// Don't fake requestAnimationFrame so the setup polyfill (setTimeout-based) is
12+
// used; Vitest's faked rAF advances by frame budget, throwing off the fps count.
13+
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
1214

1315
const mockProps = {
1416
id: 'foo',
@@ -53,7 +55,7 @@ describe('DropTarget', () => {
5355
});
5456

5557
it('upserts target with UPSERT_TARGET on interval', () => {
56-
vi.runTimersToTime(1000);
58+
vi.advanceTimersByTime(1000);
5759
expect(actions.upsertTarget.mock.calls.length).toEqual(10); // 10 fps
5860
});
5961
});

src/components/Canvas/__tests__/__snapshots__/EdgeLayout.test.js.snap

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,3 @@ exports[`<EdgeLayout /> > renders ok 1`] = `
2929
</svg>
3030
</div>
3131
`;
32-
33-
exports[`<EdgeLayout /> renders ok 1`] = `
34-
<div
35-
className="edge-layout"
36-
>
37-
<svg
38-
preserveAspectRatio="none"
39-
viewBox="0 0 100 100"
40-
xmlns="http://www.w3.org/2000/svg"
41-
>
42-
<Connect(Edge)
43-
from={
44-
Object {
45-
"x": 100,
46-
"y": 100,
47-
}
48-
}
49-
key="foo_bar_baz"
50-
to={
51-
Object {
52-
"x": 100,
53-
"y": 100,
54-
}
55-
}
56-
type="type"
57-
viewBoxScale={100}
58-
/>
59-
</svg>
60-
</div>
61-
`;

src/components/Canvas/__tests__/__snapshots__/NodeLayout.test.js.snap

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/components/__tests__/__snapshots__/Audio.test.js.snap

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,3 @@ exports[`<Audio /> > renders ok 1`] = `
88
bar
99
</audio>
1010
`;
11-
12-
exports[`<Audio /> renders ok 1`] = `
13-
<audio
14-
miscellaneousAdditionalProperty="baz"
15-
src="foo"
16-
>
17-
bar
18-
</audio>
19-
`;

src/components/__tests__/__snapshots__/BackgroundImage.test.js.snap

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,3 @@ exports[`<BackgroundImage /> > renders ok 1`] = `
1111
}
1212
/>
1313
`;
14-
15-
exports[`<BackgroundImage /> renders ok 1`] = `
16-
<div
17-
miscellaneousAdditionalProperty="baz"
18-
style={
19-
Object {
20-
"backgroundImage": "url(foo)",
21-
"width": "100%",
22-
}
23-
}
24-
/>
25-
`;

src/components/__tests__/__snapshots__/Card.test.js.snap

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -94,98 +94,3 @@ exports[`Card component > renders unselected card 1`] = `
9494
</div>
9595
</div>
9696
`;
97-
98-
exports[`Card component renders selected card 1`] = `
99-
<div
100-
className="card card--selected"
101-
onClick={null}
102-
>
103-
<svg
104-
className="card__indicator"
105-
viewBox="0 0 100 100"
106-
x="0px"
107-
xmlns="http://www.w3.org/2000/svg"
108-
y="0px"
109-
>
110-
<path
111-
d="M100,50c0,27.6-22.4,50-50,50s-50-22.4-50-50S22.5,0,50,0S100,22.4,100,50z M50,8.3C27,8.3,8.4,27,8.4,50S27,91.6,50,91.6 S91.7,73,91.7,50S73,8.3,50,8.3z"
112-
/>
113-
<polygon
114-
className="tick"
115-
points="30.8,43 45.3,57.2 69,32.1 77.4,40.6 46.3,73.8 22.7,51.6"
116-
/>
117-
</svg>
118-
<div>
119-
<h1
120-
className="card__label"
121-
>
122-
name
123-
</h1>
124-
<div
125-
className="card__attributes"
126-
>
127-
<h5
128-
className="card__attribute"
129-
key="0"
130-
>
131-
age
132-
:
133-
134-
33
135-
</h5>
136-
<h5
137-
className="card__attribute"
138-
key="1"
139-
>
140-
fullname
141-
:
142-
143-
full name
144-
</h5>
145-
</div>
146-
</div>
147-
</div>
148-
`;
149-
150-
exports[`Card component renders unselected card 1`] = `
151-
<div
152-
className="card"
153-
onClick={null}
154-
>
155-
<svg
156-
className="card__indicator"
157-
viewBox="0 0 100 100"
158-
x="0px"
159-
xmlns="http://www.w3.org/2000/svg"
160-
y="0px"
161-
>
162-
<path
163-
d="M100,50c0,27.6-22.4,50-50,50s-50-22.4-50-50S22.5,0,50,0S100,22.4,100,50z M50,8.3C27,8.3,8.4,27,8.4,50S27,91.6,50,91.6 S91.7,73,91.7,50S73,8.3,50,8.3z"
164-
/>
165-
<polygon
166-
className="tick"
167-
points="30.8,43 45.3,57.2 69,32.1 77.4,40.6 46.3,73.8 22.7,51.6"
168-
/>
169-
</svg>
170-
<div>
171-
<h1
172-
className="card__label"
173-
>
174-
name
175-
</h1>
176-
<div
177-
className="card__attributes"
178-
>
179-
<h5
180-
className="card__attribute"
181-
key="0"
182-
>
183-
age
184-
:
185-
186-
33
187-
</h5>
188-
</div>
189-
</div>
190-
</div>
191-
`;

src/components/__tests__/__snapshots__/CardList.test.js.snap

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -55,60 +55,3 @@ exports[`CardList component > renders cards with list 1`] = `
5555
/>
5656
</ContextProvider>
5757
`;
58-
59-
exports[`CardList component renders cards with list 1`] = `
60-
<ContextProvider
61-
value={
62-
Object {
63-
"store": Object {
64-
"@@observable": [Function],
65-
"dispatch": [Function],
66-
"getState": [Function],
67-
"replaceReducer": [Function],
68-
"subscribe": [Function],
69-
},
70-
"subscription": Object {
71-
"addNestedSub": [Function],
72-
"getListeners": [Function],
73-
"handleChangeWrapper": [Function],
74-
"isSubscribed": [Function],
75-
"notifyNestedSubs": [Function],
76-
"onStateChange": [Function],
77-
"trySubscribe": [Function],
78-
"tryUnsubscribe": [Function],
79-
},
80-
}
81-
}
82-
>
83-
<CardList
84-
className=""
85-
details={[Function]}
86-
getKey={[Function]}
87-
isItemSelected={[Function]}
88-
items={Array []}
89-
label={[Function]}
90-
nodes={
91-
Array [
92-
Object {
93-
"age": "22",
94-
"name": "a name",
95-
"uid": "a",
96-
},
97-
Object {
98-
"age": "88",
99-
"name": "b name",
100-
"uid": "b",
101-
},
102-
Object {
103-
"age": "33",
104-
"name": "c name",
105-
"uid": "c",
106-
},
107-
]
108-
}
109-
onItemClick={[Function]}
110-
onToggleCard={[Function]}
111-
selected={[Function]}
112-
/>
113-
</ContextProvider>
114-
`;

src/components/__tests__/__snapshots__/CategoricalItem.test.js.snap

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,39 +35,3 @@ exports[`CategoricalItem component > renders unexpanded categorical item 1`] = `
3535
</div>
3636
</FlippedWithContext>
3737
`;
38-
39-
exports[`CategoricalItem component renders unexpanded categorical item 1`] = `
40-
<FlippedWithContext>
41-
<div
42-
className="categorical-item"
43-
onClick={[Function]}
44-
style={
45-
Object {
46-
"--categorical-item-color": "black",
47-
}
48-
}
49-
>
50-
<div
51-
className="categorical-item__disk"
52-
/>
53-
<div
54-
className="categorical-item__inner"
55-
>
56-
<FlippedWithContext
57-
scale={true}
58-
>
59-
<div
60-
className="categorical-item__title"
61-
>
62-
<h3>
63-
<Memo(MarkdownLabel)
64-
inline={true}
65-
label="undefined"
66-
/>
67-
</h3>
68-
</div>
69-
</FlippedWithContext>
70-
</div>
71-
</div>
72-
</FlippedWithContext>
73-
`;

0 commit comments

Comments
 (0)