Skip to content

Commit

Permalink
Chore: replace sinon with vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed May 20, 2023
1 parent 85e1e98 commit 13f8025
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 131 deletions.
1 change: 0 additions & 1 deletion packages/inquirer/package.json
Expand Up @@ -51,7 +51,6 @@
"node": ">=14.18.0"
},
"devDependencies": {
"sinon": "^15.1.0",
"terminal-link": "^3.0.0"
},
"repository": {
Expand Down
36 changes: 15 additions & 21 deletions packages/inquirer/test/specs/inquirer.test.js
Expand Up @@ -7,7 +7,6 @@ import os from 'node:os';
import stream from 'node:stream';
import tty from 'node:tty';
import { vi, expect, beforeEach, afterEach, describe, it } from 'vitest';
import sinon from 'sinon';
import { Observable } from 'rxjs';

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

describe('inquirer.prompt', () => {
const sandbox = sinon.createSandbox();
let prompt;

beforeEach(() => {
prompt = inquirer.createPromptModule();
});

afterEach(() => {
sandbox.restore();
});

it("should close and create a new readline instances each time it's called", async () => {
const promise = prompt({
type: 'confirm',
Expand All @@ -35,13 +29,13 @@ describe('inquirer.prompt', () => {
});

const rl1 = promise.ui.rl;
sandbox.spy(rl1, 'close');
sandbox.spy(rl1.output, 'end');
vi.spyOn(rl1, 'close');
vi.spyOn(rl1.output, 'end');
rl1.emit('line');

return promise.then(() => {
expect(rl1.close.calledOnce).toEqual(true);
expect(rl1.output.end.calledOnce).toEqual(true);
expect(rl1.close).toHaveBeenCalledTimes(1);
expect(rl1.output.end).toHaveBeenCalledTimes(1);

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

const rl2 = promise2.ui.rl;
sandbox.spy(rl2, 'close');
sandbox.spy(rl2.output, 'end');
vi.spyOn(rl2, 'close');
vi.spyOn(rl2.output, 'end');
rl2.emit('line');

return promise2.then(() => {
expect(rl2.close.calledOnce).toEqual(true);
expect(rl2.output.end.calledOnce).toEqual(true);
expect(rl2.close).toHaveBeenCalledTimes(1);
expect(rl2.output.end).toHaveBeenCalledTimes(1);

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

const rl1 = promise.ui.rl;
sandbox.spy(rl1, 'close');
sandbox.spy(rl1.output, 'end');
vi.spyOn(rl1, 'close');
vi.spyOn(rl1.output, 'end');

promise.catch(() => {
expect(rl1.close.calledOnce).toEqual(true);
expect(rl1.output.end.calledOnce).toEqual(true);
expect(rl1.close).toHaveBeenCalledTimes(1);
expect(rl1.output.end).toHaveBeenCalledTimes(1);
done();
});
}));
Expand Down Expand Up @@ -400,13 +394,13 @@ describe('inquirer.prompt', () => {
];

const promise = prompt(prompts);
const spy = sinon.spy();
const spy = vi.fn();
promise.ui.process.subscribe(
spy,
() => {},
() => {
sinon.assert.calledWith(spy, { name: 'name1', answer: 'bar' });
sinon.assert.calledWith(spy, { name: 'name', answer: 'doe' });
expect(spy).toHaveBeenCalledWith({ name: 'name1', answer: 'bar' });
expect(spy).toHaveBeenCalledWith({ name: 'name', answer: 'doe' });
done();
}
);
Expand Down
10 changes: 4 additions & 6 deletions packages/inquirer/test/specs/prompts/checkbox.test.js
@@ -1,8 +1,6 @@
import { beforeEach, describe, it } from 'vitest';
import { expect } from 'vitest';
import { vi, expect, beforeEach, describe, it } from 'vitest';
import ReadlineStub from '../../helpers/readline.js';
import fixtures from '../../helpers/fixtures.js';
import sinon from 'sinon';

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

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

// 'a\n\n': 0th index, but pagination at 2nd index position due to 2 extra newlines
expect(realIndexPosition1).toEqual(2);
Expand Down
16 changes: 7 additions & 9 deletions packages/inquirer/test/specs/prompts/list.test.js
@@ -1,8 +1,6 @@
import { beforeEach, describe, it } from 'vitest';
import { expect } from 'vitest';
import { vi, expect, beforeEach, describe, it } from 'vitest';
import ReadlineStub from '../../helpers/readline.js';
import fixtures from '../../helpers/fixtures.js';
import sinon from 'sinon';

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

Expand Down Expand Up @@ -229,10 +227,10 @@ describe('`list` prompt', () => {
choices: ['a\n\n', 'b\n\n'],
};
const list = new List(multilineFixture, rl);
const spy = sinon.spy(list.paginator, 'paginate');
const spy = vi.spyOn(list.paginator, 'paginate');
list.run().then((answer) => {
const realIndexPosition1 = spy.firstCall.args[1];
const realIndexPosition2 = spy.secondCall.args[1];
const realIndexPosition1 = spy.mock.calls[0][1];
const realIndexPosition2 = spy.mock.calls[1][1];

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

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

list.run().then(() => {
const spyCall = fixture.filter.getCall(0);
expect(spyCall.args[1]).toEqual(answers);
const spyCall = fixture.filter.mock.calls[0];
expect(spyCall[1]).toEqual(answers);
done();
});

Expand Down
96 changes: 2 additions & 94 deletions yarn.lock
Expand Up @@ -825,48 +825,6 @@
resolved "https://registry.yarnpkg.com/@sindresorhus/tsconfig/-/tsconfig-3.0.1.tgz#e2eaebda42aa7a755b11bdfbea847446652e1ac4"
integrity sha512-0/gtPNTY3++0J2BZM5nHHULg0BIMw886gqdn8vWN+Av6bgF5ZU2qIcHubAn+Z9KNvJhO8WFE+9kDOU3n6OcKtA==

"@sinonjs/commons@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-2.0.0.tgz#fd4ca5b063554307e8327b4564bd56d3b73924a3"
integrity sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==
dependencies:
type-detect "4.0.8"

"@sinonjs/commons@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-3.0.0.tgz#beb434fe875d965265e04722ccfc21df7f755d72"
integrity sha512-jXBtWAF4vmdNmZgD5FoKsVLv3rPgDnLgPbU84LIJ3otV44vJlDRokVng5v8NFJdCf/da9legHcKaRuZs4L7faA==
dependencies:
type-detect "4.0.8"

"@sinonjs/fake-timers@^10.0.2":
version "10.0.2"
resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-10.0.2.tgz#d10549ed1f423d80639c528b6c7f5a1017747d0c"
integrity sha512-SwUDyjWnah1AaNl7kxsa7cfLhlTYoiyhDAIgyh+El30YvXs/o7OLXpYH88Zdhyx9JExKrmHDJ+10bwIcY80Jmw==
dependencies:
"@sinonjs/commons" "^2.0.0"

"@sinonjs/fake-timers@^10.2.0":
version "10.2.0"
resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-10.2.0.tgz#b3e322a34c5f26e3184e7f6115695f299c1b1194"
integrity sha512-OPwQlEdg40HAj5KNF8WW6q2KG4Z+cBCZb3m4ninfTZKaBmbIJodviQsDBoYMPHkOyJJMHnOJo5j2+LKDOhOACg==
dependencies:
"@sinonjs/commons" "^3.0.0"

"@sinonjs/samsam@^8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-8.0.0.tgz#0d488c91efb3fa1442e26abea81759dfc8b5ac60"
integrity sha512-Bp8KUVlLp8ibJZrnvq2foVhP0IVX2CIprMJPK0vqGqgrDa0OHVKeZyBykqskkrdxV6yKBPmGasO8LVjAKR3Gew==
dependencies:
"@sinonjs/commons" "^2.0.0"
lodash.get "^4.4.2"
type-detect "^4.0.8"

"@sinonjs/text-encoding@^0.7.1":
version "0.7.1"
resolved "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz"
integrity sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==

"@tootallnate/once@2":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-2.0.0.tgz#f544a148d3ab35801c1f633a7441fd87c2e484bf"
Expand Down Expand Up @@ -2073,11 +2031,6 @@ diff@^4.0.1:
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==

diff@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-5.1.0.tgz#bc52d298c5ea8df9194800224445ed43ffc87e40"
integrity sha512-D+mk+qE8VC/PAUrlAU34N+VfXev0ghe5ywmpqrawphmVZc1bEfn56uo9qpyGp1p4xpzOHkSW4ztBd6L7Xx4ACw==

dir-glob@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f"
Expand Down Expand Up @@ -3349,11 +3302,6 @@ is-wsl@^2.2.0:
dependencies:
is-docker "^2.0.0"

isarray@0.0.1:
version "0.0.1"
resolved "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz"
integrity sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=

isarray@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
Expand Down Expand Up @@ -3514,11 +3462,6 @@ just-diff@^6.0.0:
resolved "https://registry.yarnpkg.com/just-diff/-/just-diff-6.0.2.tgz#03b65908543ac0521caf6d8eb85035f7d27ea285"
integrity sha512-S59eriX5u3/QhMNq3v/gm8Kd0w8OS6Tz2FS1NG4blv+z0MuQcBRJyFWjdovM0Rad4/P4aUPFtnkNjMjyMlMSYA==

just-extend@^4.0.2:
version "4.2.1"
resolved "https://registry.npmjs.org/just-extend/-/just-extend-4.2.1.tgz"
integrity sha512-g3UB796vUFIY90VIv/WX3L2c8CS2MdWUww3CNrYmqza1Fg0DURc2K/O4YrnklBdQarSJ/y8JnJYDGc+1iumQjg==

kind-of@^6.0.2, kind-of@^6.0.3:
version "6.0.3"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd"
Expand Down Expand Up @@ -3733,11 +3676,6 @@ locate-path@^6.0.0:
dependencies:
p-locate "^5.0.0"

lodash.get@^4.4.2:
version "4.4.2"
resolved "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz"
integrity sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=

lodash.ismatch@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz#756cb5150ca3ba6f11085a78849645f188f85f37"
Expand Down Expand Up @@ -4175,17 +4113,6 @@ neo-async@^2.6.0:
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f"
integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==

nise@^5.1.4:
version "5.1.4"
resolved "https://registry.yarnpkg.com/nise/-/nise-5.1.4.tgz#491ce7e7307d4ec546f5a659b2efe94a18b4bbc0"
integrity sha512-8+Ib8rRJ4L0o3kfmyVCL7gzrohyDe0cMFTBa2d364yIrEGMEoetznKJx899YxjybU6bL9SQkYPSBBs1gyYs8Xg==
dependencies:
"@sinonjs/commons" "^2.0.0"
"@sinonjs/fake-timers" "^10.0.2"
"@sinonjs/text-encoding" "^0.7.1"
just-extend "^4.0.2"
path-to-regexp "^1.7.0"

node-addon-api@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-3.2.1.tgz#81325e0a2117789c0128dab65e7e38f07ceba161"
Expand Down Expand Up @@ -4810,13 +4737,6 @@ path-scurry@^1.6.1, path-scurry@^1.7.0:
lru-cache "^9.1.1"
minipass "^5.0.0"

path-to-regexp@^1.7.0:
version "1.8.0"
resolved "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz"
integrity sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==
dependencies:
isarray "0.0.1"

path-type@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/path-type/-/path-type-3.0.0.tgz#cef31dc8e0a1a3bb0d105c0cd97cf3bf47f4e36f"
Expand Down Expand Up @@ -5407,18 +5327,6 @@ sigstore@^1.0.0, sigstore@^1.3.0, sigstore@^1.4.0:
make-fetch-happen "^11.0.1"
tuf-js "^1.1.3"

sinon@^15.1.0:
version "15.1.0"
resolved "https://registry.yarnpkg.com/sinon/-/sinon-15.1.0.tgz#87656841545f7c63bd1e291df409fafd0e9aec09"
integrity sha512-cS5FgpDdE9/zx7no8bxROHymSlPLZzq0ChbbLk1DrxBfc+eTeBK3y8nIL+nu/0QeYydhhbLIr7ecHJpywjQaoQ==
dependencies:
"@sinonjs/commons" "^3.0.0"
"@sinonjs/fake-timers" "^10.2.0"
"@sinonjs/samsam" "^8.0.0"
diff "^5.1.0"
nise "^5.1.4"
supports-color "^7.2.0"

slash@3.0.0, slash@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634"
Expand Down Expand Up @@ -5669,7 +5577,7 @@ supports-color@^5.3.0:
dependencies:
has-flag "^3.0.0"

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

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

0 comments on commit 13f8025

Please sign in to comment.