Skip to content

Commit

Permalink
Use process.env.VITEST_POOL_ID if present
Browse files Browse the repository at this point in the history
  • Loading branch information
toolmantim committed Mar 17, 2024
1 parent 5a94b6e commit fedc4f1
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/shared/src/sourcegraph-api/graphql/client.ts
Expand Up @@ -810,7 +810,7 @@ export class SourcegraphGraphQLAPIClient {

// make an anonymous request to the Testing API
private fetchSourcegraphTestingAPI<T>(body: Record<string, any>): Promise<T | Error> {
const url = 'http://localhost:49300/.api/testLogging'
const url = `http://localhost:4930${process.env.VITEST_POOL_ID || '0'}/.api/testLogging`
const headers = new Headers({
'Content-Type': 'application/json',
})
Expand Down
Expand Up @@ -3,12 +3,12 @@ import type { TelemetryEventInput, TelemetryExporter } from '@sourcegraph/teleme
import { logError } from '../../logger'
import { isError } from '../../utils'

const MOCK_URL = 'http://localhost:49300'
const MOCK_URL = `http://localhost:4930${process.env.VITEST_POOL_ID || '0'}`
const ENDPOINT = '/.api/mockEventRecording'

/**
* MockServerTelemetryExporter exports events to a mock endpoint at
* http://localhost:49300/.api/mockEventRecording
* http://localhost:4930${/.api/mockEventRecording
*/
export class MockServerTelemetryExporter implements TelemetryExporter {
constructor(private anonymousUserID: string) {}
Expand Down
5 changes: 3 additions & 2 deletions vscode/src/configuration.ts
Expand Up @@ -17,6 +17,8 @@ import {
import { localStorage } from './services/LocalStorageProvider'
import { getAccessToken } from './services/SecretStorageProvider'

import { SERVER_URL as MOCK_SERVER_URL } from '../test/fixtures/mock-server'

interface ConfigGetter {
get<T>(section: (typeof CONFIG_KEY)[ConfigKeys], defaultValue?: T): T
}
Expand Down Expand Up @@ -186,8 +188,7 @@ function sanitizeCodebase(codebase: string | undefined): string {
export const getFullConfig = async (): Promise<ConfigurationWithAccessToken> => {
const config = getConfiguration()
const isTesting = process.env.CODY_TESTING === 'true'
const serverEndpoint =
localStorage?.getEndpoint() || (isTesting ? 'http://localhost:49300/' : DOTCOM_URL.href)
const serverEndpoint = localStorage?.getEndpoint() || (isTesting ? MOCK_SERVER_URL : DOTCOM_URL.href)
const accessToken = (await getAccessToken()) || null
return { ...config, accessToken, serverEndpoint }
}
Expand Down
4 changes: 3 additions & 1 deletion vscode/test/e2e/helpers.ts
Expand Up @@ -12,6 +12,8 @@ import { MockServer, loggedEvents, resetLoggedEvents, sendTestInfo } from '../fi
import { installVsCode } from './install-deps'
import { buildCustomCommandConfigFile } from './utils/buildCustomCommands'

import { SERVER_URL as MOCK_SERVER_URL } from '../fixtures/mock-server'

// Playwright test extension: The workspace directory to run the test in.
export interface WorkspaceDirectory {
workspaceDirectory: string
Expand Down Expand Up @@ -258,7 +260,7 @@ async function buildWorkSpaceSettings(
extraSettings: WorkspaceSettings
): Promise<void> {
const settings = {
'cody.serverEndpoint': 'http://localhost:49300',
'cody.serverEndpoint': MOCK_SERVER_URL,
'cody.commandCodeLenses': true,
'cody.editorTitleCommandIcon': true,
...extraSettings,
Expand Down
1 change: 0 additions & 1 deletion vscode/test/fixtures/.vscode/settings.json
@@ -1,5 +1,4 @@
{
"cody.codebase": "http://localhost:49300",
"cody.debug.enable": true,
"cody.debug.verbose": true,
}
6 changes: 3 additions & 3 deletions vscode/test/fixtures/mock-server.ts
Expand Up @@ -18,9 +18,9 @@ interface MockRequest {
}
}

const SERVER_PORT = 49300

export const SERVER_URL = 'http://localhost:49300'
// Support vitest parallelism
const SERVER_PORT = Number(`4930${process.env.VITEST_POOL_ID || '0'}`)
export const SERVER_URL = `http://localhost:${SERVER_PORT}`
export const VALID_TOKEN = 'sgp_1234567890123456789012345678901234567890'

const responses = {
Expand Down
1 change: 0 additions & 1 deletion vscode/test/fixtures/multi-root.code-workspace
Expand Up @@ -10,7 +10,6 @@
"settings": {
// Settings that should also apply to the single-root workspace tests should also be
// included in fixtures\workspace\.vscode\settings.json!
"cody.serverEndpoint": "http://localhost:49300",
"cody.commandCodeLenses": true,
"cody.editorTitleCommandIcon": true,
"cody.experimental.symfContext": false,
Expand Down

0 comments on commit fedc4f1

Please sign in to comment.