Skip to content

Commit

Permalink
Set the correct interval when changing spinner by name (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeetiss authored and sindresorhus committed Sep 23, 2019
1 parent b4ed2e8 commit 4a8cd09
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
12 changes: 8 additions & 4 deletions index.js
Expand Up @@ -59,6 +59,12 @@ class Ora {
this._indent = indent;
}

_updateInterval(interval) {
if (interval !== undefined) {
this.interval = interval;
}
}

get spinner() {
return this._spinner;
}
Expand All @@ -71,10 +77,6 @@ class Ora {
throw new Error('The given spinner must have a `frames` property');
}

if (spinner.interval !== undefined) {
this.interval = spinner.interval;
}

this._spinner = spinner;
} else if (process.platform === 'win32') {
this._spinner = cliSpinners.line;
Expand All @@ -86,6 +88,8 @@ class Ora {
} else {
throw new Error(`There is no built-in spinner named '${spinner}'. See https://github.com/sindresorhus/cli-spinners/blob/master/spinners.json for a full list.`);
}

this._updateInterval(this._spinner.interval);
}

get text() {
Expand Down
16 changes: 15 additions & 1 deletion test.js
Expand Up @@ -269,7 +269,7 @@ test('reset frameIndex when setting new spinner', async t => {
t.regex(stripAnsi(await output), /foo baz/);
});

test('reset interval when setting new spinner', t => {
test('set the correct interval when changing spinner (object case)', t => {
const spinner = new Ora({
isEnabled: false,
spinner: {frames: ['foo', 'bar']},
Expand All @@ -283,6 +283,20 @@ test('reset interval when setting new spinner', t => {
t.is(spinner.interval, 200);
});

test('set the correct interval when changing spinner (string case)', t => {
const spinner = new Ora({
isEnabled: false,
spinner: 'dots',
interval: 100
});

t.is(spinner.interval, 100);

spinner.spinner = 'layer';

t.is(spinner.interval, 150);
});

test('throw when incorrect spinner', t => {
const ora = new Ora();

Expand Down

0 comments on commit 4a8cd09

Please sign in to comment.