forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpackage-manager_spec.ts
More file actions
54 lines (45 loc) · 1.72 KB
/
package-manager_spec.ts
File metadata and controls
54 lines (45 loc) · 1.72 KB
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
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { Host } from './host';
import { PackageManager } from './package-manager';
import { SUPPORTED_PACKAGE_MANAGERS } from './package-manager-descriptor';
import { MockHost } from './testing/mock-host';
describe('PackageManager', () => {
let host: Host;
let runCommandSpy: jasmine.Spy;
const descriptor = SUPPORTED_PACKAGE_MANAGERS['npm'];
beforeEach(() => {
host = new MockHost();
runCommandSpy = spyOn(host, 'runCommand').and.resolveTo({ stdout: '1.2.3', stderr: '' });
host.runCommand = runCommandSpy;
});
describe('getVersion', () => {
it('should fetch the version from the package manager if not cached', async () => {
const pm = new PackageManager(host, '/tmp', descriptor);
const version = await pm.getVersion();
expect(version).toBe('1.2.3');
expect(runCommandSpy).toHaveBeenCalledWith(
descriptor.binary,
descriptor.versionCommand,
jasmine.objectContaining({ cwd: '/tmp' }),
);
});
it('should cache the version after the first fetch', async () => {
const pm = new PackageManager(host, '/tmp', descriptor);
await pm.getVersion();
await pm.getVersion();
expect(runCommandSpy).toHaveBeenCalledTimes(1);
});
it('should use the version provided in the constructor', async () => {
const pm = new PackageManager(host, '/tmp', descriptor, { version: '4.5.6' });
const version = await pm.getVersion();
expect(version).toBe('4.5.6');
expect(runCommandSpy).not.toHaveBeenCalled();
});
});
});