Skip to content

Commit 89ca6aa

Browse files
committed
Fix typings after updating typescript
1 parent fc07efc commit 89ca6aa

File tree

10 files changed

+838
-1439
lines changed

10 files changed

+838
-1439
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ jobs:
2828
with:
2929
node-version: '12.x'
3030
- name: Install dependencies
31-
run: yarn --dev && yarn --cwd ./playgrounds/angular
31+
run: yarn --dev && yarn --cwd ./playgrounds/vue
3232
- name: Run Browser tests
3333
uses: cypress-io/github-action@v2
3434
with:
3535
# Tests are only done on one playground to avoid long testing time
36-
start: yarn playground:angular
37-
env: playground=angular
36+
start: yarn playground:vue
37+
env: playground=vue
3838
- uses: actions/upload-artifact@v1
3939
if: failure()
4040
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,4 @@ cypress/support
118118
cypress/plugins
119119
cypress/fixtures
120120

121+
.vscode

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@
6161
"@babel/preset-env": "^7.15.6",
6262
"@rollup/plugin-commonjs": "^17.1.0",
6363
"@rollup/plugin-node-resolve": "^11.2.0",
64+
"@types/jest": "^27.0.2",
6465
"@typescript-eslint/eslint-plugin": "^4.16.1",
6566
"@typescript-eslint/parser": "^4.16.1",
6667
"@vue/eslint-config-typescript": "^7.0.0",
6768
"@vue/eslint-plugin": "^4.2.0",
6869
"algoliasearch": "^4.10.5",
6970
"babel-eslint": "^10.1.0",
70-
"babel-jest": "^26.1.0",
71+
"babel-jest": "^27.2.2",
7172
"concurrently": "^6.2.1",
7273
"cssnano": "^4.1.10",
7374
"cypress": "^7.3.0",
@@ -87,7 +88,7 @@
8788
"eslint-plugin-standard": "^5.0.0",
8889
"eslint-plugin-vue": "^7.7.0",
8990
"instantsearch.js": "^4.30.1",
90-
"jest": "^26.6.3",
91+
"jest": "^27.2.2",
9192
"jest-watch-typeahead": "^0.6.3",
9293
"prettier": "^2.0.0",
9394
"regenerator-runtime": "^0.13.7",
@@ -97,7 +98,7 @@
9798
"rollup-plugin-terser": "^7.0.0",
9899
"rollup-plugin-typescript2": "^0.30.0",
99100
"shx": "^0.3.3",
100-
"ts-jest": "^26.5.2",
101+
"ts-jest": "^27.0.5",
101102
"tslib": "^2.3.1",
102103
"typescript": "^4.4.3"
103104
}

tests/filter.tests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe('Instant MeiliSearch Browser test', () => {
113113
indexName: 'movies',
114114
params: {
115115
query: 'night',
116-
facetFilters: [['genres:action', 'genres:Thriller'], 'genres:crime'],
116+
facetFilters: [['genres:action', 'genres:Thriller'], ['genres:crime']],
117117
},
118118
}
119119
const response = await searchClient.search<Movies>([params])
@@ -126,7 +126,7 @@ describe('Instant MeiliSearch Browser test', () => {
126126
indexName: 'movies',
127127
params: {
128128
query: '',
129-
facetFilters: [['genres:action', 'genres:Thriller'], 'genres:crime'],
129+
facetFilters: [['genres:action', 'genres:Thriller'], ['genres:crime']],
130130
},
131131
}
132132
const response = await searchClient.search<Movies>([params])

tests/highlight.tests.ts

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,22 @@ describe('Highlight Browser test', () => {
4747
},
4848
])
4949

50-
const resKeys = Object.keys(response.results[0]?.hits[0]?._highlightResult)
51-
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0])))
50+
expect(response.results[0]?.hits[0]?._highlightResult).toHaveProperty('id')
51+
expect(response.results[0]?.hits[0]?._highlightResult).toHaveProperty(
52+
'title'
53+
)
54+
expect(response.results[0]?.hits[0]?._highlightResult).toHaveProperty(
55+
'overview'
56+
)
57+
expect(response.results[0]?.hits[0]?._highlightResult).toHaveProperty(
58+
'genres'
59+
)
60+
expect(response.results[0]?.hits[0]?._highlightResult).toHaveProperty(
61+
'poster'
62+
)
63+
expect(response.results[0]?.hits[0]?._highlightResult).toHaveProperty(
64+
'release_date'
65+
)
5266
})
5367

5468
test('Test no attributesToHighlight on placeholder', async () => {
@@ -61,8 +75,7 @@ describe('Highlight Browser test', () => {
6175
},
6276
},
6377
])
64-
const resKeys = response.results[0]?.hits[0]?._highlightResult
65-
expect(resKeys).toEqual(undefined)
78+
expect(response.results[0]?.hits[0]).not.toHaveProperty('_highlightResult')
6679
})
6780

6881
test('Test one attributesToHighlight on specific query', async () => {
@@ -77,9 +90,7 @@ describe('Highlight Browser test', () => {
7790
])
7891

7992
const highlightedResults = response.results[0].hits[0]._highlightResult
80-
const resKeys = Object.keys(highlightedResults)
81-
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0])))
82-
expect(highlightedResults.title?.value).toEqual(
93+
expect(highlightedResults?.title?.value).toEqual(
8394
'__ais-highlight__Ar__/ais-highlight__iel'
8495
)
8596
})
@@ -96,12 +107,10 @@ describe('Highlight Browser test', () => {
96107
])
97108

98109
const highlightedResults = response.results[0].hits[0]._highlightResult
99-
const resKeys = Object.keys(highlightedResults)
100-
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0])))
101-
expect(highlightedResults.title?.value).toEqual(
110+
expect(highlightedResults?.title?.value).toEqual(
102111
'__ais-highlight__S__/ais-highlight__tar Wars'
103112
)
104-
expect(highlightedResults.overview?.value).toEqual(
113+
expect(highlightedResults?.overview?.value).toEqual(
105114
expect.stringMatching('__ais-highlight__S__/ais-highlight__kywalker')
106115
)
107116
})
@@ -118,12 +127,10 @@ describe('Highlight Browser test', () => {
118127
])
119128

120129
const highlightedResults = response.results[0].hits[0]._highlightResult
121-
const resKeys = Object.keys(highlightedResults)
122-
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0])))
123-
expect(highlightedResults.title?.value).toEqual(
130+
expect(highlightedResults?.title?.value).toEqual(
124131
'__ais-highlight__Magnetic__/ais-highlight__ Rose'
125132
)
126-
expect(highlightedResults.overview?.value).toEqual(
133+
expect(highlightedResults?.overview?.value).toEqual(
127134
expect.not.stringMatching('__ais-highlight__Magnetic__/ais-highlight__')
128135
)
129136
})
@@ -139,12 +146,10 @@ describe('Highlight Browser test', () => {
139146
},
140147
])
141148
const highlightedResults = response.results[0].hits[0]._highlightResult
142-
const resKeys = Object.keys(highlightedResults)
143-
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0])))
144-
expect(highlightedResults.title?.value).toEqual(
149+
expect(highlightedResults?.title?.value).toEqual(
145150
'__ais-highlight__Magnetic__/ais-highlight__ Rose'
146151
)
147-
expect(highlightedResults.overview?.value).toEqual(
152+
expect(highlightedResults?.overview?.value).toEqual(
148153
expect.not.stringMatching('__ais-highlight__Magnetic__/ais-highlight__')
149154
)
150155
})
@@ -160,12 +165,10 @@ describe('Highlight Browser test', () => {
160165
},
161166
])
162167
const highlightedResults = response.results[0].hits[0]._highlightResult
163-
const resKeys = Object.keys(highlightedResults)
164-
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0])))
165-
expect(highlightedResults.title?.value).toEqual(
168+
expect(highlightedResults?.title?.value).toEqual(
166169
'__ais-highlight__Magnetic__/ais-highlight__ Rose'
167170
)
168-
expect(highlightedResults.overview?.value).toEqual(
171+
expect(highlightedResults?.overview?.value).toEqual(
169172
expect.not.stringMatching('__ais-highlight__Magnetic__/ais-highlight__')
170173
)
171174
})
@@ -182,12 +185,10 @@ describe('Highlight Browser test', () => {
182185
])
183186

184187
const highlightedResults = response.results[0].hits[0]._highlightResult
185-
const resKeys = Object.keys(highlightedResults)
186-
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0])))
187-
expect(highlightedResults.title?.value).toEqual(
188+
expect(highlightedResults?.title?.value).toEqual(
188189
'__ais-highlight__S__/ais-highlight__tar Wars'
189190
)
190-
expect(highlightedResults.overview?.value).toEqual(
191+
expect(highlightedResults?.overview?.value).toEqual(
191192
expect.stringMatching('__ais-highlight__S__/ais-highlight__kywalker')
192193
)
193194
})
@@ -206,10 +207,8 @@ describe('Highlight Browser test', () => {
206207
])
207208

208209
const highlightedResults = response.results[0].hits[0]._highlightResult
209-
const resKeys = Object.keys(highlightedResults)
210-
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0])))
211-
expect(highlightedResults.title?.value).toEqual('<p>S</p>tar Wars')
212-
expect(highlightedResults.overview?.value).toEqual(
210+
expect(highlightedResults?.title?.value).toEqual('<p>S</p>tar Wars')
211+
expect(highlightedResults?.overview?.value).toEqual(
213212
expect.stringMatching('<p>S</p>olo')
214213
)
215214
})

tests/snippets.tests.ts

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ describe('Snippet Browser test', () => {
2929
},
3030
])
3131
const snippeted = response.results[0]?.hits[0]?._highlightResult
32-
expect(snippeted.overview.value).toEqual('Princess')
33-
const resKeys = Object.keys(snippeted)
34-
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0])))
32+
expect(snippeted?.overview?.value).toEqual('Princess')
3533
})
3634

3735
test('Test one attributesToSnippet on specific query', async () => {
@@ -47,11 +45,8 @@ describe('Snippet Browser test', () => {
4745
])
4846
const highlighted = response.results[0]?.hits[0]?._highlightResult
4947
const snippeted = response.results[0].hits[0]._snippetResult
50-
expect(highlighted.overview.value).toEqual('While')
51-
expect(snippeted.overview.value).toEqual('While...')
52-
const resKeys = Object.keys(response.results[0]?.hits[0]?._highlightResult)
53-
54-
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0])))
48+
expect(highlighted?.overview?.value).toEqual('While')
49+
expect(snippeted?.overview?.value).toEqual('While...')
5550
})
5651

5752
test('Test two attributesToSnippet on specific query with one hit empty string', async () => {
@@ -71,24 +66,21 @@ describe('Snippet Browser test', () => {
7166
const firstHitHighlight = response.results[0]?.hits[0]?._highlightResult
7267
const firstHitSnippet = response.results[0].hits[0]._snippetResult
7368

74-
expect(firstHitHighlight.title.value).toEqual('<p>S</p>tar Wars')
75-
expect(firstHitHighlight.overview.value).toEqual(
69+
expect(firstHitHighlight?.title?.value).toEqual('<p>S</p>tar Wars')
70+
expect(firstHitHighlight?.overview?.value).toEqual(
7671
'Luke <p>S</p>kywalker and'
7772
)
78-
expect(firstHitSnippet.title.value).toEqual('<p>S</p>tar Wars...')
79-
expect(firstHitSnippet.overview.value).toEqual(
73+
expect(firstHitSnippet?.title?.value).toEqual('<p>S</p>tar Wars...')
74+
expect(firstHitSnippet?.overview?.value).toEqual(
8075
'Luke <p>S</p>kywalker and...'
8176
)
8277

8378
const secondHitHighlight = response.results[0]?.hits[1]?._highlightResult
8479
const secondHitSnippet = response.results[0]?.hits[1]?._snippetResult
85-
expect(secondHitHighlight.title.value).toEqual('Four')
86-
expect(secondHitHighlight.overview.value).toEqual("It'<p>s</p> Ted")
87-
expect(secondHitSnippet.title.value).toEqual('Four...')
88-
expect(secondHitSnippet.overview.value).toEqual("It'<p>s</p> Ted...")
89-
90-
const resKeys = Object.keys(response.results[0]?.hits[0]?._highlightResult)
91-
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0])))
80+
expect(secondHitHighlight?.title?.value).toEqual('Four')
81+
expect(secondHitHighlight?.overview?.value).toEqual("It'<p>s</p> Ted")
82+
expect(secondHitSnippet?.title?.value).toEqual('Four...')
83+
expect(secondHitSnippet?.overview?.value).toEqual("It'<p>s</p> Ted...")
9284
})
9385

9486
test('Test attributesToSnippet on a null attribute', async () => {
@@ -103,10 +95,7 @@ describe('Snippet Browser test', () => {
10395
])
10496

10597
const firstHit = response.results[0]?.hits[0]?._highlightResult
106-
expect(firstHit.overview.value).toEqual('null')
107-
108-
const resKeys = Object.keys(response.results[0]?.hits[0]?._highlightResult)
109-
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0])))
98+
expect(firstHit?.overview?.value).toEqual('null')
11099
})
111100

112101
test('Test one attributesToSnippet on placeholder w/ snippetEllipsisText', async () => {
@@ -120,9 +109,7 @@ describe('Snippet Browser test', () => {
120109
},
121110
])
122111
const snippeted = response.results[0]?.hits[0]?._highlightResult
123-
expect(snippeted.overview.value).toEqual('Princess')
124-
const resKeys = Object.keys(snippeted)
125-
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0])))
112+
expect(snippeted?.overview?.value).toEqual('Princess')
126113
})
127114

128115
test('Test one attributesToSnippet on specific query w/ snippetEllipsisText', async () => {
@@ -136,9 +123,7 @@ describe('Snippet Browser test', () => {
136123
},
137124
])
138125
const snippeted = response.results[0]?.hits[0]?._highlightResult?.overview
139-
expect(snippeted.value).toEqual('While')
140-
const resKeys = Object.keys(response.results[0]?.hits[0]?._highlightResult)
141-
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0])))
126+
expect(snippeted?.value).toEqual('While')
142127
})
143128

144129
test('Test two attributesToSnippet on specific query with one hit empty string w/ snippetEllipsisText', async () => {
@@ -153,20 +138,17 @@ describe('Snippet Browser test', () => {
153138
])
154139
const firstHit = response.results[0]?.hits[0]?._highlightResult
155140

156-
expect(firstHit.title.value).toEqual(
141+
expect(firstHit?.title?.value).toEqual(
157142
'__ais-highlight__S__/ais-highlight__tar Wars'
158143
)
159-
expect(firstHit.overview.value).toEqual(
144+
expect(firstHit?.overview?.value).toEqual(
160145
'Luke __ais-highlight__S__/ais-highlight__kywalker and'
161146
)
162147
const secondHit = response.results[0].hits[1]._highlightResult
163-
expect(secondHit.title.value).toEqual('Four')
164-
expect(secondHit.overview.value).toEqual(
148+
expect(secondHit?.title?.value).toEqual('Four')
149+
expect(secondHit?.overview?.value).toEqual(
165150
"It'__ais-highlight__s__/ais-highlight__ Ted"
166151
)
167-
168-
const resKeys = Object.keys(response.results[0]?.hits[0]?._highlightResult)
169-
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0])))
170152
})
171153

172154
test('Test attributesToSnippet on a null attribute w/ snippetEllipsisText', async () => {
@@ -181,8 +163,23 @@ describe('Snippet Browser test', () => {
181163
])
182164

183165
const firstHit = response.results[0]?.hits[0]?._highlightResult
184-
expect(firstHit.overview.value).toEqual('null')
185-
const resKeys = Object.keys(response.results[0]?.hits[0]?._highlightResult)
186-
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0])))
166+
expect(firstHit?.overview?.value).toEqual('null')
167+
expect(response.results[0]?.hits[0]?._highlightResult).toHaveProperty('id')
168+
expect(response.results[0]?.hits[0]?._highlightResult).toHaveProperty(
169+
'title'
170+
)
171+
expect(response.results[0]?.hits[0]?._highlightResult).toHaveProperty(
172+
'overview'
173+
)
174+
expect(response.results[0]?.hits[0]?._highlightResult).toHaveProperty(
175+
'genres'
176+
)
177+
expect(response.results[0]?.hits[0]?._highlightResult).toHaveProperty(
178+
'poster'
179+
)
180+
expect(response.results[0]?.hits[0]?._highlightResult).toHaveProperty(
181+
'release_date'
182+
)
183+
// expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0])))
187184
})
188185
})

tests/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../tsconfig.test.json",
3+
}

tsconfig.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
"esModuleInterop": true,
1010
"allowSyntheticDefaultImports": true,
1111
"moduleResolution": "node",
12-
"lib": ["ES2019", "ESNext", "dom"],
12+
"lib": [
13+
"ES2019",
14+
"ESNext",
15+
"dom"
16+
],
1317
"importHelpers": true,
14-
1518
// Enforced typing rules
1619
"strict": true,
1720
"noImplicitAny": true,
@@ -29,6 +32,13 @@
2932
"noUnusedParameters": true,
3033
"isolatedModules": true
3134
},
32-
"include": ["src"], // files to include during compilation
33-
"exclude": ["tests", "*.js", "scripts", "**/__tests__/*.ts"],
35+
"include": [
36+
"src"
37+
], // files to include during compilation
38+
"exclude": [
39+
"tests",
40+
"*.js",
41+
"scripts",
42+
"**/__tests__/*.ts"
43+
],
3444
}

tsconfig.test.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"compilerOptions": {
44
"suppressImplicitAnyIndexErrors": true,
55
},
6+
"include": [
7+
"./**/*"
8+
],
69
"exclude": []
710
}

0 commit comments

Comments
 (0)