frontend/.pnpm-store/v3/files/2f/7ce2d6d0dd32202d7b9c6deeac517621151e28a74a81bfa15509acc3930ddfae725ac96502027fbf56e2e115dcd7b8387329ba80c7d377861ae622011b5f9b

59 lines
1.8 KiB
Plaintext

import test from 'ava';
import sinon from 'sinon';
import Spinner from '../lib/spinner.js';
import Config from '../lib/config.js';
test.beforeEach(t => {
t.context.ora = sinon.spy();
});
const getConfig = options => {
const testConfig = {
ci: false,
config: false
};
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.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.callCount, 1);
t.is(ora.firstCall.args[0], task.firstCall.returnValue);
t.is(ora.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.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.callCount, 1);
});