-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(fetch): use undici + ProxyAgent
#1000
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3269cdc
test: remove MSW in favor of nock
kanadgupta f72351a
test: remove useless connection delay
kanadgupta f80d95a
test: remove last instance of MSW
kanadgupta 951624f
test: remove msw helper
kanadgupta 1d2b5f1
chore(deps): uninstall msw
kanadgupta 1be0390
chore: whoops also remove this
kanadgupta b9cc12b
chore(deps): remove node-fetch and formdata-node
kanadgupta 04fe2f4
feat: use undici ProxyAgent
kanadgupta 2c0f8e3
test: add note
kanadgupta 5d7f6ad
ci: pin undici
kanadgupta f21ab26
Merge branch 'next' into kanad-2024-05-06/remove-msw
kanadgupta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,6 @@ | |
import fs from 'node:fs'; | ||
|
||
import chalk from 'chalk'; | ||
import { http } from 'msw'; | ||
import { setupServer } from 'msw/node'; | ||
import nock from 'nock'; | ||
import prompts from 'prompts'; | ||
import { describe, beforeAll, beforeEach, afterEach, it, expect, vi } from 'vitest'; | ||
|
@@ -135,7 +133,6 @@ describe('rdme openapi', () => { | |
.basicAuth({ user: key }) | ||
.reply(200, [{ _id: 'spec1', title: 'spec1_title' }]) | ||
.post('/api/v1/api-specification', { registryUUID }) | ||
.delayConnection(1000) | ||
.basicAuth({ user: key }) | ||
.reply(201, { _id: 1 }, { location: exampleRefLocation }); | ||
|
||
|
@@ -165,7 +162,6 @@ describe('rdme openapi', () => { | |
|
||
const postMock = getAPIMockWithVersionHeader(version) | ||
.post('/api/v1/api-specification', { registryUUID }) | ||
.delayConnection(1000) | ||
.basicAuth({ user: key }) | ||
.reply(201, { _id: 1 }, { location: exampleRefLocation }); | ||
|
||
|
@@ -196,7 +192,6 @@ describe('rdme openapi', () => { | |
|
||
const postMock = getAPIMockWithVersionHeader(version) | ||
.post('/api/v1/api-specification', { registryUUID }) | ||
.delayConnection(1000) | ||
.basicAuth({ user: key }) | ||
.reply(201, { _id: 1 }, { location: exampleRefLocation }); | ||
|
||
|
@@ -416,7 +411,6 @@ describe('rdme openapi', () => { | |
{ _id: 'spec2', title: 'spec2_title' }, | ||
]) | ||
.put('/api/v1/api-specification/spec2', { registryUUID }) | ||
.delayConnection(1000) | ||
.basicAuth({ user: key }) | ||
.reply(201, { _id: 1 }, { location: exampleRefLocation }); | ||
|
||
|
@@ -484,7 +478,6 @@ describe('rdme openapi', () => { | |
.basicAuth({ user: key }) | ||
.reply(200, [{ _id: 'spec1', title: 'spec1_title' }]) | ||
.put('/api/v1/api-specification/spec1', { registryUUID }) | ||
.delayConnection(1000) | ||
.basicAuth({ user: key }) | ||
.reply(201, { _id: 1 }, { location: exampleRefLocation }); | ||
|
||
|
@@ -544,7 +537,6 @@ describe('rdme openapi', () => { | |
.post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) | ||
.reply(201, { registryUUID, spec: { openapi: '3.0.0' } }) | ||
.put('/api/v1/api-specification/spec1', { registryUUID }) | ||
.delayConnection(1000) | ||
.basicAuth({ user: key }) | ||
.reply(function (uri, rBody, cb) { | ||
expect(this.req.headers['x-readme-version']).toBeUndefined(); | ||
|
@@ -824,7 +816,6 @@ describe('rdme openapi', () => { | |
.basicAuth({ user: key }) | ||
.reply(200, []) | ||
.post('/api/v1/api-specification', { registryUUID }) | ||
.delayConnection(1000) | ||
.basicAuth({ user: key }) | ||
.reply(400, errorObject); | ||
|
||
|
@@ -856,7 +847,6 @@ describe('rdme openapi', () => { | |
|
||
const putMock = getAPIMockWithVersionHeader(version) | ||
.put(`/api/v1/api-specification/${id}`, { registryUUID }) | ||
.delayConnection(1000) | ||
.basicAuth({ user: key }) | ||
.reply(400, errorObject); | ||
|
||
|
@@ -922,7 +912,6 @@ describe('rdme openapi', () => { | |
.basicAuth({ user: key }) | ||
.reply(200, []) | ||
.post('/api/v1/api-specification', { registryUUID }) | ||
.delayConnection(1000) | ||
.basicAuth({ user: key }) | ||
.reply(400, errorObject); | ||
|
||
|
@@ -949,7 +938,6 @@ describe('rdme openapi', () => { | |
.basicAuth({ user: key }) | ||
.reply(200, []) | ||
.post('/api/v1/api-specification', { registryUUID }) | ||
.delayConnection(1000) | ||
.basicAuth({ user: key }) | ||
.reply(400, 'some non-JSON upload error'); | ||
|
||
|
@@ -980,7 +968,6 @@ describe('rdme openapi', () => { | |
.basicAuth({ user: key }) | ||
.reply(200, []) | ||
.post('/api/v1/api-specification', { registryUUID }) | ||
.delayConnection(1000) | ||
.basicAuth({ user: key }) | ||
.reply(500, '<title>Application Error</title>'); | ||
|
||
|
@@ -1028,7 +1015,6 @@ describe('rdme openapi', () => { | |
.basicAuth({ user: key }) | ||
.reply(200, [{ _id: 'spec1', title: 'spec1_title' }]) | ||
.post('/api/v1/api-specification', { registryUUID }) | ||
.delayConnection(1000) | ||
.basicAuth({ user: key }) | ||
.reply(201, { _id: 1 }, { location: exampleRefLocation }); | ||
|
||
|
@@ -1071,7 +1057,6 @@ describe('rdme openapi', () => { | |
.basicAuth({ user: key }) | ||
.reply(200, [{ _id: 'spec1', title: 'spec1_title' }]) | ||
.post('/api/v1/api-specification', { registryUUID }) | ||
.delayConnection(1000) | ||
.basicAuth({ user: key }) | ||
.reply(201, { _id: 1 }, { location: exampleRefLocation }); | ||
|
||
|
@@ -1118,7 +1103,6 @@ describe('rdme openapi', () => { | |
{ _id: 'spec2', title: 'spec2_title' }, | ||
]) | ||
.put('/api/v1/api-specification/spec2', { registryUUID }) | ||
.delayConnection(1000) | ||
.basicAuth({ user: key }) | ||
.reply(201, { _id: 'spec2' }, { location: exampleRefLocation }); | ||
|
||
|
@@ -1155,7 +1139,6 @@ describe('rdme openapi', () => { | |
|
||
const mockWithHeader = getAPIMockWithVersionHeader(altVersion) | ||
.post('/api/v1/api-specification', { registryUUID }) | ||
.delayConnection(1000) | ||
.basicAuth({ user: key }) | ||
.reply(201, { _id: 1 }, { location: exampleRefLocation }); | ||
|
||
|
@@ -1192,7 +1175,6 @@ describe('rdme openapi', () => { | |
|
||
const postMock = getAPIMockWithVersionHeader(version) | ||
.post('/api/v1/api-specification', { registryUUID }) | ||
.delayConnection(1000) | ||
.basicAuth({ user: key }) | ||
.reply(201, { _id: 1 }, { location: exampleRefLocation }); | ||
|
||
|
@@ -1232,7 +1214,6 @@ describe('rdme openapi', () => { | |
.basicAuth({ user: key }) | ||
.reply(200, [{ _id: 'spec1', title: 'spec1_title' }]) | ||
.put('/api/v1/api-specification/spec1', { registryUUID }) | ||
.delayConnection(1000) | ||
.basicAuth({ user: key }) | ||
.reply(201, { _id: 1 }, { location: exampleRefLocation }); | ||
|
||
|
@@ -1270,7 +1251,6 @@ describe('rdme openapi', () => { | |
.basicAuth({ user: key }) | ||
.reply(200, [{ _id: 'spec1', title: 'spec1_title' }]) | ||
.post('/api/v1/api-specification', { registryUUID }) | ||
.delayConnection(1000) | ||
.basicAuth({ user: key }) | ||
.reply(201, { _id: 1 }, { location: exampleRefLocation }); | ||
|
||
|
@@ -1350,37 +1330,24 @@ describe('rdme openapi', () => { | |
}); | ||
|
||
it('should send proper headers in GitHub Actions CI for spec hosted at URL', async () => { | ||
expect.assertions(8); | ||
const registryUUID = getRandomRegistryId(); | ||
const spec = 'https://example.com/openapi.json'; | ||
|
||
// TODO: move all of this boilerplate to the top-level once we migrate everything over to MSW | ||
const server = setupServer(...[]); | ||
const mock = getAPIMock() | ||
.post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) | ||
.reply(201, { registryUUID }); | ||
|
||
server.listen({ onUnhandledRequest: 'error' }); | ||
const exampleMock = nock('https://example.com').get('/openapi.json').reply(200, petstoreWeird); | ||
|
||
server.use( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. msw i think you're really neat but my dude... the code bloat There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah... once nock started using the same underlying interceptor, it was game over |
||
...[ | ||
http.post(`${config.host}/api/v1/api-registry`, async ({ request }) => { | ||
const body = await request.text(); | ||
expect(body).toMatch('form-data; name="spec"'); | ||
return Response.json({ registryUUID }, { status: 201 }); | ||
}), | ||
http.get(spec, () => { | ||
return Response.json(petstoreWeird, { status: 200 }); | ||
}), | ||
http.put(`${config.host}/api/v1/api-specification/${id}`, async ({ request }) => { | ||
expect(request.headers.get('authorization')).toBeBasicAuthApiKey(key); | ||
expect(request.headers.get('x-rdme-ci')).toBe('GitHub Actions (test)'); | ||
expect(request.headers.get('x-readme-source')).toBe('cli-gh'); | ||
expect(request.headers.get('x-readme-source-url')).toBe(spec); | ||
expect(request.headers.get('x-readme-version')).toBe(version); | ||
const body = await request.json(); | ||
expect(body).toStrictEqual({ registryUUID }); | ||
return Response.json({ _id: 1 }, { status: 201, headers: { location: exampleRefLocation } }); | ||
}), | ||
], | ||
); | ||
const putMock = getAPIMock({ | ||
'x-rdme-ci': 'GitHub Actions (test)', | ||
'x-readme-source': 'cli-gh', | ||
'x-readme-source-url': spec, | ||
'x-readme-version': version, | ||
}) | ||
.put(`/api/v1/api-specification/${id}`, { registryUUID }) | ||
.basicAuth({ user: key }) | ||
.reply(201, { _id: 1 }, { location: exampleRefLocation }); | ||
|
||
await expect( | ||
openapi.run({ | ||
|
@@ -1391,7 +1358,9 @@ describe('rdme openapi', () => { | |
}), | ||
).resolves.toBe(successfulUpdate(spec)); | ||
|
||
return server.resetHandlers(); | ||
putMock.done(); | ||
exampleMock.done(); | ||
return mock.done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love to see it