mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-06 22:49:46 -06:00
internal: (studio) add network agent to the studio session call (#31617)
* internal: (studio) add network agent to the studio session call * Update packages/server/lib/cloud/api/studio/post_studio_session.ts Co-authored-by: Matt Schile <mschile@cypress.io> --------- Co-authored-by: Matt Schile <mschile@cypress.io>
This commit is contained in:
@@ -2,6 +2,7 @@ import { asyncRetry, linearDelay } from '../../../util/async_retry'
|
||||
import { isRetryableError } from '../../network/is_retryable_error'
|
||||
import fetch from 'cross-fetch'
|
||||
import os from 'os'
|
||||
import { agent } from '@packages/network'
|
||||
|
||||
const pkg = require('@packages/root')
|
||||
const routes = require('../../routes') as typeof import('../../routes')
|
||||
@@ -15,6 +16,8 @@ const _delay = linearDelay(500)
|
||||
export const postStudioSession = async ({ projectId }: GetStudioSessionOptions) => {
|
||||
return await (asyncRetry(async () => {
|
||||
const response = await fetch(routes.apiRoutes.studioSession(), {
|
||||
// @ts-expect-error - this is supported
|
||||
agent,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { SystemError } from '../../../../../lib/cloud/network/system_error'
|
||||
import { proxyquire } from '../../../../spec_helper'
|
||||
import os from 'os'
|
||||
import { agent } from '@packages/network'
|
||||
import pkg from '@packages/root'
|
||||
|
||||
describe('postStudioSession', () => {
|
||||
let postStudioSession: typeof import('@packages/server/lib/cloud/api/studio/post_studio_session').postStudioSession
|
||||
@@ -31,6 +34,21 @@ describe('postStudioSession', () => {
|
||||
studioUrl: 'http://localhost:1234/studio/bundle/abc.tgz',
|
||||
protocolUrl: 'http://localhost:1234/capture-protocol/script/def.js',
|
||||
})
|
||||
|
||||
expect(crossFetchStub).to.have.been.calledOnce
|
||||
expect(crossFetchStub).to.have.been.calledWith(
|
||||
'http://localhost:1234/studio/session',
|
||||
{
|
||||
method: 'POST',
|
||||
agent,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-os-name': os.platform(),
|
||||
'x-cypress-version': pkg.version,
|
||||
},
|
||||
body: JSON.stringify({ projectSlug: '12345', studioMountVersion: 1, protocolMountVersion: 2 }),
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
it('should throw immediately if the response is not ok', async () => {
|
||||
|
||||
Reference in New Issue
Block a user