Skip to content

Commit 3dc02a3

Browse files
committed
feat: strict type for log
1 parent 7001133 commit 3dc02a3

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

lib/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ const parseEnv = env => {
162162
* Helper to normalize String and Objects with { name, description } when logging out.
163163
*
164164
* @param {String | CompletionItem} item - Item to normalize
165-
* @param {String} shell
165+
* @param {SupportedShell} shell
166166
* @returns {CompletionItem} normalized items
167167
*/
168168
const completionItem = (item, shell) => {
@@ -198,9 +198,9 @@ const completionItem = (item, shell) => {
198198
*
199199
* @param {Array.<CompletionItem | String>} args to log, Strings or Objects with name and
200200
* description property.
201-
* @param {String} shell
201+
* @param {SupportedShell} shell
202202
*/
203-
const log = (args, shell = systemShell()) => {
203+
const log = (args, shell) => {
204204
if (!Array.isArray(args)) {
205205
throw new Error('log: Invalid arguments, must be an array');
206206
}

test/log.js

+5-20
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,24 @@ describe('tabtab.log', () => {
5454
});
5555

5656
it('tabtab.log normalize String and Objects, with description stripped out on Bash', () => {
57-
const shell = process.env.SHELL;
58-
process.env.SHELL = '/bin/bash';
5957
const logs = logTestHelper([
6058
{ name: '--foo', description: 'Foo options' },
6159
{ name: '--bar', description: 'Bar option' },
6260
'foobar',
6361
'barfoo:barfoo is not foobar'
64-
]);
62+
], 'bash');
6563

6664
assert.equal(logs.length, 4);
6765
assert.deepStrictEqual(logs, ['--foo', '--bar', 'foobar', 'barfoo']);
68-
process.env.SHELL = shell;
6966
});
7067

7168
it('tabtab.log with description NOT stripped out on Zsh', () => {
72-
const shell = process.env.SHELL;
73-
process.env.SHELL = '/usr/bin/zsh';
7469
const logs = logTestHelper([
7570
{ name: '--foo', description: 'Foo option' },
7671
{ name: '--bar', description: 'Bar option' },
7772
'foobar',
7873
'barfoo:barfoo is not foobar'
79-
]);
74+
], 'zsh');
8075

8176
assert.equal(logs.length, 4);
8277
assert.deepStrictEqual(logs, [
@@ -85,18 +80,15 @@ describe('tabtab.log', () => {
8580
'foobar',
8681
'barfoo:barfoo is not foobar'
8782
]);
88-
process.env.SHELL = shell;
8983
});
9084

9185
it('tabtab.log with description NOT stripped out on fish', () => {
92-
const shell = process.env.SHELL;
93-
process.env.SHELL = '/usr/bin/fish';
9486
const logs = logTestHelper([
9587
{ name: '--foo', description: 'Foo option' },
9688
{ name: '--bar', description: 'Bar option' },
9789
'foobar',
9890
'barfoo:barfoo is not foobar'
99-
]);
91+
], 'fish');
10092

10193
assert.equal(logs.length, 4);
10294
assert.deepStrictEqual(logs, [
@@ -105,18 +97,15 @@ describe('tabtab.log', () => {
10597
'foobar',
10698
'barfoo\tbarfoo is not foobar'
10799
]);
108-
process.env.SHELL = shell;
109100
});
110101

111102
it('tabtab.log could use {name, description} for completions with ":" in them', () => {
112-
const shell = process.env.SHELL;
113-
process.env.SHELL = '/usr/bin/zsh';
114103
const logs = logTestHelper([
115104
{ name: '--foo:bar', description: 'Foo option' },
116105
{ name: '--bar:foo', description: 'Bar option' },
117106
'foobar',
118107
'barfoo:barfoo is not foobar'
119-
]);
108+
], 'zsh');
120109

121110
assert.equal(logs.length, 4);
122111
assert.deepStrictEqual(logs, [
@@ -125,25 +114,21 @@ describe('tabtab.log', () => {
125114
'foobar',
126115
'barfoo:barfoo is not foobar'
127116
]);
128-
process.env.SHELL = shell;
129117
});
130118

131119
it('tabtab.log should escape ":" when name is given as an object without description', () => {
132-
const shell = process.env.SHELL;
133-
process.env.SHELL = '/usr/bin/zsh';
134120
const logs = logTestHelper([
135121
'foo:bar',
136122
{ name: 'foo:bar' },
137123
{ name: 'foo:bar', description: 'A command' },
138124
{ name: 'foo:bar', description: 'The foo:bar command' }
139-
]);
125+
], 'zsh');
140126

141127
assert.deepStrictEqual(logs, [
142128
'foo:bar',
143129
'foo\\:bar',
144130
'foo\\:bar:A command',
145131
'foo\\:bar:The foo\\:bar command'
146132
]);
147-
process.env.SHELL = shell;
148133
});
149134
});

0 commit comments

Comments
 (0)