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 f0bac45 commit 85e1e98
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
22 changes: 11 additions & 11 deletions packages/inquirer/test/helpers/readline.js
@@ -1,21 +1,21 @@
import { EventEmitter } from 'node:events';
import sinon from 'sinon';
import { vi } from 'vitest';
import util from 'node:util';

const stub = {};

Object.assign(stub, {
write: sinon.stub().returns(stub),
moveCursor: sinon.stub().returns(stub),
setPrompt: sinon.stub().returns(stub),
close: sinon.stub().returns(stub),
pause: sinon.stub().returns(stub),
resume: sinon.stub().returns(stub),
_getCursorPos: sinon.stub().returns({ cols: 0, rows: 0 }),
write: vi.fn(() => stub),
moveCursor: vi.fn(() => stub),
setPrompt: vi.fn(() => stub),
close: vi.fn(() => stub),
pause: vi.fn(() => stub),
resume: vi.fn(() => stub),
_getCursorPos: vi.fn(() => ({ cols: 0, rows: 0 })),
output: {
end: sinon.stub(),
mute: sinon.stub(),
unmute: sinon.stub(),
end: vi.fn(),
mute: vi.fn(),
unmute: vi.fn(),
__raw__: '',
write(str) {
this.__raw__ += str;
Expand Down
26 changes: 12 additions & 14 deletions packages/inquirer/test/specs/inquirer.test.js
Expand Up @@ -6,8 +6,7 @@ import fs from 'node:fs';
import os from 'node:os';
import stream from 'node:stream';
import tty from 'node:tty';
import { beforeEach, afterEach, describe, it } from 'vitest';
import { expect } from 'vitest';
import { vi, expect, beforeEach, afterEach, describe, it } from 'vitest';
import sinon from 'sinon';
import { Observable } from 'rxjs';

Expand Down Expand Up @@ -176,7 +175,7 @@ describe('inquirer.prompt', () => {
it('should parse `message` if passed as a function', async () => {
const stubMessage = 'foo';
prompt.registerPrompt('stub', function (params) {
this.run = sinon.stub().returns(Promise.resolve());
this.run = vi.fn(() => Promise.resolve());
expect(params.message).toEqual(stubMessage);
});

Expand Down Expand Up @@ -212,7 +211,7 @@ describe('inquirer.prompt', () => {
new Promise((done) => {
const stubMessage = 'foo';
prompt.registerPrompt('stub', function (params) {
this.run = sinon.stub().returns(Promise.resolve());
this.run = vi.fn(() => Promise.resolve());
expect(params.message).toEqual(stubMessage);
done();
});
Expand Down Expand Up @@ -245,7 +244,7 @@ describe('inquirer.prompt', () => {
new Promise((done) => {
const stubDefault = 'foo';
prompt.registerPrompt('stub', function (params) {
this.run = sinon.stub().returns(Promise.resolve());
this.run = vi.fn(() => Promise.resolve());
expect(params.default).toEqual(stubDefault);
done();
});
Expand Down Expand Up @@ -311,7 +310,7 @@ describe('inquirer.prompt', () => {
it('should pass previous answers to the prompt constructor', async () =>
new Promise((done) => {
prompt.registerPrompt('stub', function (params, rl, answers) {
this.run = sinon.stub().returns(Promise.resolve());
this.run = vi.fn(() => Promise.resolve());
expect(answers.name1).toEqual('bar');
done();
});
Expand All @@ -338,7 +337,7 @@ describe('inquirer.prompt', () => {
new Promise((done) => {
const stubChoices = ['foo', 'bar'];
prompt.registerPrompt('stub', function (params) {
this.run = sinon.stub().returns(Promise.resolve());
this.run = vi.fn(() => Promise.resolve());
expect(params.choices).toEqual(stubChoices);
done();
});
Expand Down Expand Up @@ -471,8 +470,7 @@ describe('inquirer.prompt', () => {

it('should provide answers in filter callback for lists', async () =>
new Promise((done) => {
const filter = sinon.stub();
filter.returns('foo');
const filter = vi.fn(() => 'foo');

const prompts = [
{
Expand All @@ -488,10 +486,10 @@ describe('inquirer.prompt', () => {
const promise = prompt(prompts);
promise.ui.rl.emit('line');
promise.then(() => {
const spyCall = filter.getCall(0);
const spyCalls = filter.mock.calls[0];

expect(spyCall.args[0]).toEqual('foo');
expect(spyCall.args[1]).toBeTypeOf('object');
expect(spyCalls[0]).toEqual('foo');
expect(spyCalls[1]).toBeTypeOf('object');
done();
});
}));
Expand Down Expand Up @@ -795,7 +793,7 @@ describe('inquirer.prompt', () => {
inquirer.registerPrompt('foo', function (question, rl, answers) {
expect(question).toEqual(questions[0]);
expect(answers).toEqual({});
this.run = sinon.stub().returns(Promise.resolve());
this.run = vi.fn(() => Promise.resolve());
done();
});

Expand All @@ -806,7 +804,7 @@ describe('inquirer.prompt', () => {
new Promise((done) => {
const questions = [{ type: 'confirm', message: 'something' }];
inquirer.registerPrompt('confirm', function () {
this.run = sinon.stub().returns(Promise.resolve());
this.run = vi.fn(() => Promise.resolve());
done();
});

Expand Down

0 comments on commit 85e1e98

Please sign in to comment.