|
1 | 1 | import * as api from '../index.js'; |
| 2 | +import log from '../../log.js'; |
| 3 | + |
| 4 | +jest.mock('../../log.js', () => { |
| 5 | + return { |
| 6 | + info: jest.fn(), |
| 7 | + warn: jest.fn(), |
| 8 | + }; |
| 9 | +}); |
| 10 | + |
| 11 | +beforeEach(() => { |
| 12 | + jest.resetAllMocks(); |
| 13 | +}); |
2 | 14 |
|
3 | 15 | describe('hits', () => { |
4 | 16 | beforeAll(async () => { |
@@ -51,34 +63,48 @@ describe('hits', () => { |
51 | 63 | describe('files', () => { |
52 | 64 | describe('getFilesList()', () => { |
53 | 65 | it('should get a flat list of files', async () => { |
54 | | - const files = await api.getFilesList({ name: 'jest@24.8.0' }); |
| 66 | + const files = await api.getFilesList({ |
| 67 | + name: 'jest', |
| 68 | + version: '24.8.0', |
| 69 | + }); |
55 | 70 | expect(files).toMatchSnapshot(); |
56 | 71 | }); |
57 | 72 |
|
58 | | - it('should not get a files list', async () => { |
| 73 | + it('should not get a files list for fake package', async () => { |
59 | 74 | const files = await api.getFilesList({ |
60 | | - name: 'thispackagedoesnotexist@3.33.0', |
| 75 | + name: 'thispackagedoesnotexist', |
| 76 | + version: '3.33.0', |
61 | 77 | }); |
62 | 78 | expect(files).toEqual([]); |
| 79 | + expect(log.warn.mock.calls[0][0].message).toMatchInlineSnapshot( |
| 80 | + `"Response code 404 (Not Found)"` |
| 81 | + ); |
63 | 82 | }); |
64 | 83 | }); |
65 | 84 |
|
66 | 85 | describe('getAllFilesList()', () => { |
67 | 86 | it('should get a flat list of files', async () => { |
68 | | - const files = await api.getAllFilesList([{ name: 'jest@24.8.0' }]); |
| 87 | + const files = await api.getAllFilesList([ |
| 88 | + { name: 'jest', version: '24.8.0' }, |
| 89 | + ]); |
69 | 90 | expect(files).toMatchSnapshot(); |
70 | 91 | }); |
71 | 92 |
|
72 | 93 | it('should get multiple flat list of files', async () => { |
73 | 94 | const files = await api.getAllFilesList([ |
74 | 95 | { |
75 | | - name: 'jest@24.8.0', |
| 96 | + name: 'jest', |
| 97 | + version: '24.8.0', |
76 | 98 | }, |
77 | 99 | { |
78 | | - name: 'thispackagedoesnotexist@3.33.0', |
| 100 | + name: 'thispackagedoesnotexist', |
| 101 | + version: '3.33.0', |
79 | 102 | }, |
80 | 103 | ]); |
81 | 104 | expect(files).toMatchSnapshot(); |
| 105 | + expect(log.warn.mock.calls[0][0].message).toMatchInlineSnapshot( |
| 106 | + `"Response code 404 (Not Found)"` |
| 107 | + ); |
82 | 108 | }); |
83 | 109 | }); |
84 | 110 | }); |
0 commit comments