Skip to content

Commit

Permalink
Downgrade chalk & migrate ora usage
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Dec 1, 2021
1 parent ee36d7b commit a6bb29b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/spinner.js
@@ -1,12 +1,12 @@
import ora from 'ora';
import { oraPromise } from 'ora';
import { format } from './util.js';

const noop = Promise.resolve();

class Spinner {
constructor({ container = {} } = {}) {
this.config = container.config;
this.ora = container.ora || ora;
this.ora = container.ora || oraPromise;
}
show({ enabled = true, task, label, external = false, context }) {
if (!enabled) return noop;
Expand All @@ -19,7 +19,7 @@ class Spinner {

if (!this.isSpinnerDisabled || (external && this.canForce)) {
const text = format(label, context);
this.ora.promise(awaitTask, text);
this.ora(awaitTask, text);
}

return awaitTask;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -64,7 +64,7 @@
"@iarna/toml": "2.2.5",
"@octokit/rest": "18.12.0",
"async-retry": "1.3.3",
"chalk": "5.0.0",
"chalk": "4.1.2",
"cosmiconfig": "7.0.1",
"debug": "4.3.3",
"deprecated-obj": "2.0.0",
Expand Down
16 changes: 7 additions & 9 deletions test/spinner.js
Expand Up @@ -4,9 +4,7 @@ import Spinner from '../lib/spinner.js';
import Config from '../lib/config.js';

test.beforeEach(t => {
t.context.ora = {
promise: sinon.spy()
};
t.context.ora = sinon.spy();
});

const getConfig = options => {
Expand All @@ -24,7 +22,7 @@ test('should not show spinner and not execute task if disabled', async t => {
const spinner = new Spinner({ container: { ora } });
await spinner.show({ enabled: false, task });
t.is(task.callCount, 0);
t.is(ora.promise.callCount, 0);
t.is(ora.callCount, 0);
});

test('should show spinner and run task by default', async t => {
Expand All @@ -35,9 +33,9 @@ test('should show spinner and run task by default', async t => {
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);
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 => {
Expand All @@ -47,7 +45,7 @@ test('should run task, but not show spinner if interactive', async t => {
const spinner = new Spinner({ container: { ora, config } });
await spinner.show({ task });
t.is(task.callCount, 1);
t.is(ora.promise.callCount, 0);
t.is(ora.callCount, 0);
});

test('should run task and show spinner if interactive, but external', async t => {
Expand All @@ -57,5 +55,5 @@ test('should run task and show spinner if interactive, but external', async t =>
const spinner = new Spinner({ container: { ora, config } });
await spinner.show({ task, external: true });
t.is(task.callCount, 1);
t.is(ora.promise.callCount, 1);
t.is(ora.callCount, 1);
});

0 comments on commit a6bb29b

Please sign in to comment.