frontend/.pnpm-store/v3/files/52/b31969050d5be1a2d7b8d16e4bb95a0913d5e0d08f1b4552fbce4c431d0ef278eb3c02fa56cc79ccd8d65c91b24226659339366c80b18534428b644006c58c

62 lines
1.9 KiB
Plaintext

const test = require('ava');
const sinon = require('sinon');
const Spinner = require('../lib/spinner');
const Config = require('../lib/config');
test.beforeEach(t => {
t.context.ora = {
promise: sinon.spy()
};
});
const getConfig = options => {
const testConfig = {
ci: false,
config: false,
'disable-metrics': true
};
return new Config(Object.assign({}, testConfig, options));
};
test('should not show spinner and not execute task if disabled', async t => {
const { ora } = t.context;
const task = sinon.spy();
const spinner = new Spinner({ container: { ora } });
await spinner.show({ enabled: false, task });
t.is(task.callCount, 0);
t.is(ora.promise.callCount, 0);
});
test('should show spinner and run task by default', async t => {
const { ora } = t.context;
const task = sinon.stub().resolves();
const label = 'foo';
const config = getConfig({ ci: true });
const spinner = new Spinner({ container: { ora, config } });
await spinner.show({ task, label });
t.is(task.callCount, 1);
t.is(ora.promise.callCount, 1);
t.is(ora.promise.firstCall.args[0], task.firstCall.returnValue);
t.is(ora.promise.firstCall.args[1], label);
});
test('should run task, but not show spinner if interactive', async t => {
const { ora } = t.context;
const task = sinon.stub().resolves();
const config = getConfig({ ci: false });
const spinner = new Spinner({ container: { ora, config } });
await spinner.show({ task });
t.is(task.callCount, 1);
t.is(ora.promise.callCount, 0);
});
test('should run task and show spinner if interactive, but external', async t => {
const { ora } = t.context;
const task = sinon.stub().resolves();
const config = getConfig({ ci: false });
const spinner = new Spinner({ container: { ora, config } });
await spinner.show({ task, external: true });
t.is(task.callCount, 1);
t.is(ora.promise.callCount, 1);
});