-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathindex.test.ts
More file actions
143 lines (125 loc) · 4.04 KB
/
index.test.ts
File metadata and controls
143 lines (125 loc) · 4.04 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import * as npm from '../npm';
import { fileExistsInUnpkg } from '../unpkg';
import * as api from './index';
jest.mock('../npm');
jest.mock('../unpkg');
describe('loadTypesIndex()', () => {
it('should download and cache all @types', async () => {
expect(api.typesCache).not.toHaveProperty('algoliasearch');
expect(api.isDefinitelyTyped({ name: 'algoliasearch' })).toBe(undefined);
await api.loadTypesIndex();
expect(api.typesCache).toHaveProperty('algoliasearch');
expect(api.typesCache).not.toHaveProperty('algoliasearch/lite');
expect(api.typesCache.algoliasearch).toBe('algoliasearch');
expect(api.typesCache['algoliasearch/lite']).toBe(undefined);
expect(api.typesCache.doesnotexist).toBe(undefined);
expect(api.isDefinitelyTyped({ name: 'algoliasearch' })).toBe(
'algoliasearch'
);
});
});
describe('getTypeScriptSupport()', () => {
it('If types are already calculated - return early', async () => {
const typesSupport = await api.getTypeScriptSupport({
name: 'Has Types',
types: { ts: 'included' },
version: '1.0',
});
expect(typesSupport).toEqual({ types: { ts: 'included' } });
});
it('Handles not having any possible TS types', async () => {
const typesSupport = await api.getTypeScriptSupport({
name: 'my-lib',
types: { ts: false },
version: '1.0',
});
expect(typesSupport).toEqual({ types: { ts: false } });
});
describe('Definitely Typed', () => {
it('Checks for @types/[name]', async () => {
const atTypesSupport = await api.getTypeScriptSupport({
name: 'lodash.valuesin',
types: { ts: false },
version: '1.0',
});
expect(atTypesSupport).toEqual({
types: {
ts: 'definitely-typed',
definitelyTyped: '@types/lodash.valuesin',
},
});
});
it('Checks for @types/[scope__name]', async () => {
const atTypesSupport = await api.getTypeScriptSupport({
name: '@mapbox/geojson-area',
types: { ts: false },
version: '1.0',
});
expect(atTypesSupport).toEqual({
types: {
ts: 'definitely-typed',
definitelyTyped: '@types/mapbox__geojson-area',
},
});
const atTypesSupport2 = await api.getTypeScriptSupport({
name: '@reach/router',
types: { ts: false },
version: '1.0',
});
expect(atTypesSupport2).toEqual({
types: {
ts: 'definitely-typed',
definitelyTyped: '@types/reach__router',
},
});
});
});
describe('unpkg', () => {
it('Checks for a d.ts resolved version of main', async () => {
// @ts-expect-error
npm.validatePackageExists.mockResolvedValue(false);
// @ts-expect-error
fileExistsInUnpkg.mockResolvedValue(true);
const typesSupport = await api.getTypeScriptSupport({
name: 'my-lib',
types: { ts: { possible: true, dtsMain: 'main.d.ts' } },
version: '1.0.0',
});
expect(typesSupport).toEqual({ types: { ts: 'included' } });
});
});
// TO DO : reup this
// adescribe('FilesList', () => {
// ait('should match a correct filesList', async () => {
// const atTypesSupport = await api.getTypeScriptSupport(
// {
// name: 'doesnotexist',
// types: { ts: false },
// version: '1.0',
// },
// [{ name: 'index.js' }, { name: 'index.d.ts' }]
// );
// expect(atTypesSupport).toEqual({
// types: {
// _where: 'filesList',
// ts: 'included',
// },
// });
// });
// ait('should not match an incorrect filesList', async () => {
// const atTypesSupport = await api.getTypeScriptSupport(
// {
// name: 'doesnotexist',
// types: { ts: false },
// version: '1.0',
// },
// [{ name: 'index.js' }, { name: 'index.ts' }, { name: 'index.md' }]
// );
// expect(atTypesSupport).toEqual({
// types: {
// ts: false,
// },
// });
// });
// });
});