Skip to content

Commit b684665

Browse files
committed
replace sinon with vitest's built in spy/mock library
fixes an incompatibility between the newly added `ChaiStyleAssertions` by vitest v4.1, and the `sinon-chai` plugin we used previously closes #12056
1 parent 8f704ce commit b684665

File tree

20 files changed

+105
-215
lines changed

20 files changed

+105
-215
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ _Breaking developer changes, which may affect downstream projects or sites that
4747
#### :hourglass: Performance
4848
#### :mortar_board: Walkthrough / Help
4949
#### :hammer: Development
50+
* Replace `sinon` with `vitest`'s built in spy/mock library ([#12058])
51+
52+
[#12058]: https://github.com/openstreetmap/iD/pull/12058
5053

5154

5255
# 2.39.2

package-lock.json

Lines changed: 0 additions & 124 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@
135135
"serve-handler": "^6.1.6",
136136
"shelljs": "^0.10.0",
137137
"shx": "^0.4.0",
138-
"sinon": "^21.0.0",
139-
"sinon-chai": "^4.0.1",
140138
"svg-sprite": "2.0.4",
141139
"typescript": "^5.9.3",
142140
"typescript-eslint": "^8.56.0",

test/spec/core/history.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { fn } from '@vitest/spy';
12
import { setTimeout } from 'node:timers/promises';
23
import { clear } from 'idb-keyval';
34
import { asyncPrefs } from '../../../modules/core/preferences';
@@ -14,7 +15,7 @@ describe('iD.coreHistory', function () {
1415
beforeEach(function () {
1516
context = iD.coreContext().assetPath('../dist/').init();
1617
history = context.history();
17-
spy = sinon.spy();
18+
spy = fn();
1819
});
1920

2021
describe('#graph', function () {
@@ -57,13 +58,12 @@ describe('iD.coreHistory', function () {
5758
it('emits a change event', function () {
5859
history.on('change', spy);
5960
var difference = history.perform(actionNoop);
60-
expect(spy).to.have.been.calledWith(difference);
61-
expect(spy.callCount).to.eql(1);
61+
expect(spy).to.have.been.calledOnceWith(difference);
6262
});
6363

6464
it('performs multiple actions', function () {
65-
var action1 = sinon.stub().returns(iD.coreGraph());
66-
var action2 = sinon.stub().returns(iD.coreGraph());
65+
const action1 = fn().mockReturnValue(iD.coreGraph());
66+
const action2 = fn().mockReturnValue(iD.coreGraph());
6767
history.perform(action1, action2, 'annotation');
6868
expect(action1).to.have.been.called;
6969
expect(action2).to.have.been.called;
@@ -76,7 +76,7 @@ describe('iD.coreHistory', function () {
7676
history.on('change', spy);
7777
await history.perform(action1);
7878
await setTimeout(300);
79-
expect(spy.callCount).to.be.above(2);
79+
expect(spy.mock.calls.length).to.be.above(2);
8080
});
8181
});
8282

@@ -104,8 +104,8 @@ describe('iD.coreHistory', function () {
104104
});
105105

106106
it('performs multiple actions', function () {
107-
var action1 = sinon.stub().returns(iD.coreGraph());
108-
var action2 = sinon.stub().returns(iD.coreGraph());
107+
const action1 = fn().mockReturnValue(iD.coreGraph());
108+
const action2 = fn().mockReturnValue(iD.coreGraph());
109109
history.replace(action1, action2, 'annotation');
110110
expect(action1).to.have.been.called;
111111
expect(action2).to.have.been.called;

test/spec/presets/field.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { spyOn } from '@vitest/spy';
2+
13
describe('iD.presetField', function() {
24
describe('#references', function() {
35
it('references label and terms of another field', function() {
@@ -8,15 +10,15 @@ describe('iD.presetField', function() {
810
allFields.preset = field;
911

1012
// mock localizer
11-
sinon.spy(other, 't');
12-
sinon.spy(field, 't');
13+
spyOn(other, 't');
14+
spyOn(field, 't');
1315

1416
field.title();
1517
expect(other.t).to.have.been.calledOnce;
1618
expect(field.t).not.to.have.been.called;
1719

18-
other.t.resetHistory();
19-
field.t.resetHistory();
20+
other.t.mockClear();
21+
field.t.mockClear();
2022

2123
field.terms();
2224
expect(other.t).to.have.been.calledOnce;
@@ -31,8 +33,8 @@ describe('iD.presetField', function() {
3133
allFields.preset = field;
3234

3335
// mock localizer
34-
sinon.spy(other, 't');
35-
sinon.spy(field, 't');
36+
spyOn(other, 't');
37+
spyOn(field, 't');
3638

3739
field.placeholder();
3840
expect(other.t).to.have.been.calledOnce;
@@ -47,9 +49,9 @@ describe('iD.presetField', function() {
4749
allFields.preset = field;
4850

4951
// mock localizer
50-
sinon.spy(other.t, 'append');
51-
sinon.spy(field.t, 'append');
52-
sinon.stub(other, 'hasTextForStringId').returns(true);
52+
spyOn(other.t, 'append');
53+
spyOn(field.t, 'append');
54+
spyOn(other, 'hasTextForStringId').mockReturnValue(true);
5355

5456
var context = iD.coreContext().assetPath('../dist/').init();
5557
var uiField = iD.uiFieldCombo(field, context);

0 commit comments

Comments
 (0)