-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix: large responses now download correctly [INS-2365] #9807
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
Open
arora-r
wants to merge
9
commits into
Kong:develop
Choose a base branch
from
arora-r:fix/large-response-downloads
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a8085dc
fix: large responses now download correctly
arora-r ee98e97
Merge branch 'develop' into fix/large-response-downloads
arora-r 42c4a1a
fix: linting
arora-r 8a79b63
chore: add e2e testing to prevent future regressions
arora-r 07945a9
Merge branch 'develop' into fix/large-response-downloads
arora-r 92a24fc
Merge branch 'develop' into fix/large-response-downloads
arora-r 8c0c438
Merge branch 'develop' into fix/large-response-downloads
arora-r ebc7f04
Merge branch 'develop' into fix/large-response-downloads
arora-r 9b814c3
Merge branch 'develop' into fix/large-response-downloads
arora-r 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
50 changes: 50 additions & 0 deletions
50
packages/insomnia-smoke-test/fixtures/response-download-collection.yaml
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| type: collection.insomnia.rest/5.0 | ||
| schema_version: "5.1" | ||
| name: Response Download Tests | ||
| meta: | ||
| id: wrk_response_download_tests_001 | ||
| created: 1776178027509 | ||
| modified: 1776178027509 | ||
| collection: | ||
| - url: http://127.0.0.1:4010/pets/1 | ||
| name: JSON Request | ||
| meta: | ||
| id: req_0d0ec3bafe584da3a3ecfc668bf2824a | ||
| created: 1776178029290 | ||
| modified: 1776178033770 | ||
| isPrivate: false | ||
| description: "" | ||
| sortKey: -1776178029290 | ||
| method: GET | ||
| headers: | ||
| - name: Content-Type | ||
| value: application/json | ||
| settings: | ||
| renderRequestBody: true | ||
| encodeUrl: true | ||
| followRedirects: global | ||
| cookies: | ||
| send: true | ||
| store: true | ||
| rebuildPath: true | ||
| - url: http://127.0.0.1:4010/large-json | ||
| name: Large JSON Request | ||
| meta: | ||
| id: req_10813c5f0ea14388a5141987645e2e94 | ||
| created: 1776178064890 | ||
| modified: 1776178068539 | ||
| isPrivate: false | ||
| description: "" | ||
| sortKey: -1776178064890 | ||
| method: GET | ||
| headers: | ||
| - name: Content-Type | ||
| value: application/json | ||
| settings: | ||
| renderRequestBody: true | ||
| encodeUrl: true | ||
| followRedirects: global | ||
| cookies: | ||
| send: true | ||
| store: true | ||
| rebuildPath: true | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -54,6 +54,15 @@ app.get('/pets/:id', (req, res) => { | |
| res.status(200).send({ id: req.params.id }); | ||
| }); | ||
|
|
||
| app.get('/large-json', (_req, res) => { | ||
| const items = Array.from({ length: 100_000 }, (_, i) => ({ | ||
| id: i, | ||
| name: `item-${i}`, | ||
| value: 'x'.repeat(100), | ||
| })); | ||
| res.status(200).json({ items }); | ||
| }); | ||
|
Comment on lines
+57
to
+64
Author
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. Generates ~13MB response size |
||
|
|
||
| app.get('/builds/check/*', (_req, res) => { | ||
| res.status(200).send({ | ||
| url: 'https://github.com/Kong/insomnia/releases/download/core@2023.5.6/Insomnia.Core-2023.5.6.zip', | ||
|
|
||
114 changes: 114 additions & 0 deletions
114
packages/insomnia-smoke-test/tests/smoke/response-downloads.test.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
|
|
||
| import { expect } from '@playwright/test'; | ||
|
|
||
| import { test } from '../../playwright/test'; | ||
| import { | ||
| cleanupExportDir, | ||
| createTempExportDir, | ||
| mockSaveDialogForFile, | ||
| readExportedFile, | ||
| waitForExportFiles, | ||
| } from '../../playwright/utils'; | ||
|
|
||
| test.describe('Response Downloads', () => { | ||
| test.slow(process.platform === 'darwin' || process.platform === 'win32', 'Slow app start on these platforms'); | ||
|
|
||
| const FIXTURE = 'response-download-collection.yaml'; | ||
|
|
||
| test('Can export raw response body', async ({ insomnia, app, page }) => { | ||
| await insomnia.projectPage.importFixture(FIXTURE); | ||
| await page.getByLabel('Request Collection').getByTestId('JSON Request').press('Enter'); | ||
| await page.getByTestId('request-pane').getByRole('button', { name: 'Send' }).click(); | ||
| await expect.soft(page.locator('[data-testid="response-status-tag"]:visible')).toContainText('200 OK'); | ||
|
|
||
| const tempDir = createTempExportDir(); | ||
| const exportPath = path.join(tempDir, 'response-raw.json'); | ||
| try { | ||
| await mockSaveDialogForFile(app, exportPath); | ||
| await page.getByRole('button', { name: 'Preview' }).click(); | ||
| await page.getByRole('menuitem', { name: 'Export raw response' }).click(); | ||
| await waitForExportFiles(tempDir, 1); | ||
| const content = readExportedFile(exportPath); | ||
| expect.soft(content).toContain('"id"'); | ||
| expect.soft(content).toContain('"1"'); | ||
| } finally { | ||
| cleanupExportDir(tempDir); | ||
| } | ||
| }); | ||
|
|
||
| test('Can export prettified JSON response', async ({ insomnia, app, page }) => { | ||
| await insomnia.projectPage.importFixture(FIXTURE); | ||
| await page.getByLabel('Request Collection').getByTestId('JSON Request').press('Enter'); | ||
| await page.getByTestId('request-pane').getByRole('button', { name: 'Send' }).click(); | ||
| await expect.soft(page.locator('[data-testid="response-status-tag"]:visible')).toContainText('200 OK'); | ||
|
|
||
| const tempDir = createTempExportDir(); | ||
| const exportPath = path.join(tempDir, 'response-pretty.json'); | ||
| try { | ||
| await mockSaveDialogForFile(app, exportPath); | ||
| await page.getByRole('button', { name: 'Preview' }).click(); | ||
| await page.getByRole('menuitem', { name: 'Export prettified response' }).click(); | ||
| await waitForExportFiles(tempDir, 1); | ||
| const content = readExportedFile(exportPath); | ||
| const parsed = JSON.parse(content); | ||
| expect.soft(parsed.id).toBe('1'); | ||
| expect.soft(content.length).toBeGreaterThan('{"id":"1"}'.length); | ||
| } finally { | ||
| cleanupExportDir(tempDir); | ||
| } | ||
| }); | ||
|
|
||
| test('Can export HTTP debug file', async ({ insomnia, app, page }) => { | ||
| await insomnia.projectPage.importFixture(FIXTURE); | ||
| await page.getByLabel('Request Collection').getByTestId('JSON Request').press('Enter'); | ||
| await page.getByTestId('request-pane').getByRole('button', { name: 'Send' }).click(); | ||
| await expect.soft(page.locator('[data-testid="response-status-tag"]:visible')).toContainText('200 OK'); | ||
|
|
||
| const tempDir = createTempExportDir(); | ||
| const exportPath = path.join(tempDir, 'response-debug.txt'); | ||
| try { | ||
| await mockSaveDialogForFile(app, exportPath); | ||
| await page.getByRole('button', { name: 'Preview' }).click(); | ||
| await page.getByRole('menuitem', { name: 'Export HTTP debug' }).click(); | ||
| await waitForExportFiles(tempDir, 1); | ||
| const content = readExportedFile(exportPath); | ||
| expect.soft(content).toContain('Content-Type'); | ||
| expect.soft(content).toContain('"id"'); | ||
| } finally { | ||
| cleanupExportDir(tempDir); | ||
| } | ||
| }); | ||
|
|
||
| test('Can export raw large response body', async ({ insomnia, app, page }) => { | ||
| await insomnia.projectPage.importFixture(FIXTURE); | ||
| await page.getByLabel('Request Collection').getByTestId('Large JSON Request').press('Enter'); | ||
| await page.getByTestId('request-pane').getByRole('button', { name: 'Send' }).click(); | ||
| await expect.soft(page.locator('[data-testid="response-status-tag"]:visible')).toContainText('200 OK'); | ||
|
|
||
| const tempDir = createTempExportDir(); | ||
| const exportPath = path.join(tempDir, 'response-large.json'); | ||
| try { | ||
| await mockSaveDialogForFile(app, exportPath); | ||
| await page.getByRole('button', { name: 'Preview' }).click(); | ||
| await page.getByRole('menuitem', { name: 'Export raw response' }).click(); | ||
| await waitForExportFiles(tempDir, 1, 30_000); | ||
| const { size } = fs.statSync(exportPath); | ||
| expect.soft(size).toBeGreaterThan(5 * 1024 * 1024); | ||
| } finally { | ||
| cleanupExportDir(tempDir); | ||
| } | ||
| }); | ||
|
|
||
| test('Prettified export is disabled for large JSON response', async ({ insomnia, page }) => { | ||
| await insomnia.projectPage.importFixture(FIXTURE); | ||
| await page.getByLabel('Request Collection').getByTestId('Large JSON Request').press('Enter'); | ||
| await page.getByTestId('request-pane').getByRole('button', { name: 'Send' }).click(); | ||
| await expect.soft(page.locator('[data-testid="response-status-tag"]:visible')).toContainText('200 OK'); | ||
|
|
||
| await page.getByRole('button', { name: 'Preview' }).click(); | ||
| const prettifyItem = page.getByRole('menuitem', { name: 'Export prettified response' }); | ||
| await expect.soft(prettifyItem).toContainText('must be <5MB'); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Created the collection in the insomnia app and then exported them for this file