forked from renovatebot/renovate
/
util.spec.ts
67 lines (57 loc) · 1.85 KB
/
util.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
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
import { getName } from '../../../test/util';
import type { Preset } from './types';
import {
FetchPresetConfig,
PRESET_DEP_NOT_FOUND,
PRESET_NOT_FOUND,
fetchPreset,
} from './util';
const config: FetchPresetConfig = {
pkgName: 'some/repo',
filePreset: 'default',
endpoint: 'endpoint',
fetch: undefined,
};
const fetch = jest.fn(() => Promise.resolve<Preset>({}));
describe(getName(), () => {
beforeEach(() => {
fetch.mockReset();
});
it('works', async () => {
fetch.mockResolvedValue({ sub: { preset: { foo: true } } });
expect(await fetchPreset({ ...config, fetch })).toEqual({
sub: { preset: { foo: true } },
});
expect(
await fetchPreset({ ...config, filePreset: 'some/sub', fetch })
).toEqual({ preset: { foo: true } });
expect(
await fetchPreset({ ...config, filePreset: 'some/sub/preset', fetch })
).toEqual({ foo: true });
});
it('fails', async () => {
fetch.mockRejectedValueOnce(new Error('fails'));
await expect(fetchPreset({ ...config, fetch })).rejects.toThrow('fails');
});
it(PRESET_DEP_NOT_FOUND, async () => {
fetch.mockResolvedValueOnce(null);
await expect(fetchPreset({ ...config, fetch })).rejects.toThrow(
PRESET_DEP_NOT_FOUND
);
fetch.mockRejectedValueOnce(new Error(PRESET_DEP_NOT_FOUND));
fetch.mockRejectedValueOnce(new Error(PRESET_DEP_NOT_FOUND));
await expect(fetchPreset({ ...config, fetch })).rejects.toThrow(
PRESET_DEP_NOT_FOUND
);
});
it(PRESET_NOT_FOUND, async () => {
fetch.mockResolvedValueOnce({});
await expect(
fetchPreset({ ...config, filePreset: 'some/sub/preset', fetch })
).rejects.toThrow(PRESET_NOT_FOUND);
fetch.mockResolvedValueOnce({ sub: {} });
await expect(
fetchPreset({ ...config, filePreset: 'some/sub/preset', fetch })
).rejects.toThrow(PRESET_NOT_FOUND);
});
});