Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the correct interval when changing spinner by name #128

Merged
merged 3 commits into from Sep 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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