Skip to content

Commit 13f8025

Browse files
committed
Chore: replace sinon with vitest
1 parent 85e1e98 commit 13f8025

File tree

5 files changed

+28
-131
lines changed

5 files changed

+28
-131
lines changed

packages/inquirer/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"node": ">=14.18.0"
5252
},
5353
"devDependencies": {
54-
"sinon": "^15.1.0",
5554
"terminal-link": "^3.0.0"
5655
},
5756
"repository": {

packages/inquirer/test/specs/inquirer.test.js

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import os from 'node:os';
77
import stream from 'node:stream';
88
import tty from 'node:tty';
99
import { vi, expect, beforeEach, afterEach, describe, it } from 'vitest';
10-
import sinon from 'sinon';
1110
import { Observable } from 'rxjs';
1211

1312
import inquirer from '../../lib/inquirer.js';
@@ -16,17 +15,12 @@ import { autosubmit } from '../helpers/events.js';
1615
const ostype = os.type();
1716

1817
describe('inquirer.prompt', () => {
19-
const sandbox = sinon.createSandbox();
2018
let prompt;
2119

2220
beforeEach(() => {
2321
prompt = inquirer.createPromptModule();
2422
});
2523

26-
afterEach(() => {
27-
sandbox.restore();
28-
});
29-
3024
it("should close and create a new readline instances each time it's called", async () => {
3125
const promise = prompt({
3226
type: 'confirm',
@@ -35,13 +29,13 @@ describe('inquirer.prompt', () => {
3529
});
3630

3731
const rl1 = promise.ui.rl;
38-
sandbox.spy(rl1, 'close');
39-
sandbox.spy(rl1.output, 'end');
32+
vi.spyOn(rl1, 'close');
33+
vi.spyOn(rl1.output, 'end');
4034
rl1.emit('line');
4135

4236
return promise.then(() => {
43-
expect(rl1.close.calledOnce).toEqual(true);
44-
expect(rl1.output.end.calledOnce).toEqual(true);
37+
expect(rl1.close).toHaveBeenCalledTimes(1);
38+
expect(rl1.output.end).toHaveBeenCalledTimes(1);
4539

4640
const promise2 = prompt({
4741
type: 'confirm',
@@ -50,13 +44,13 @@ describe('inquirer.prompt', () => {
5044
});
5145

5246
const rl2 = promise2.ui.rl;
53-
sandbox.spy(rl2, 'close');
54-
sandbox.spy(rl2.output, 'end');
47+
vi.spyOn(rl2, 'close');
48+
vi.spyOn(rl2.output, 'end');
5549
rl2.emit('line');
5650

5751
return promise2.then(() => {
58-
expect(rl2.close.calledOnce).toEqual(true);
59-
expect(rl2.output.end.calledOnce).toEqual(true);
52+
expect(rl2.close).toHaveBeenCalledTimes(1);
53+
expect(rl2.output.end).toHaveBeenCalledTimes(1);
6054

6155
expect(rl1).not.toEqual(rl2);
6256
});
@@ -73,12 +67,12 @@ describe('inquirer.prompt', () => {
7367
});
7468

7569
const rl1 = promise.ui.rl;
76-
sandbox.spy(rl1, 'close');
77-
sandbox.spy(rl1.output, 'end');
70+
vi.spyOn(rl1, 'close');
71+
vi.spyOn(rl1.output, 'end');
7872

7973
promise.catch(() => {
80-
expect(rl1.close.calledOnce).toEqual(true);
81-
expect(rl1.output.end.calledOnce).toEqual(true);
74+
expect(rl1.close).toHaveBeenCalledTimes(1);
75+
expect(rl1.output.end).toHaveBeenCalledTimes(1);
8276
done();
8377
});
8478
}));
@@ -400,13 +394,13 @@ describe('inquirer.prompt', () => {
400394
];
401395

402396
const promise = prompt(prompts);
403-
const spy = sinon.spy();
397+
const spy = vi.fn();
404398
promise.ui.process.subscribe(
405399
spy,
406400
() => {},
407401
() => {
408-
sinon.assert.calledWith(spy, { name: 'name1', answer: 'bar' });
409-
sinon.assert.calledWith(spy, { name: 'name', answer: 'doe' });
402+
expect(spy).toHaveBeenCalledWith({ name: 'name1', answer: 'bar' });
403+
expect(spy).toHaveBeenCalledWith({ name: 'name', answer: 'doe' });
410404
done();
411405
}
412406
);

packages/inquirer/test/specs/prompts/checkbox.test.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { beforeEach, describe, it } from 'vitest';
2-
import { expect } from 'vitest';
1+
import { vi, expect, beforeEach, describe, it } from 'vitest';
32
import ReadlineStub from '../../helpers/readline.js';
43
import fixtures from '../../helpers/fixtures.js';
5-
import sinon from 'sinon';
64

75
import Checkbox from '../../../lib/prompts/checkbox.js';
86

@@ -205,10 +203,10 @@ describe('`checkbox` prompt', () => {
205203
choices: ['a\n\n', 'b\n\n'],
206204
};
207205
const list = new Checkbox(multilineFixture, rl);
208-
const spy = sinon.spy(list.paginator, 'paginate');
206+
const spy = vi.spyOn(list.paginator, 'paginate');
209207
list.run().then((answer) => {
210-
const realIndexPosition1 = spy.firstCall.args[1];
211-
const realIndexPosition2 = spy.secondCall.args[1];
208+
const realIndexPosition1 = spy.mock.calls[0][1];
209+
const realIndexPosition2 = spy.mock.calls[1][1];
212210

213211
// 'a\n\n': 0th index, but pagination at 2nd index position due to 2 extra newlines
214212
expect(realIndexPosition1).toEqual(2);

packages/inquirer/test/specs/prompts/list.test.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { beforeEach, describe, it } from 'vitest';
2-
import { expect } from 'vitest';
1+
import { vi, expect, beforeEach, describe, it } from 'vitest';
32
import ReadlineStub from '../../helpers/readline.js';
43
import fixtures from '../../helpers/fixtures.js';
5-
import sinon from 'sinon';
64

75
import List from '../../../lib/prompts/list.js';
86

@@ -229,10 +227,10 @@ describe('`list` prompt', () => {
229227
choices: ['a\n\n', 'b\n\n'],
230228
};
231229
const list = new List(multilineFixture, rl);
232-
const spy = sinon.spy(list.paginator, 'paginate');
230+
const spy = vi.spyOn(list.paginator, 'paginate');
233231
list.run().then((answer) => {
234-
const realIndexPosition1 = spy.firstCall.args[1];
235-
const realIndexPosition2 = spy.secondCall.args[1];
232+
const realIndexPosition1 = spy.mock.calls[0][1];
233+
const realIndexPosition2 = spy.mock.calls[1][1];
236234

237235
// 'a\n\n': 0th index, but pagination at 2nd index position due to 2 extra newlines
238236
expect(realIndexPosition1).toEqual(2);
@@ -263,13 +261,13 @@ describe('`list` prompt', () => {
263261
fixture.filter = function () {
264262
return true;
265263
};
266-
sinon.spy(fixture, 'filter');
264+
vi.spyOn(fixture, 'filter');
267265

268266
const list = new List(fixture, rl, answers);
269267

270268
list.run().then(() => {
271-
const spyCall = fixture.filter.getCall(0);
272-
expect(spyCall.args[1]).toEqual(answers);
269+
const spyCall = fixture.filter.mock.calls[0];
270+
expect(spyCall[1]).toEqual(answers);
273271
done();
274272
});
275273

yarn.lock

Lines changed: 2 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -825,48 +825,6 @@
825825
resolved "https://registry.yarnpkg.com/@sindresorhus/tsconfig/-/tsconfig-3.0.1.tgz#e2eaebda42aa7a755b11bdfbea847446652e1ac4"
826826
integrity sha512-0/gtPNTY3++0J2BZM5nHHULg0BIMw886gqdn8vWN+Av6bgF5ZU2qIcHubAn+Z9KNvJhO8WFE+9kDOU3n6OcKtA==
827827

828-
"@sinonjs/commons@^2.0.0":
829-
version "2.0.0"
830-
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-2.0.0.tgz#fd4ca5b063554307e8327b4564bd56d3b73924a3"
831-
integrity sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==
832-
dependencies:
833-
type-detect "4.0.8"
834-
835-
"@sinonjs/commons@^3.0.0":
836-
version "3.0.0"
837-
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-3.0.0.tgz#beb434fe875d965265e04722ccfc21df7f755d72"
838-
integrity sha512-jXBtWAF4vmdNmZgD5FoKsVLv3rPgDnLgPbU84LIJ3otV44vJlDRokVng5v8NFJdCf/da9legHcKaRuZs4L7faA==
839-
dependencies:
840-
type-detect "4.0.8"
841-
842-
"@sinonjs/fake-timers@^10.0.2":
843-
version "10.0.2"
844-
resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-10.0.2.tgz#d10549ed1f423d80639c528b6c7f5a1017747d0c"
845-
integrity sha512-SwUDyjWnah1AaNl7kxsa7cfLhlTYoiyhDAIgyh+El30YvXs/o7OLXpYH88Zdhyx9JExKrmHDJ+10bwIcY80Jmw==
846-
dependencies:
847-
"@sinonjs/commons" "^2.0.0"
848-
849-
"@sinonjs/fake-timers@^10.2.0":
850-
version "10.2.0"
851-
resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-10.2.0.tgz#b3e322a34c5f26e3184e7f6115695f299c1b1194"
852-
integrity sha512-OPwQlEdg40HAj5KNF8WW6q2KG4Z+cBCZb3m4ninfTZKaBmbIJodviQsDBoYMPHkOyJJMHnOJo5j2+LKDOhOACg==
853-
dependencies:
854-
"@sinonjs/commons" "^3.0.0"
855-
856-
"@sinonjs/samsam@^8.0.0":
857-
version "8.0.0"
858-
resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-8.0.0.tgz#0d488c91efb3fa1442e26abea81759dfc8b5ac60"
859-
integrity sha512-Bp8KUVlLp8ibJZrnvq2foVhP0IVX2CIprMJPK0vqGqgrDa0OHVKeZyBykqskkrdxV6yKBPmGasO8LVjAKR3Gew==
860-
dependencies:
861-
"@sinonjs/commons" "^2.0.0"
862-
lodash.get "^4.4.2"
863-
type-detect "^4.0.8"
864-
865-
"@sinonjs/text-encoding@^0.7.1":
866-
version "0.7.1"
867-
resolved "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz"
868-
integrity sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==
869-
870828
"@tootallnate/once@2":
871829
version "2.0.0"
872830
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-2.0.0.tgz#f544a148d3ab35801c1f633a7441fd87c2e484bf"
@@ -2073,11 +2031,6 @@ diff@^4.0.1:
20732031
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
20742032
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
20752033

2076-
diff@^5.1.0:
2077-
version "5.1.0"
2078-
resolved "https://registry.yarnpkg.com/diff/-/diff-5.1.0.tgz#bc52d298c5ea8df9194800224445ed43ffc87e40"
2079-
integrity sha512-D+mk+qE8VC/PAUrlAU34N+VfXev0ghe5ywmpqrawphmVZc1bEfn56uo9qpyGp1p4xpzOHkSW4ztBd6L7Xx4ACw==
2080-
20812034
dir-glob@^3.0.1:
20822035
version "3.0.1"
20832036
resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f"
@@ -3349,11 +3302,6 @@ is-wsl@^2.2.0:
33493302
dependencies:
33503303
is-docker "^2.0.0"
33513304

3352-
isarray@0.0.1:
3353-
version "0.0.1"
3354-
resolved "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz"
3355-
integrity sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=
3356-
33573305
isarray@~1.0.0:
33583306
version "1.0.0"
33593307
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
@@ -3514,11 +3462,6 @@ just-diff@^6.0.0:
35143462
resolved "https://registry.yarnpkg.com/just-diff/-/just-diff-6.0.2.tgz#03b65908543ac0521caf6d8eb85035f7d27ea285"
35153463
integrity sha512-S59eriX5u3/QhMNq3v/gm8Kd0w8OS6Tz2FS1NG4blv+z0MuQcBRJyFWjdovM0Rad4/P4aUPFtnkNjMjyMlMSYA==
35163464

3517-
just-extend@^4.0.2:
3518-
version "4.2.1"
3519-
resolved "https://registry.npmjs.org/just-extend/-/just-extend-4.2.1.tgz"
3520-
integrity sha512-g3UB796vUFIY90VIv/WX3L2c8CS2MdWUww3CNrYmqza1Fg0DURc2K/O4YrnklBdQarSJ/y8JnJYDGc+1iumQjg==
3521-
35223465
kind-of@^6.0.2, kind-of@^6.0.3:
35233466
version "6.0.3"
35243467
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd"
@@ -3733,11 +3676,6 @@ locate-path@^6.0.0:
37333676
dependencies:
37343677
p-locate "^5.0.0"
37353678

3736-
lodash.get@^4.4.2:
3737-
version "4.4.2"
3738-
resolved "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz"
3739-
integrity sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=
3740-
37413679
lodash.ismatch@^4.4.0:
37423680
version "4.4.0"
37433681
resolved "https://registry.yarnpkg.com/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz#756cb5150ca3ba6f11085a78849645f188f85f37"
@@ -4175,17 +4113,6 @@ neo-async@^2.6.0:
41754113
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f"
41764114
integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==
41774115

4178-
nise@^5.1.4:
4179-
version "5.1.4"
4180-
resolved "https://registry.yarnpkg.com/nise/-/nise-5.1.4.tgz#491ce7e7307d4ec546f5a659b2efe94a18b4bbc0"
4181-
integrity sha512-8+Ib8rRJ4L0o3kfmyVCL7gzrohyDe0cMFTBa2d364yIrEGMEoetznKJx899YxjybU6bL9SQkYPSBBs1gyYs8Xg==
4182-
dependencies:
4183-
"@sinonjs/commons" "^2.0.0"
4184-
"@sinonjs/fake-timers" "^10.0.2"
4185-
"@sinonjs/text-encoding" "^0.7.1"
4186-
just-extend "^4.0.2"
4187-
path-to-regexp "^1.7.0"
4188-
41894116
node-addon-api@^3.2.1:
41904117
version "3.2.1"
41914118
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-3.2.1.tgz#81325e0a2117789c0128dab65e7e38f07ceba161"
@@ -4810,13 +4737,6 @@ path-scurry@^1.6.1, path-scurry@^1.7.0:
48104737
lru-cache "^9.1.1"
48114738
minipass "^5.0.0"
48124739

4813-
path-to-regexp@^1.7.0:
4814-
version "1.8.0"
4815-
resolved "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz"
4816-
integrity sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==
4817-
dependencies:
4818-
isarray "0.0.1"
4819-
48204740
path-type@^3.0.0:
48214741
version "3.0.0"
48224742
resolved "https://registry.yarnpkg.com/path-type/-/path-type-3.0.0.tgz#cef31dc8e0a1a3bb0d105c0cd97cf3bf47f4e36f"
@@ -5407,18 +5327,6 @@ sigstore@^1.0.0, sigstore@^1.3.0, sigstore@^1.4.0:
54075327
make-fetch-happen "^11.0.1"
54085328
tuf-js "^1.1.3"
54095329

5410-
sinon@^15.1.0:
5411-
version "15.1.0"
5412-
resolved "https://registry.yarnpkg.com/sinon/-/sinon-15.1.0.tgz#87656841545f7c63bd1e291df409fafd0e9aec09"
5413-
integrity sha512-cS5FgpDdE9/zx7no8bxROHymSlPLZzq0ChbbLk1DrxBfc+eTeBK3y8nIL+nu/0QeYydhhbLIr7ecHJpywjQaoQ==
5414-
dependencies:
5415-
"@sinonjs/commons" "^3.0.0"
5416-
"@sinonjs/fake-timers" "^10.2.0"
5417-
"@sinonjs/samsam" "^8.0.0"
5418-
diff "^5.1.0"
5419-
nise "^5.1.4"
5420-
supports-color "^7.2.0"
5421-
54225330
slash@3.0.0, slash@^3.0.0:
54235331
version "3.0.0"
54245332
resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634"
@@ -5669,7 +5577,7 @@ supports-color@^5.3.0:
56695577
dependencies:
56705578
has-flag "^3.0.0"
56715579

5672-
supports-color@^7.0.0, supports-color@^7.1.0, supports-color@^7.2.0:
5580+
supports-color@^7.0.0, supports-color@^7.1.0:
56735581
version "7.2.0"
56745582
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da"
56755583
integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==
@@ -5909,7 +5817,7 @@ type-check@^0.4.0, type-check@~0.4.0:
59095817
dependencies:
59105818
prelude-ls "^1.2.1"
59115819

5912-
type-detect@4.0.8, type-detect@^4.0.0, type-detect@^4.0.5, type-detect@^4.0.8:
5820+
type-detect@^4.0.0, type-detect@^4.0.5:
59135821
version "4.0.8"
59145822
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
59155823
integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==

0 commit comments

Comments
 (0)