Skip to content

Commit a91ad4f

Browse files
authored
Remove legacy keys from wrapped got in end-to-end tests (#36265)
1 parent 4d77791 commit a91ad4f

File tree

15 files changed

+59
-63
lines changed

15 files changed

+59
-63
lines changed

src/rest/tests/api.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('anchor-redirect api', () => {
2222
sp.set('hash', hash)
2323
const res = await get('/api/anchor-redirect?' + sp)
2424
expect(res.statusCode).toBe(200)
25-
const { to } = JSON.parse(res.text)
25+
const { to } = JSON.parse(res.body)
2626
expect(to).toBe(value)
2727
})
2828
test('errors when path is not passed', async () => {
@@ -48,7 +48,7 @@ describe('anchor-redirect api', () => {
4848
sp.set('path', 'foo')
4949
sp.set('hash', 'bar')
5050
const res = await get('/api/anchor-redirect?' + sp)
51-
const { to } = JSON.parse(res.text)
51+
const { to } = JSON.parse(res.body)
5252
expect(to).toBe(undefined)
5353
})
5454
test('reasonably aggressive cache-control headers', async () => {

src/search/tests/api-search.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
3535
sp.set('query', 'foo')
3636
const res = await get('/api/search/v1?' + sp)
3737
expect(res.statusCode).toBe(200)
38-
const results = JSON.parse(res.text)
38+
const results = JSON.parse(res.body)
3939

4040
expect(results.meta).toBeTruthy()
4141
expect(results.meta.found.value).toBeGreaterThanOrEqual(1)
@@ -77,7 +77,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
7777
sp.set('debug', '1') // Note!
7878
const res = await get('/api/search/v1?' + sp)
7979
expect(res.statusCode).toBe(200)
80-
const results = JSON.parse(res.text)
80+
const results = JSON.parse(res.body)
8181
// safe because we know exactly the fixtures
8282
const hit = results.hits[0]
8383
expect(hit.popularity).toBeTruthy()
@@ -92,7 +92,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
9292
sp.set('query', 'sill')
9393
const res = await get('/api/search/v1?' + sp)
9494
expect(res.statusCode).toBe(200)
95-
const results = JSON.parse(res.text)
95+
const results = JSON.parse(res.body)
9696
// Fixtures contains no word called 'sill'. It does contain the term
9797
// 'silly' which, in English, becomes 'silli` when stemmed.
9898
// Because we don't use `&autocomplete=true` this time, we expect
@@ -107,7 +107,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
107107
sp.set('autocomplete', 'true')
108108
const res = await get('/api/search/v1?' + sp)
109109
expect(res.statusCode).toBe(200)
110-
const results = JSON.parse(res.text)
110+
const results = JSON.parse(res.body)
111111
expect(results.meta.found.value).toBeGreaterThanOrEqual(1)
112112
const hit = results.hits[0]
113113
const contentHighlights = hit.highlights.content
@@ -120,7 +120,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
120120
sp.set('query', 'xojixjoiwejhfoiuwehjfioweufhj')
121121
const res = await get('/api/search/v1?' + sp)
122122
expect(res.statusCode).toBe(200)
123-
const results = JSON.parse(res.text)
123+
const results = JSON.parse(res.body)
124124
expect(results.hits.length).toBe(0)
125125
expect(results.meta.found.value).toBe(0)
126126
})
@@ -132,7 +132,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
132132
sp.append('highlights', 'content')
133133
const res = await get('/api/search/v1?' + sp)
134134
expect(res.statusCode).toBe(200)
135-
const results = JSON.parse(res.text)
135+
const results = JSON.parse(res.body)
136136
expect(results.meta.found.value).toBeGreaterThanOrEqual(1)
137137
for (const hit of results.hits) {
138138
expect(hit.highlights.title).toBeFalsy()
@@ -148,7 +148,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
148148
sp.set('highlights', 'headings')
149149
const res = await get('/api/search/v1?' + sp)
150150
expect(res.statusCode).toBe(200)
151-
const results = JSON.parse(res.text)
151+
const results = JSON.parse(res.body)
152152
expect(results.meta.found.value).toBeGreaterThanOrEqual(1)
153153
for (const hit of results.hits) {
154154
expect(hit.highlights.headings).toBeTruthy()
@@ -163,12 +163,12 @@ describeIfElasticsearchURL('search v1 middleware', () => {
163163
sp.set('version', 'dotcom')
164164
const res1 = await get('/api/search/v1?' + sp)
165165
expect(res1.statusCode).toBe(200)
166-
const results1 = JSON.parse(res1.text)
166+
const results1 = JSON.parse(res1.body)
167167

168168
sp.set('version', 'free-pro-team@latest')
169169
const res2 = await get('/api/search/v1?' + sp)
170170
expect(res2.statusCode).toBe(200)
171-
const results2 = JSON.parse(res2.text)
171+
const results2 = JSON.parse(res2.body)
172172
expect(results1.hits[0].id).toBe(results2.hits[0].id)
173173
})
174174

@@ -177,15 +177,15 @@ describeIfElasticsearchURL('search v1 middleware', () => {
177177
{
178178
const res = await get('/api/search/v1')
179179
expect(res.statusCode).toBe(400)
180-
expect(JSON.parse(res.text).error).toBeTruthy()
180+
expect(JSON.parse(res.body).error).toBeTruthy()
181181
}
182182
// query is just whitespace
183183
{
184184
const sp = new URLSearchParams()
185185
sp.set('query', ' ')
186186
const res = await get('/api/search/v1?' + sp)
187187
expect(res.statusCode).toBe(400)
188-
expect(JSON.parse(res.text).error).toBeTruthy()
188+
expect(JSON.parse(res.body).error).toBeTruthy()
189189
}
190190
// unrecognized language
191191
{
@@ -194,7 +194,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
194194
sp.set('language', 'xxx')
195195
const res = await get('/api/search/v1?' + sp)
196196
expect(res.statusCode).toBe(400)
197-
expect(JSON.parse(res.text).error).toMatch('language')
197+
expect(JSON.parse(res.body).error).toMatch('language')
198198
}
199199
// unrecognized page
200200
{
@@ -203,7 +203,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
203203
sp.set('page', '9999')
204204
const res = await get('/api/search/v1?' + sp)
205205
expect(res.statusCode).toBe(400)
206-
expect(JSON.parse(res.text).error).toMatch('page')
206+
expect(JSON.parse(res.body).error).toMatch('page')
207207
}
208208
// unrecognized version
209209
{
@@ -212,8 +212,8 @@ describeIfElasticsearchURL('search v1 middleware', () => {
212212
sp.set('version', 'xxxxx')
213213
const res = await get('/api/search/v1?' + sp)
214214
expect(res.statusCode).toBe(400)
215-
expect(JSON.parse(res.text).error).toMatch("'xxxxx'")
216-
expect(JSON.parse(res.text).field).toMatch('version')
215+
expect(JSON.parse(res.body).error).toMatch("'xxxxx'")
216+
expect(JSON.parse(res.body).field).toMatch('version')
217217
}
218218
// unrecognized size
219219
{
@@ -222,7 +222,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
222222
sp.set('size', 'not a number')
223223
const res = await get('/api/search/v1?' + sp)
224224
expect(res.statusCode).toBe(400)
225-
expect(JSON.parse(res.text).error).toMatch('size')
225+
expect(JSON.parse(res.body).error).toMatch('size')
226226
}
227227
// unrecognized sort
228228
{
@@ -231,7 +231,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
231231
sp.set('sort', 'neverheardof')
232232
const res = await get('/api/search/v1?' + sp)
233233
expect(res.statusCode).toBe(400)
234-
expect(JSON.parse(res.text).error).toMatch('sort')
234+
expect(JSON.parse(res.body).error).toMatch('sort')
235235
}
236236
// unrecognized highlights
237237
{
@@ -240,7 +240,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
240240
sp.set('highlights', 'neverheardof')
241241
const res = await get('/api/search/v1?' + sp)
242242
expect(res.statusCode).toBe(400)
243-
expect(JSON.parse(res.text).error).toMatch('neverheardof')
243+
expect(JSON.parse(res.body).error).toMatch('neverheardof')
244244
}
245245
})
246246

@@ -249,7 +249,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
249249
sp.set('query', 'breadcrumbs')
250250
const res = await get('/api/search/v1?' + sp)
251251
expect(res.statusCode).toBe(200)
252-
const results = JSON.parse(res.text)
252+
const results = JSON.parse(res.body)
253253
// safe because we know exactly the fixtures
254254
const hit = results.hits[0]
255255
expect(hit.breadcrumbs).toBe('')
@@ -264,7 +264,7 @@ describeIfElasticsearchURL("additional fields with 'include'", () => {
264264
sp.set('query', 'foo')
265265
const res = await get('/api/search/v1?' + sp)
266266
expect(res.statusCode).toBe(200)
267-
const results = JSON.parse(res.text)
267+
const results = JSON.parse(res.body)
268268
const firstKeys = Object.keys(results.hits[0])
269269
expect(firstKeys.includes('intro')).toBeFalsy()
270270
expect(firstKeys.includes('headings')).toBeFalsy()
@@ -276,7 +276,7 @@ describeIfElasticsearchURL("additional fields with 'include'", () => {
276276
sp.set('include', 'intro')
277277
const res = await get('/api/search/v1?' + sp)
278278
expect(res.statusCode).toBe(200)
279-
const results = JSON.parse(res.text)
279+
const results = JSON.parse(res.body)
280280
const firstKeys = Object.keys(results.hits[0])
281281
expect(firstKeys.includes('intro')).toBeTruthy()
282282
expect(firstKeys.includes('headings')).toBeFalsy()
@@ -289,7 +289,7 @@ describeIfElasticsearchURL("additional fields with 'include'", () => {
289289
sp.append('include', 'headings')
290290
const res = await get('/api/search/v1?' + sp)
291291
expect(res.statusCode).toBe(200)
292-
const results = JSON.parse(res.text)
292+
const results = JSON.parse(res.body)
293293
const firstKeys = Object.keys(results.hits[0])
294294
expect(firstKeys.includes('intro')).toBeTruthy()
295295
expect(firstKeys.includes('headings')).toBeTruthy()
@@ -301,7 +301,7 @@ describeIfElasticsearchURL("additional fields with 'include'", () => {
301301
sp.set('include', 'xxxxx')
302302
const res = await get('/api/search/v1?' + sp)
303303
expect(res.statusCode).toBe(400)
304-
const results = JSON.parse(res.text)
304+
const results = JSON.parse(res.body)
305305
expect(results.error).toMatch(`Not a valid value (["xxxxx"]) for key 'include'`)
306306
})
307307
})

src/webhooks/tests/api.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('webhooks v1 middleware', () => {
1515
sp.set('version', 'free-pro-team@latest')
1616
const res = await get('/api/webhooks/v1?' + sp)
1717
expect(res.statusCode).toBe(200)
18-
const results = JSON.parse(res.text)
18+
const results = JSON.parse(res.body)
1919
const actionTypes = Object.keys(results)
2020
expect(actionTypes.length).toBeGreaterThan(2)
2121
expect(Object.keys(results[actionTypes[0]]).includes('category')).toBeTruthy()
@@ -37,7 +37,7 @@ describe('webhooks v1 middleware', () => {
3737
sp.set('version', 'enterprise-cloud@latest')
3838
const res = await get('/api/webhooks/v1?' + sp)
3939
expect(res.statusCode).toBe(200)
40-
const results = JSON.parse(res.text)
40+
const results = JSON.parse(res.body)
4141
const actionTypes = Object.keys(results)
4242
expect(actionTypes.length).toBeGreaterThan(2)
4343
expect(Object.keys(results[actionTypes[0]]).includes('category')).toBeTruthy()
@@ -52,7 +52,7 @@ describe('webhooks v1 middleware', () => {
5252
const res = await get('/api/webhooks/v1?' + sp)
5353

5454
expect(res.statusCode).toBe(404)
55-
expect(JSON.parse(res.text).error).toBeTruthy()
55+
expect(JSON.parse(res.body).error).toBeTruthy()
5656
})
5757

5858
test('unknown version', async () => {
@@ -62,6 +62,6 @@ describe('webhooks v1 middleware', () => {
6262
const res = await get('/api/webhooks/v1?' + sp)
6363

6464
expect(res.statusCode).toBe(404)
65-
expect(JSON.parse(res.text).error).toBeTruthy()
65+
expect(JSON.parse(res.body).error).toBeTruthy()
6666
})
6767
})

tests/helpers/e2etest.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ export async function get(
4444
statusCode,
4545
headers,
4646
url,
47-
// Legacy
48-
text: body,
49-
status: statusCode,
50-
header: headers,
5147
}
5248
}
5349

@@ -81,7 +77,7 @@ export async function getDOM(
8177
if (!allow404 && res.status === 404) {
8278
throw new Error(`Page not found on ${route}`)
8379
}
84-
const $ = cheerio.load(res.text || '', { xmlMode: true })
80+
const $ = cheerio.load(res.body || '', { xmlMode: true })
8581
$.res = Object.assign({}, res)
8682
return $
8783
}
@@ -96,5 +92,5 @@ export async function getJSON(route, opts) {
9692
if (res.status >= 400) {
9793
console.warn(`${res.status} on ${route} and the response might not be JSON`)
9894
}
99-
return JSON.parse(res.text)
95+
return JSON.parse(res.body)
10096
}

tests/rendering-fixtures/dynamic-assets.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('dynamic assets', () => {
1414
})
1515
expect(res.statusCode).toBe(200)
1616
expect(res.headers['content-type']).toBe('image/webp')
17-
const { mime } = await fileTypeFromBuffer(res.text)
17+
const { mime } = await fileTypeFromBuffer(res.body)
1818
expect(mime).toBe('image/webp')
1919
})
2020

@@ -39,7 +39,7 @@ describe('dynamic assets', () => {
3939
})
4040
expect(res.statusCode).toBe(200)
4141
expect(res.headers['content-type']).toBe('image/webp')
42-
const image = sharp(res.text)
42+
const image = sharp(res.body)
4343
const { width, height } = await image.metadata()
4444
expect(width).toBe(1000)
4545
expect(height).toBe(747)
@@ -52,7 +52,7 @@ describe('dynamic assets', () => {
5252
})
5353
expect(res.statusCode).toBe(200)
5454
expect(res.headers['content-type']).toBe('image/webp')
55-
const image = sharp(res.text)
55+
const image = sharp(res.body)
5656
const { width, height } = await image.metadata()
5757
expect(width).toBe(448)
5858
expect(height).toBe(448)
@@ -69,14 +69,14 @@ describe('dynamic assets', () => {
6969
const res = await get('/assets/images/mw-0/_fixtures/screenshot.webp')
7070
expect(res.statusCode).toBe(400)
7171
expect(res.headers['content-type']).toMatch('text/plain')
72-
expect(res.text).toMatch('Error: width number (0) is not a valid number')
72+
expect(res.body).toMatch('Error: width number (0) is not a valid number')
7373
}
7474
// 1234 is not a number that is recognized
7575
{
7676
const res = await get('/assets/images/mw-1234/_fixtures/screenshot.webp')
7777
expect(res.statusCode).toBe(400)
7878
expect(res.headers['content-type']).toMatch('text/plain')
79-
expect(res.text).toMatch('Error: width number (1234) is not a valid number')
79+
expect(res.body).toMatch('Error: width number (1234) is not a valid number')
8080
}
8181
})
8282

tests/rendering-fixtures/images.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('render Markdown image tags', () => {
3232
// When transformed as a source in a `<picture>` tag, it's automatically
3333
// injected with the `mw-XXXXX` virtual indicator in the URL that
3434
// resizes it on-the-fly.
35-
const image = sharp(res.text)
35+
const image = sharp(res.body)
3636
const { width, height } = await image.metadata()
3737
expect(width).toBe(1000)
3838
// The `_fixtures/screenshot.png` is 2000x1494.

tests/rendering/api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ describe('general /api pages', () => {
1414
test("any /api/* URL that isn't found should be JSON", async () => {
1515
const res = await get('/api/yadayada')
1616
expect(res.statusCode).toBe(404)
17-
expect(JSON.parse(res.text).error).toBe('/yadayada not found')
17+
expect(JSON.parse(res.body).error).toBe('/yadayada not found')
1818
})
1919
})

tests/rendering/favicons.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('favicon assets', () => {
1515
expect(res.headers['cache-control']).toContain('public')
1616
expect(res.headers['cache-control']).toContain('immutable')
1717
expect(res.headers['cache-control']).toMatch(/max-age=\d+/)
18-
const maxAgeSeconds = parseInt(res.header['cache-control'].match(/max-age=(\d+)/)[1], 10)
18+
const maxAgeSeconds = parseInt(res.headers['cache-control'].match(/max-age=(\d+)/)[1], 10)
1919
// Let's not be too specific in the tests, just as long as it's testing
2020
// that it's a reasonably large number of seconds.
2121
expect(maxAgeSeconds).toBeGreaterThanOrEqual(60 * 60)
@@ -30,7 +30,7 @@ describe('favicon assets', () => {
3030
expect(res.headers['cache-control']).toContain('public')
3131
expect(res.headers['cache-control']).toContain('immutable')
3232
expect(res.headers['cache-control']).toMatch(/max-age=\d+/)
33-
const maxAgeSeconds = parseInt(res.header['cache-control'].match(/max-age=(\d+)/)[1], 10)
33+
const maxAgeSeconds = parseInt(res.headers['cache-control'].match(/max-age=(\d+)/)[1], 10)
3434
// Let's not be too specific in the tests, just as long as it's testing
3535
// that it's a reasonably large number of seconds.
3636
expect(maxAgeSeconds).toBeGreaterThanOrEqual(60 * 60)

tests/rendering/robots-txt.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ describe('robots.txt', () => {
3030
host: 'docs-internal-preview-12345-asdfz.azurecontainer.io',
3131
},
3232
})
33-
expect(res.text).toEqual('User-agent: *\nDisallow: /')
33+
expect(res.body).toEqual('User-agent: *\nDisallow: /')
3434
})
3535

3636
it('does not have duplicate lines', () => {
3737
const lines = new Set()
38-
for (const line of res.text.split('\n')) {
38+
for (const line of res.body.split('\n')) {
3939
if (/^\s*$/.test(line)) continue
4040
expect(lines.has(line)).toBe(false)
4141
lines.add(line)

0 commit comments

Comments
 (0)