forked from open-cli-tools/concurrently
-
Notifications
You must be signed in to change notification settings - Fork 0
/
expand-npm-wildcard.spec.js
68 lines (54 loc) · 1.78 KB
/
expand-npm-wildcard.spec.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const ExpandNpmWildcard = require('./expand-npm-wildcard');
let parser, readPkg;
beforeEach(() => {
readPkg = jest.fn();
parser = new ExpandNpmWildcard(readPkg);
});
it('returns same command if not an npm run command', () => {
const commandInfo = {
command: 'npm test'
};
expect(readPkg).not.toHaveBeenCalled();
expect(parser.parse(commandInfo)).toBe(commandInfo);
});
it('returns same command if no wildcard present', () => {
const commandInfo = {
command: 'npm run foo bar'
};
expect(readPkg).not.toHaveBeenCalled();
expect(parser.parse(commandInfo)).toBe(commandInfo);
});
it('expands to nothing if no scripts exist in package.json', () => {
readPkg.mockReturnValue({});
expect(parser.parse({ command: 'npm run foo-*-baz qux' })).toEqual([]);
});
it('expands to all scripts matching pattern', () => {
readPkg.mockReturnValue({
scripts: {
'foo-bar-baz': '',
'foo--baz': '',
}
});
expect(parser.parse({ command: 'npm run foo-*-baz qux' })).toEqual([
{ name: 'bar', command: 'npm run foo-bar-baz qux' },
{ name: '', command: 'npm run foo--baz qux' },
]);
});
it('caches scripts upon calls', () => {
readPkg.mockReturnValue({});
parser.parse({ command: 'npm run foo-*-baz qux' });
parser.parse({ command: 'npm run foo-*-baz qux' });
expect(readPkg).toHaveBeenCalledTimes(1);
});
it('suffix name with wildcard values', () => {
readPkg.mockReturnValue({
scripts: {
'watch-foo': '',
'watch-bar': '',
}
});
expect(parser.parse({ name: 'w:', command: 'npm run watch-*' })).toEqual([
{ name: 'w:foo', command: 'npm run watch-foo' },
{ name: 'w:bar', command: 'npm run watch-bar' },
]);
});