|
| 1 | +import { SpawnOptions } from 'child_process' |
| 2 | +import path from 'path' |
1 | 3 | import { install } from '../../src/util/install' |
2 | 4 |
|
3 | 5 | let resolveMock: jest.MockedFunction<(name: string) => string> |
4 | 6 | jest.mock('../../src/util/resolve', () => ({ |
5 | 7 | resolve: (name: string) => resolveMock(name), |
6 | 8 | })) |
7 | 9 |
|
8 | | -let spawnMock: jest.MockedFn<(cmd: string, args: string[]) => Promise<string>> |
| 10 | +let spawnMock: jest.MockedFn<(cmd: string, args: string[], opt: SpawnOptions) => Promise<string>> |
9 | 11 | jest.mock('../../src/util/spawn', () => ({ |
10 | | - spawn: (cmd: string, args: string[]) => spawnMock(cmd, args), |
| 12 | + spawn: (cmd: string, args: string[], opt: SpawnOptions) => spawnMock(cmd, args, opt), |
11 | 13 | })) |
12 | 14 |
|
13 | 15 | test('skip present modules', async () => { |
@@ -42,3 +44,15 @@ test('install missing modules', async () => { |
42 | 44 | expect(spawnMock.mock.calls[0][1]).toContain('bar') |
43 | 45 | expect(log).toEqual([expect.stringContaining('Install ["foo","bar"]')]) |
44 | 46 | }) |
| 47 | + |
| 48 | +test('install in dist', async () => { |
| 49 | + spawnMock = jest.fn() |
| 50 | + |
| 51 | + await install(['foo'], () => undefined) |
| 52 | + |
| 53 | + expect(spawnMock).toBeCalledTimes(1) |
| 54 | + expect(spawnMock.mock.calls[0][2]).toEqual(expect.objectContaining({ |
| 55 | + // In test this should be the directory of the `install` util |
| 56 | + cwd: path.resolve(__dirname, '../../src/util'), |
| 57 | + })) |
| 58 | +}) |
0 commit comments