Skip to content
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

fix: cy.request allows nested objects as qs #27908

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ _Released 1/16/2024 (PENDING)_
- When generating assertions via Cypress Studio, the preview of the generated assertions now correctly displays the past tense of 'expected' instead of 'expect'. Fixed in [#28593](https://github.com/cypress-io/cypress/pull/28593).
- Fixed a regression in [`13.6.2`](https://docs.cypress.io/guides/references/changelog/13.6.2) where the `body` element was not highlighted correctly in Test Replay. Fixed in [#28627](https://github.com/cypress-io/cypress/pull/28627).
- Fixed an issue where some cross-origin logs, like assertions or cy.clock(), were getting too many dom snapshots. Fixes [#28609](https://github.com/cypress-io/cypress/issues/28609).
- Fixed an issue where nested object url queries would be incorrectly serialized in `cy.request()` and `cy.visit()`. Fixes [#27745](https://github.com/cypress-io/cypress/issues/27745). Addressed in [#27908](https://github.com/cypress-io/cypress/pull/27908).

**Performance:**

Expand All @@ -19,6 +20,7 @@ _Released 1/16/2024 (PENDING)_

- Remove dependency on `@types/node` package. Addresses [#28473](https://github.com/cypress-io/cypress/issues/28473).
- Updated `@cypress/unique-selector` to include a performance optimization. It's possible this could improve performance of the selector playground. Addressed in [#28571](https://github.com/cypress-io/cypress/pull/28571).
- Added dependency to [npm [email protected]](https://www.npmjs.com/package/qs) in driver. Addressed in [#27908](https://github.com/cypress-io/cypress/pull/27908).

**Misc:**

Expand Down
10 changes: 10 additions & 0 deletions packages/driver/cypress/e2e/commands/navigation.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,16 @@ describe('src/cy/commands/navigation', () => {
})
})

it('can send nested querystring params', () => {
const qs = { foo: { bar: 'baz', quux: [1, 2, 3] } }

cy
.visit('http://localhost:3500/dump-qs', { qs })
.then(() => {
cy.url().should('eq', 'http://localhost:3500/dump-qs?foo%5Bbar%5D=baz&foo%5Bquux%5D=1%2C2%2C3')
})
})

describe('can send a POST request', () => {
it('automatically urlencoded using an object body', () => {
cy.visit('http://localhost:3500/post-only', {
Expand Down
24 changes: 24 additions & 0 deletions packages/driver/cypress/e2e/commands/request.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,30 @@ describe('src/cy/commands/request', () => {
})
})
})

it('accepts a nested object', () => {
cy.request({
url: 'http://localhost:8888',
qs: { foo: { bar: 'baz' } },
})
.then(function () {
this.expectOptionsToBe({
url: 'http://localhost:8888/?foo%5Bbar%5D=baz',
})
})
})

it('accepts a nested array', () => {
cy.request({
url: 'http://localhost:8888',
qs: { foo: [['bar', 'baz'], ['qux']] },
})
.then(function () {
this.expectOptionsToBe({
url: 'http://localhost:8888/?foo=bar%2Cbaz%2Cqux',
})
})
})
})

context('form', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"mocha": "7.0.1",
"multer": "1.4.2",
"ordinal": "1.0.3",
"qs": "6.11.2",
"react-15.6.1": "npm:[email protected]",
"react-16.0.0": "npm:[email protected]",
"react-dom-15.6.1": "npm:[email protected]",
Expand Down
9 changes: 8 additions & 1 deletion packages/driver/src/cypress/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import _ from 'lodash'
import UrlParse from 'url-parse'
import * as cors from '@packages/network/lib/cors'
import qs from 'qs'

const reHttp = /^https?:\/\//
const reWww = /^www/
Expand Down Expand Up @@ -170,7 +171,13 @@ export class $Location {

static mergeUrlWithParams (url, params) {
url = new UrlParse(url, null, true)
url.set('query', _.merge(url.query || {}, params))
const query = _.merge(url.query || {}, params)

// Use qs over UrlParse for parsing queries to accept
// queries as nested objects and arrays #27908
const queryString = qs.stringify(query, { arrayFormat: 'comma' })

url.set('query', queryString)

return url.toString()
}
Expand Down
38 changes: 19 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6609,21 +6609,21 @@
"@types/node" "*"

"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz#4ba8ddb720221f432e443bd5f9117fd22cfd4762"
integrity sha512-sz7iLqvVUg1gIedBOvlkxPlc8/uVzyS5OwGz1cKjXzkl3FpL3al0crU8YGU1WoHkxn0Wxbw5tyi6hvzJKNzFsw==
version "2.0.4"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz#8467d4b3c087805d63580480890791277ce35c44"
integrity sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==

"@types/istanbul-lib-report@*":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.0.tgz#c14c24f18ea8190c118ee7562b7ff99a36552686"
integrity sha512-plGgXAPfVKFoYfa9NpYDAkseG+g6Jr294RqeqcqDixSbU34MZVJRi/P+7Y8GDpzkEwLaGZZOpKIEmeVZNtKsrg==
version "3.0.1"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.1.tgz#412e0725ef41cde73bfa03e0e833eaff41e0fd63"
integrity sha512-gPQuzaPR5h/djlAv2apEG1HVOyj1IUs7GpfMZixU0/0KXT3pm64ylHuMUI1/Akh+sq/iikxg6Z2j+fcMDXaaTQ==
dependencies:
"@types/istanbul-lib-coverage" "*"

"@types/istanbul-reports@^3.0.0":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@types/istanbul-reports/-/istanbul-reports-3.0.1.tgz#9153fe98bba2bd565a63add9436d6f0d7f8468ff"
integrity sha512-c3mAZEuK0lvBp8tmuL74XRKn1+y2dcwOUpH7x4WrF6gk1GIgiluDRgMYQtw2OFcBvAJWlt6ASU3tSqxp0Uu0Aw==
version "3.0.2"
resolved "https://registry.yarnpkg.com/@types/istanbul-reports/-/istanbul-reports-3.0.2.tgz#edc8e421991a3b4df875036d381fc0a5a982f549"
integrity sha512-kv43F9eb3Lhj+lr/Hn6OcLCs/sSM8bt+fIaP11rCYngfV6NVjzWXJ17owQtDQTL9tQ8WSLUrGsSJ6rJz0F1w1A==
dependencies:
"@types/istanbul-lib-report" "*"

Expand Down Expand Up @@ -7278,9 +7278,9 @@
integrity sha512-37RSHht+gzzgYeobbG+KWryeAW8J33Nhr69cjTqSYymXVZEN9NbRYWoYlRtDhHKPVT1FyNKwaTPC1NynKZpzRA==

"@types/yargs@^15.0.0":
version "15.0.14"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-15.0.14.tgz#26d821ddb89e70492160b66d10a0eb6df8f6fb06"
integrity sha512-yEJzHoxf6SyQGhBhIYGXQDSCkJjB6HohDShto7m8vaKg9Yp0Yn8+71J9eakh2bnPg6BfsH9PRMhiRTZnd4eXGQ==
version "15.0.16"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-15.0.16.tgz#258009dc52907e8f03041eb64ffdac297ba4b208"
integrity sha512-2FeD5qezW3FvLpZ0JpfuaEWepgNLl9b2gQYiz/ce0NhoB1W/D+VZu98phITXkADYerfr/jb7JcDcVhITsc9bwg==
dependencies:
"@types/yargs-parser" "*"

Expand Down Expand Up @@ -24436,6 +24436,13 @@ qrcode-terminal@^0.12.0:
resolved "https://registry.yarnpkg.com/qrcode-terminal/-/qrcode-terminal-0.12.0.tgz#bb5b699ef7f9f0505092a3748be4464fe71b5819"
integrity sha512-EXtzRZmC+YGmGlDFbXKxQiMZNwCLEO6BANKXG4iCtSIM0yqc/pappSx3RIKr4r0uh5JsBckOXeKrB3Iz7mdQpQ==

[email protected], qs@^6.11.0, qs@^6.4.0, qs@^6.5.1, qs@^6.9.4:
version "6.11.2"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.11.2.tgz#64bea51f12c1f5da1bc01496f48ffcff7c69d7d9"
integrity sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==
dependencies:
side-channel "^1.0.4"

[email protected]:
version "6.7.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc"
Expand All @@ -24446,13 +24453,6 @@ [email protected]:
resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.7.tgz#4610846871485e1e048f44ae3b94033f0e675afe"
integrity sha512-IhMFgUmuNpyRfxA90umL7ByLlgRXu6tIfKPpF5TmcfRLlLCckfP/g3IQmju6jjpu+Hh8rA+2p6A27ZSPOOHdKw==

qs@^6.11.0, qs@^6.4.0, qs@^6.5.1, qs@^6.9.4:
version "6.11.2"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.11.2.tgz#64bea51f12c1f5da1bc01496f48ffcff7c69d7d9"
integrity sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==
dependencies:
side-channel "^1.0.4"

qs@~6.10.3:
version "6.10.5"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.10.5.tgz#974715920a80ff6a262264acd2c7e6c2a53282b4"
Expand Down
Loading