/
expand-npm-shortcut.spec.ts
36 lines (31 loc) · 1.18 KB
/
expand-npm-shortcut.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { CommandInfo } from '../command';
import { ExpandNpmShortcut } from './expand-npm-shortcut';
const parser = new ExpandNpmShortcut();
const createCommandInfo = (command: string, name?: string): CommandInfo => ({
name,
command,
});
it('returns same command if no npm: prefix is present', () => {
const commandInfo = createCommandInfo('echo foo');
expect(parser.parse(commandInfo)).toBe(commandInfo);
});
for (const npmCmd of ['npm', 'yarn', 'pnpm']) {
describe(`with ${npmCmd}: prefix`, () => {
it(`expands to "${npmCmd} run <script> <args>"`, () => {
const commandInfo = createCommandInfo(`${npmCmd}:foo -- bar`, 'echo');
expect(parser.parse(commandInfo)).toEqual({
...commandInfo,
name: 'echo',
command: `${npmCmd} run foo -- bar`,
});
});
it('sets name to script name if none', () => {
const commandInfo = createCommandInfo(`${npmCmd}:foo -- bar`);
expect(parser.parse(commandInfo)).toEqual({
...commandInfo,
name: 'foo',
command: `${npmCmd} run foo -- bar`,
});
});
});
}