Skip to content

Commit

Permalink
Set the correct interval when changing spinner (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeetiss authored and sindresorhus committed Sep 14, 2019
1 parent 38c2be9 commit ad324dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Expand Up @@ -64,6 +64,10 @@ 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 Down
14 changes: 14 additions & 0 deletions test.js
Expand Up @@ -269,6 +269,20 @@ test('reset frameIndex when setting new spinner', async t => {
t.regex(stripAnsi(await output), /foo baz/);
});

test('reset interval when setting new spinner', t => {
const spinner = new Ora({
isEnabled: false,
spinner: {frames: ['foo', 'bar']},
interval: 300
});

t.is(spinner.interval, 300);

spinner.spinner = {frames: ['baz'], interval: 200};

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

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

Expand Down

0 comments on commit ad324dc

Please sign in to comment.