diff --git a/web/package.json b/web/package.json index 07901cd57c82bd..5820eebebc88cc 100644 --- a/web/package.json +++ b/web/package.json @@ -6,7 +6,7 @@ "license": "MIT", "scripts": { "test": "jest --testPathIgnorePatterns end-to-end --testPathIgnorePatterns regression integration", - "test:integration": "mocha ./src/integration/**/*.test.ts", + "test:integration": "NODE_NO_WARNINGS=1 mocha ./src/integration/**/*.test.ts", "test:regression": "mocha './src/regression/**/*.test.ts'", "test:regression:auth": "mocha ./src/regression/auth.test.ts", "test:regression:codeintel": "mocha ./src/regression/codeintel.test.ts", diff --git a/web/src/enterprise/codeintel/CodeIntelIndexPage.story.tsx b/web/src/enterprise/codeintel/CodeIntelIndexPage.story.tsx index 25a5caf87f62cc..af0dd0e02e28f4 100644 --- a/web/src/enterprise/codeintel/CodeIntelIndexPage.story.tsx +++ b/web/src/enterprise/codeintel/CodeIntelIndexPage.story.tsx @@ -7,6 +7,7 @@ import * as GQL from '../../../../shared/src/graphql/schema' import * as H from 'history' import React from 'react' import webStyles from '../../SourcegraphWebApp.scss' +import { SourcegraphContext } from '../../jscontext' window.context = {} as SourcegraphContext & SuiteFunction diff --git a/web/src/enterprise/codeintel/CodeIntelIndexesPage.story.tsx b/web/src/enterprise/codeintel/CodeIntelIndexesPage.story.tsx index ed050b433d5c3b..6b42ef958d45a8 100644 --- a/web/src/enterprise/codeintel/CodeIntelIndexesPage.story.tsx +++ b/web/src/enterprise/codeintel/CodeIntelIndexesPage.story.tsx @@ -7,6 +7,7 @@ import * as GQL from '../../../../shared/src/graphql/schema' import * as H from 'history' import React from 'react' import webStyles from '../../SourcegraphWebApp.scss' +import { SourcegraphContext } from '../../jscontext' window.context = {} as SourcegraphContext & SuiteFunction diff --git a/web/src/enterprise/codeintel/CodeIntelUploadPage.story.tsx b/web/src/enterprise/codeintel/CodeIntelUploadPage.story.tsx index e8f025a49fb754..b79c426cd2cabe 100644 --- a/web/src/enterprise/codeintel/CodeIntelUploadPage.story.tsx +++ b/web/src/enterprise/codeintel/CodeIntelUploadPage.story.tsx @@ -7,6 +7,7 @@ import * as GQL from '../../../../shared/src/graphql/schema' import * as H from 'history' import React from 'react' import webStyles from '../../SourcegraphWebApp.scss' +import { SourcegraphContext } from '../../jscontext' window.context = {} as SourcegraphContext & SuiteFunction diff --git a/web/src/enterprise/codeintel/CodeIntelUploadsPage.story.tsx b/web/src/enterprise/codeintel/CodeIntelUploadsPage.story.tsx index 9594b35f2dc87c..bae24321607182 100644 --- a/web/src/enterprise/codeintel/CodeIntelUploadsPage.story.tsx +++ b/web/src/enterprise/codeintel/CodeIntelUploadsPage.story.tsx @@ -7,6 +7,7 @@ import * as GQL from '../../../../shared/src/graphql/schema' import * as H from 'history' import React from 'react' import webStyles from '../../SourcegraphWebApp.scss' +import { SourcegraphContext } from '../../jscontext' window.context = {} as SourcegraphContext & SuiteFunction diff --git a/web/src/globals.d.ts b/web/src/globals.d.ts index 05e0bd60fe0e5a..e61c12c944da9a 100644 --- a/web/src/globals.d.ts +++ b/web/src/globals.d.ts @@ -7,142 +7,12 @@ interface PageError { interface Window { pageError?: PageError - context: SourcegraphContext + context: import('./jscontext').SourcegraphContext MonacoEnvironment: { getWorkerUrl(moduleId: string, label: string): string } } -/** - * Represents user properties that are guaranteed to both (1) be set if the user is signed in, - * and (2) not change over a user session - */ -interface ImmutableUser { - readonly UID: number -} - -type DeployType = 'kubernetes' | 'docker-container' | 'docker-compose' | 'pure-docker' | 'dev' - -/** - * Defined in cmd/frontend/internal/app/jscontext/jscontext.go JSContext struct - */ -interface SourcegraphContext - extends Pick, 'experimentalFeatures'> { - xhrHeaders: { [key: string]: string } - csrfToken: string - userAgentIsBot: boolean - - /** - * Whether the user is authenticated. Use authenticatedUser in ./auth.ts to obtain information about the user. - */ - readonly isAuthenticatedUser: boolean - - readonly sentryDSN: string | null - - /** Externally accessible URL for Sourcegraph (e.g., https://sourcegraph.com or http://localhost:3080). */ - externalURL: string - - /** URL path to image/font/etc. assets on server */ - assetsRoot: string - - version: string - - /** - * Debug is whether debug mode is enabled. - */ - debug: boolean - - sourcegraphDotComMode: boolean - - /** - * siteID is the identifier of the Sourcegraph site. - */ - siteID: string - - /** The GraphQL ID of the Sourcegraph site. */ - siteGQLID: GQL.ID - - /** - * Whether the site needs to be initialized. - */ - needsSiteInit: boolean - - /** - * Emails support enabled - */ - emailEnabled: boolean - - /** - * A subset of the site configuration. Not all fields are set. - */ - site: Pick< - import('./schema/site.schema').SiteConfiguration, - | 'auth.public' - | 'update.channel' - | 'campaigns.readAccess.enabled' - | 'disableNonCriticalTelemetry' - | 'permissions.backgroundSync' - > - - /** Whether access tokens are enabled. */ - accessTokensAllow: 'all-users-create' | 'site-admin-create' | 'none' - - /** Whether the reset-password flow is enabled. */ - resetPasswordEnabled: boolean - - /** - * Likely running within a Docker container under a Mac host OS. - */ - likelyDockerOnMac: boolean - - /** - * Whether or not the server needs to restart in order to apply a pending - * configuration change. - */ - needServerRestart: boolean - - /** - * The kind of deployment. - */ - deployType: DeployType - - /** Whether signup is allowed on the site. */ - allowSignup: boolean - - /** Authentication provider instances in site config. */ - authProviders?: { - displayName: string - isBuiltin: boolean - authenticationURL?: string - }[] - - /** Custom branding for the homepage and search icon. */ - branding?: { - /** The URL of the favicon to be used for your instance */ - favicon?: string - - /** Override style for light themes */ - light?: BrandAssets - /** Override style for dark themes */ - dark?: BrandAssets - - /** Prevents the icon in the top-left corner of the screen from spinning. */ - disableSymbolSpin?: boolean - - brandName: string - } - - /** The publishable key for the billing service (Stripe). */ - billingPublishableKey?: string -} - -interface BrandAssets { - /** The URL to the logo used on the homepage */ - logo?: string - /** The URL to the symbol used as the search icon */ - symbol?: string -} - declare module '*.scss' { const cssModule: string export default cssModule diff --git a/web/src/integration/__fixtures__/search/case_sensitivity_toggle/clicking_toggle_turns_off_case_sensitivity_and_removes_case_url_parameter_2951888955/recording.har b/web/src/integration/__fixtures__/search/case_sensitivity_toggle/clicking_toggle_turns_off_case_sensitivity_and_removes_case_url_parameter_2951888955/recording.har deleted file mode 100644 index a17b73f1153393..00000000000000 --- a/web/src/integration/__fixtures__/search/case_sensitivity_toggle/clicking_toggle_turns_off_case_sensitivity_and_removes_case_url_parameter_2951888955/recording.har +++ /dev/null @@ -1,134 +0,0 @@ -{ - "log": { - "_recordingName": "clicking_toggle_turns_off_case_sensitivity_and_removes_case_url_parameter", - "creator": { - "comment": "persister:fs", - "name": "Polly.JS", - "version": "4.3.0" - }, - "entries": [ - { - "_id": "6547c6b6df0da9da10ea1cca6ed2daef", - "_order": 0, - "cache": {}, - "request": { - "bodySize": 0, - "cookies": [], - "headers": [ - { - "name": "upgrade-insecure-requests", - "value": "1" - }, - { - "name": "user-agent", - "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.0 Safari/537.36" - }, - { - "name": "sec-fetch-user", - "value": "?1" - } - ], - "headersSize": 272, - "httpVersion": "HTTP/1.1", - "method": "GET", - "queryString": [ - { - "name": "q", - "value": "test" - }, - { - "name": "patternType", - "value": "literal" - }, - { - "name": "case", - "value": "yes" - } - ], - "url": "https://sourcegraph.test:3443/search?q=test&patternType=literal&case=yes" - }, - "response": { - "bodySize": 1600, - "content": { - "mimeType": "text/html; charset=utf-8", - "size": 1600, - "text": "\n\n\n\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\t\n\t\n\ttest - Sourcegraph\n\t\n\t\n\t\n\t\n\t\n\t\n\n\n\n\t\n\t\n\t
\n\t\n\t\n\t\n\n\n\n" - }, - "cookies": [], - "headers": [ - { - "name": "date", - "value": "Wed, 08 Jul 2020 14:10:07 GMT" - }, - { - "name": "content-type", - "value": "text/html; charset=utf-8" - }, - { - "name": "content-length", - "value": "1600" - }, - { - "name": "connection", - "value": "keep-alive" - }, - { - "name": "x-powered-by", - "value": "Express" - }, - { - "name": "access-control-allow-credentials", - "value": "true" - }, - { - "name": "cache-control", - "value": "no-cache, max-age=0" - }, - { - "name": "content-encoding", - "value": "gzip" - }, - { - "name": "vary", - "value": "Authorization, Cookie, Cookie, Accept-Encoding" - }, - { - "name": "x-content-type-options", - "value": "nosniff" - }, - { - "name": "x-frame-options", - "value": "DENY" - }, - { - "name": "x-trace", - "value": "#tracer-not-enabled" - }, - { - "name": "x-xss-protection", - "value": "1; mode=block" - } - ], - "headersSize": 436, - "httpVersion": "HTTP/1.1", - "redirectURL": "", - "status": 200, - "statusText": "OK" - }, - "startedDateTime": "2020-07-08T14:10:07.532Z", - "time": 35, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 35 - } - } - ], - "pages": [], - "version": "1.2" - } -} diff --git a/web/src/integration/__fixtures__/search/case_sensitivity_toggle/clicking_toggle_turns_on_case_sensitivity_1945884784/recording.har b/web/src/integration/__fixtures__/search/case_sensitivity_toggle/clicking_toggle_turns_on_case_sensitivity_1945884784/recording.har deleted file mode 100644 index c338d89db88d09..00000000000000 --- a/web/src/integration/__fixtures__/search/case_sensitivity_toggle/clicking_toggle_turns_on_case_sensitivity_1945884784/recording.har +++ /dev/null @@ -1,121 +0,0 @@ -{ - "log": { - "_recordingName": "clicking_toggle_turns_on_case_sensitivity", - "creator": { - "comment": "persister:fs", - "name": "Polly.JS", - "version": "4.3.0" - }, - "entries": [ - { - "_id": "8279c1670782628c87672b2ec1cde615", - "_order": 0, - "cache": {}, - "request": { - "bodySize": 0, - "cookies": [], - "headers": [ - { - "name": "upgrade-insecure-requests", - "value": "1" - }, - { - "name": "user-agent", - "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.0 Safari/537.36" - }, - { - "name": "sec-fetch-user", - "value": "?1" - } - ], - "headersSize": 236, - "httpVersion": "HTTP/1.1", - "method": "GET", - "queryString": [], - "url": "https://sourcegraph.test:3443/search" - }, - "response": { - "bodySize": 1593, - "content": { - "mimeType": "text/html; charset=utf-8", - "size": 1593, - "text": "\n\n\n\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\t\n\t\n\tSourcegraph\n\t\n\t\n\t\n\t\n\t\n\t\n\n\n\n\t\n\t\n\t
\n\t\n\t\n\t\n\n\n\n" - }, - "cookies": [], - "headers": [ - { - "name": "date", - "value": "Wed, 08 Jul 2020 14:10:05 GMT" - }, - { - "name": "content-type", - "value": "text/html; charset=utf-8" - }, - { - "name": "content-length", - "value": "1593" - }, - { - "name": "connection", - "value": "keep-alive" - }, - { - "name": "x-powered-by", - "value": "Express" - }, - { - "name": "access-control-allow-credentials", - "value": "true" - }, - { - "name": "cache-control", - "value": "no-cache, max-age=0" - }, - { - "name": "content-encoding", - "value": "gzip" - }, - { - "name": "vary", - "value": "Authorization, Cookie, Cookie, Accept-Encoding" - }, - { - "name": "x-content-type-options", - "value": "nosniff" - }, - { - "name": "x-frame-options", - "value": "DENY" - }, - { - "name": "x-trace", - "value": "#tracer-not-enabled" - }, - { - "name": "x-xss-protection", - "value": "1; mode=block" - } - ], - "headersSize": 436, - "httpVersion": "HTTP/1.1", - "redirectURL": "", - "status": 200, - "statusText": "OK" - }, - "startedDateTime": "2020-07-08T14:10:05.286Z", - "time": 43, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 43 - } - } - ], - "pages": [], - "version": "1.2" - } -} diff --git a/web/src/integration/__fixtures__/search/interactive_search_mode/filter_buttons_1341189549/recording.har b/web/src/integration/__fixtures__/search/interactive_search_mode/filter_buttons_1341189549/recording.har deleted file mode 100644 index 142e158d960fbb..00000000000000 --- a/web/src/integration/__fixtures__/search/interactive_search_mode/filter_buttons_1341189549/recording.har +++ /dev/null @@ -1,344 +0,0 @@ -{ - "log": { - "_recordingName": "filter_buttons", - "creator": { - "comment": "persister:fs", - "name": "Polly.JS", - "version": "4.3.0" - }, - "entries": [ - { - "_id": "8279c1670782628c87672b2ec1cde615", - "_order": 0, - "cache": {}, - "request": { - "bodySize": 0, - "cookies": [], - "headers": [ - { - "name": "upgrade-insecure-requests", - "value": "1" - }, - { - "name": "user-agent", - "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.0 Safari/537.36" - }, - { - "name": "sec-fetch-user", - "value": "?1" - } - ], - "headersSize": 236, - "httpVersion": "HTTP/1.1", - "method": "GET", - "queryString": [], - "url": "https://sourcegraph.test:3443/search" - }, - "response": { - "bodySize": 1593, - "content": { - "mimeType": "text/html; charset=utf-8", - "size": 1593, - "text": "\n\n\n\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\t\n\t\n\tSourcegraph\n\t\n\t\n\t\n\t\n\t\n\t\n\n\n\n\t\n\t\n\t
\n\t\n\t\n\t\n\n\n\n" - }, - "cookies": [], - "headers": [ - { - "name": "date", - "value": "Wed, 08 Jul 2020 14:09:53 GMT" - }, - { - "name": "content-type", - "value": "text/html; charset=utf-8" - }, - { - "name": "content-length", - "value": "1593" - }, - { - "name": "connection", - "value": "keep-alive" - }, - { - "name": "x-powered-by", - "value": "Express" - }, - { - "name": "access-control-allow-credentials", - "value": "true" - }, - { - "name": "cache-control", - "value": "no-cache, max-age=0" - }, - { - "name": "content-encoding", - "value": "gzip" - }, - { - "name": "vary", - "value": "Authorization, Cookie, Cookie, Accept-Encoding" - }, - { - "name": "x-content-type-options", - "value": "nosniff" - }, - { - "name": "x-frame-options", - "value": "DENY" - }, - { - "name": "x-trace", - "value": "#tracer-not-enabled" - }, - { - "name": "x-xss-protection", - "value": "1; mode=block" - } - ], - "headersSize": 436, - "httpVersion": "HTTP/1.1", - "redirectURL": "", - "status": 200, - "statusText": "OK" - }, - "startedDateTime": "2020-07-08T14:09:53.087Z", - "time": 48, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 48 - } - }, - { - "_id": "1766c1dccf8325c912c72a2ca9f1607c", - "_order": 0, - "cache": {}, - "request": { - "bodySize": 0, - "cookies": [], - "headers": [ - { - "name": "upgrade-insecure-requests", - "value": "1" - }, - { - "name": "user-agent", - "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.0 Safari/537.36" - }, - { - "name": "sec-fetch-user", - "value": "?1" - } - ], - "headersSize": 279, - "httpVersion": "HTTP/1.1", - "method": "GET", - "queryString": [ - { - "name": "q", - "value": "repo:gorilla/mux" - }, - { - "name": "patternType", - "value": "literal" - } - ], - "url": "https://sourcegraph.test:3443/search?q=repo%3Agorilla%2Fmux&patternType=literal" - }, - "response": { - "bodySize": 1601, - "content": { - "mimeType": "text/html; charset=utf-8", - "size": 1601, - "text": "\n\n\n\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\t\n\t\n\trepo:gorilla/mux - Sourcegraph\n\t\n\t\n\t\n\t\n\t\n\t\n\n\n\n\t\n\t\n\t
\n\t\n\t\n\t\n\n\n\n" - }, - "cookies": [], - "headers": [ - { - "name": "date", - "value": "Wed, 08 Jul 2020 14:09:56 GMT" - }, - { - "name": "content-type", - "value": "text/html; charset=utf-8" - }, - { - "name": "content-length", - "value": "1601" - }, - { - "name": "connection", - "value": "keep-alive" - }, - { - "name": "x-powered-by", - "value": "Express" - }, - { - "name": "access-control-allow-credentials", - "value": "true" - }, - { - "name": "cache-control", - "value": "no-cache, max-age=0" - }, - { - "name": "content-encoding", - "value": "gzip" - }, - { - "name": "vary", - "value": "Authorization, Cookie, Cookie, Accept-Encoding" - }, - { - "name": "x-content-type-options", - "value": "nosniff" - }, - { - "name": "x-frame-options", - "value": "DENY" - }, - { - "name": "x-trace", - "value": "#tracer-not-enabled" - }, - { - "name": "x-xss-protection", - "value": "1; mode=block" - } - ], - "headersSize": 436, - "httpVersion": "HTTP/1.1", - "redirectURL": "", - "status": 200, - "statusText": "OK" - }, - "startedDateTime": "2020-07-08T14:09:56.216Z", - "time": 43, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 43 - } - }, - { - "_id": "8279c1670782628c87672b2ec1cde615", - "_order": 1, - "cache": {}, - "request": { - "bodySize": 0, - "cookies": [], - "headers": [ - { - "name": "upgrade-insecure-requests", - "value": "1" - }, - { - "name": "user-agent", - "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.0 Safari/537.36" - }, - { - "name": "sec-fetch-user", - "value": "?1" - } - ], - "headersSize": 236, - "httpVersion": "HTTP/1.1", - "method": "GET", - "queryString": [], - "url": "https://sourcegraph.test:3443/search" - }, - "response": { - "bodySize": 1591, - "content": { - "mimeType": "text/html; charset=utf-8", - "size": 1591, - "text": "\n\n\n\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\t\n\t\n\tSourcegraph\n\t\n\t\n\t\n\t\n\t\n\t\n\n\n\n\t\n\t\n\t
\n\t\n\t\n\t\n\n\n\n" - }, - "cookies": [], - "headers": [ - { - "name": "date", - "value": "Wed, 08 Jul 2020 14:09:57 GMT" - }, - { - "name": "content-type", - "value": "text/html; charset=utf-8" - }, - { - "name": "content-length", - "value": "1591" - }, - { - "name": "connection", - "value": "keep-alive" - }, - { - "name": "x-powered-by", - "value": "Express" - }, - { - "name": "access-control-allow-credentials", - "value": "true" - }, - { - "name": "cache-control", - "value": "no-cache, max-age=0" - }, - { - "name": "content-encoding", - "value": "gzip" - }, - { - "name": "vary", - "value": "Authorization, Cookie, Cookie, Accept-Encoding" - }, - { - "name": "x-content-type-options", - "value": "nosniff" - }, - { - "name": "x-frame-options", - "value": "DENY" - }, - { - "name": "x-trace", - "value": "#tracer-not-enabled" - }, - { - "name": "x-xss-protection", - "value": "1; mode=block" - } - ], - "headersSize": 436, - "httpVersion": "HTTP/1.1", - "redirectURL": "", - "status": 200, - "statusText": "OK" - }, - "startedDateTime": "2020-07-08T14:09:57.620Z", - "time": 48, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 48 - } - } - ], - "pages": [], - "version": "1.2" - } -} diff --git a/web/src/integration/__fixtures__/search/interactive_search_mode/filter_dropdown_and_finite_option_filter_inputs_3032515524/recording.har b/web/src/integration/__fixtures__/search/interactive_search_mode/filter_dropdown_and_finite_option_filter_inputs_3032515524/recording.har deleted file mode 100644 index 097255a2d15e4a..00000000000000 --- a/web/src/integration/__fixtures__/search/interactive_search_mode/filter_dropdown_and_finite_option_filter_inputs_3032515524/recording.har +++ /dev/null @@ -1,121 +0,0 @@ -{ - "log": { - "_recordingName": "filter_dropdown_and_finite_option_filter_inputs", - "creator": { - "comment": "persister:fs", - "name": "Polly.JS", - "version": "4.3.0" - }, - "entries": [ - { - "_id": "8279c1670782628c87672b2ec1cde615", - "_order": 0, - "cache": {}, - "request": { - "bodySize": 0, - "cookies": [], - "headers": [ - { - "name": "upgrade-insecure-requests", - "value": "1" - }, - { - "name": "user-agent", - "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.0 Safari/537.36" - }, - { - "name": "sec-fetch-user", - "value": "?1" - } - ], - "headersSize": 236, - "httpVersion": "HTTP/1.1", - "method": "GET", - "queryString": [], - "url": "https://sourcegraph.test:3443/search" - }, - "response": { - "bodySize": 1593, - "content": { - "mimeType": "text/html; charset=utf-8", - "size": 1593, - "text": "\n\n\n\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\t\n\t\n\tSourcegraph\n\t\n\t\n\t\n\t\n\t\n\t\n\n\n\n\t\n\t\n\t
\n\t\n\t\n\t\n\n\n\n" - }, - "cookies": [], - "headers": [ - { - "name": "date", - "value": "Wed, 08 Jul 2020 14:10:01 GMT" - }, - { - "name": "content-type", - "value": "text/html; charset=utf-8" - }, - { - "name": "content-length", - "value": "1593" - }, - { - "name": "connection", - "value": "keep-alive" - }, - { - "name": "x-powered-by", - "value": "Express" - }, - { - "name": "access-control-allow-credentials", - "value": "true" - }, - { - "name": "cache-control", - "value": "no-cache, max-age=0" - }, - { - "name": "content-encoding", - "value": "gzip" - }, - { - "name": "vary", - "value": "Authorization, Cookie, Cookie, Accept-Encoding" - }, - { - "name": "x-content-type-options", - "value": "nosniff" - }, - { - "name": "x-frame-options", - "value": "DENY" - }, - { - "name": "x-trace", - "value": "#tracer-not-enabled" - }, - { - "name": "x-xss-protection", - "value": "1; mode=block" - } - ], - "headersSize": 436, - "httpVersion": "HTTP/1.1", - "redirectURL": "", - "status": 200, - "statusText": "OK" - }, - "startedDateTime": "2020-07-08T14:10:01.842Z", - "time": 27, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 27 - } - } - ], - "pages": [], - "version": "1.2" - } -} diff --git a/web/src/integration/__fixtures__/search/interactive_search_mode/search_mode_component_appears_3096847116/recording.har b/web/src/integration/__fixtures__/search/interactive_search_mode/search_mode_component_appears_3096847116/recording.har deleted file mode 100644 index 9c743afbd40fad..00000000000000 --- a/web/src/integration/__fixtures__/search/interactive_search_mode/search_mode_component_appears_3096847116/recording.har +++ /dev/null @@ -1,121 +0,0 @@ -{ - "log": { - "_recordingName": "search_mode_component_appears", - "creator": { - "comment": "persister:fs", - "name": "Polly.JS", - "version": "4.3.0" - }, - "entries": [ - { - "_id": "8279c1670782628c87672b2ec1cde615", - "_order": 0, - "cache": {}, - "request": { - "bodySize": 0, - "cookies": [], - "headers": [ - { - "name": "upgrade-insecure-requests", - "value": "1" - }, - { - "name": "user-agent", - "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.0 Safari/537.36" - }, - { - "name": "sec-fetch-user", - "value": "?1" - } - ], - "headersSize": 236, - "httpVersion": "HTTP/1.1", - "method": "GET", - "queryString": [], - "url": "https://sourcegraph.test:3443/search" - }, - "response": { - "bodySize": 1591, - "content": { - "mimeType": "text/html; charset=utf-8", - "size": 1591, - "text": "\n\n\n\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\t\n\t\n\tSourcegraph\n\t\n\t\n\t\n\t\n\t\n\t\n\n\n\n\t\n\t\n\t
\n\t\n\t\n\t\n\n\n\n" - }, - "cookies": [], - "headers": [ - { - "name": "date", - "value": "Wed, 08 Jul 2020 14:09:50 GMT" - }, - { - "name": "content-type", - "value": "text/html; charset=utf-8" - }, - { - "name": "content-length", - "value": "1591" - }, - { - "name": "connection", - "value": "keep-alive" - }, - { - "name": "x-powered-by", - "value": "Express" - }, - { - "name": "access-control-allow-credentials", - "value": "true" - }, - { - "name": "cache-control", - "value": "no-cache, max-age=0" - }, - { - "name": "content-encoding", - "value": "gzip" - }, - { - "name": "vary", - "value": "Authorization, Cookie, Cookie, Accept-Encoding" - }, - { - "name": "x-content-type-options", - "value": "nosniff" - }, - { - "name": "x-frame-options", - "value": "DENY" - }, - { - "name": "x-trace", - "value": "#tracer-not-enabled" - }, - { - "name": "x-xss-protection", - "value": "1; mode=block" - } - ], - "headersSize": 436, - "httpVersion": "HTTP/1.1", - "redirectURL": "", - "status": 200, - "statusText": "OK" - }, - "startedDateTime": "2020-07-08T14:09:50.894Z", - "time": 58, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 58 - } - } - ], - "pages": [], - "version": "1.2" - } -} diff --git a/web/src/integration/__fixtures__/search/interactive_search_mode/updates_query_when_searching_from_directory_page_2511634085/recording.har b/web/src/integration/__fixtures__/search/interactive_search_mode/updates_query_when_searching_from_directory_page_2511634085/recording.har deleted file mode 100644 index 08089cbd940b7b..00000000000000 --- a/web/src/integration/__fixtures__/search/interactive_search_mode/updates_query_when_searching_from_directory_page_2511634085/recording.har +++ /dev/null @@ -1,121 +0,0 @@ -{ - "log": { - "_recordingName": "updates_query_when_searching_from_directory_page", - "creator": { - "comment": "persister:fs", - "name": "Polly.JS", - "version": "4.3.0" - }, - "entries": [ - { - "_id": "5522a7c9a925b6191d7447ce07215f2f", - "_order": 0, - "cache": {}, - "request": { - "bodySize": 0, - "cookies": [], - "headers": [ - { - "name": "upgrade-insecure-requests", - "value": "1" - }, - { - "name": "user-agent", - "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.0 Safari/537.36" - }, - { - "name": "sec-fetch-user", - "value": "?1" - } - ], - "headersSize": 261, - "httpVersion": "HTTP/1.1", - "method": "GET", - "queryString": [], - "url": "https://sourcegraph.test:3443/github.com/sourcegraph/jsonrpc2" - }, - "response": { - "bodySize": 1602, - "content": { - "mimeType": "text/html; charset=utf-8", - "size": 1602, - "text": "\n\n\n\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\t\n\t\n\tsourcegraph/jsonrpc2 - Sourcegraph\n\t\n\t\n\t\n\t\n\t\n\t\n\n\n\n\t\n\t\n\t
\n\t\n\t\n\t\n\n\n\n" - }, - "cookies": [], - "headers": [ - { - "name": "date", - "value": "Wed, 08 Jul 2020 14:09:59 GMT" - }, - { - "name": "content-type", - "value": "text/html; charset=utf-8" - }, - { - "name": "content-length", - "value": "1602" - }, - { - "name": "connection", - "value": "keep-alive" - }, - { - "name": "x-powered-by", - "value": "Express" - }, - { - "name": "access-control-allow-credentials", - "value": "true" - }, - { - "name": "cache-control", - "value": "no-cache, max-age=0" - }, - { - "name": "content-encoding", - "value": "gzip" - }, - { - "name": "vary", - "value": "Authorization, Cookie, Cookie, Accept-Encoding" - }, - { - "name": "x-content-type-options", - "value": "nosniff" - }, - { - "name": "x-frame-options", - "value": "DENY" - }, - { - "name": "x-trace", - "value": "#tracer-not-enabled" - }, - { - "name": "x-xss-protection", - "value": "1; mode=block" - } - ], - "headersSize": 436, - "httpVersion": "HTTP/1.1", - "redirectURL": "", - "status": 200, - "statusText": "OK" - }, - "startedDateTime": "2020-07-08T14:09:59.742Z", - "time": 44, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 44 - } - } - ], - "pages": [], - "version": "1.2" - } -} diff --git a/web/src/integration/__fixtures__/search/structural_search_toggle/clicking_toggle_turns_off_structural_saerch_and_reverts_to_default_pattern_type_1607440570/recording.har b/web/src/integration/__fixtures__/search/structural_search_toggle/clicking_toggle_turns_off_structural_saerch_and_reverts_to_default_pattern_type_1607440570/recording.har deleted file mode 100644 index 92aade2d5d8edd..00000000000000 --- a/web/src/integration/__fixtures__/search/structural_search_toggle/clicking_toggle_turns_off_structural_saerch_and_reverts_to_default_pattern_type_1607440570/recording.har +++ /dev/null @@ -1,130 +0,0 @@ -{ - "log": { - "_recordingName": "clicking_toggle_turns_off_structural_saerch_and_reverts_to_default_pattern_type", - "creator": { - "comment": "persister:fs", - "name": "Polly.JS", - "version": "4.3.0" - }, - "entries": [ - { - "_id": "5e8fee5014edc18bbdcc07d7ce62a0b8", - "_order": 0, - "cache": {}, - "request": { - "bodySize": 0, - "cookies": [], - "headers": [ - { - "name": "upgrade-insecure-requests", - "value": "1" - }, - { - "name": "user-agent", - "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.0 Safari/537.36" - }, - { - "name": "sec-fetch-user", - "value": "?1" - } - ], - "headersSize": 266, - "httpVersion": "HTTP/1.1", - "method": "GET", - "queryString": [ - { - "name": "q", - "value": "test" - }, - { - "name": "patternType", - "value": "structural" - } - ], - "url": "https://sourcegraph.test:3443/search?q=test&patternType=structural" - }, - "response": { - "bodySize": 1594, - "content": { - "mimeType": "text/html; charset=utf-8", - "size": 1594, - "text": "\n\n\n\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\t\n\t\n\ttest - Sourcegraph\n\t\n\t\n\t\n\t\n\t\n\t\n\n\n\n\t\n\t\n\t
\n\t\n\t\n\t\n\n\n\n" - }, - "cookies": [], - "headers": [ - { - "name": "date", - "value": "Wed, 08 Jul 2020 14:10:13 GMT" - }, - { - "name": "content-type", - "value": "text/html; charset=utf-8" - }, - { - "name": "content-length", - "value": "1594" - }, - { - "name": "connection", - "value": "keep-alive" - }, - { - "name": "x-powered-by", - "value": "Express" - }, - { - "name": "access-control-allow-credentials", - "value": "true" - }, - { - "name": "cache-control", - "value": "no-cache, max-age=0" - }, - { - "name": "content-encoding", - "value": "gzip" - }, - { - "name": "vary", - "value": "Authorization, Cookie, Cookie, Accept-Encoding" - }, - { - "name": "x-content-type-options", - "value": "nosniff" - }, - { - "name": "x-frame-options", - "value": "DENY" - }, - { - "name": "x-trace", - "value": "#tracer-not-enabled" - }, - { - "name": "x-xss-protection", - "value": "1; mode=block" - } - ], - "headersSize": 436, - "httpVersion": "HTTP/1.1", - "redirectURL": "", - "status": 200, - "statusText": "OK" - }, - "startedDateTime": "2020-07-08T14:10:13.937Z", - "time": 38, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 38 - } - } - ], - "pages": [], - "version": "1.2" - } -} diff --git a/web/src/integration/__fixtures__/search/structural_search_toggle/clicking_toggle_turns_on_structural_search_3387440268/recording.har b/web/src/integration/__fixtures__/search/structural_search_toggle/clicking_toggle_turns_on_structural_search_3387440268/recording.har deleted file mode 100644 index 24739dc39d26f0..00000000000000 --- a/web/src/integration/__fixtures__/search/structural_search_toggle/clicking_toggle_turns_on_structural_search_3387440268/recording.har +++ /dev/null @@ -1,121 +0,0 @@ -{ - "log": { - "_recordingName": "clicking_toggle_turns_on_structural_search", - "creator": { - "comment": "persister:fs", - "name": "Polly.JS", - "version": "4.3.0" - }, - "entries": [ - { - "_id": "8279c1670782628c87672b2ec1cde615", - "_order": 0, - "cache": {}, - "request": { - "bodySize": 0, - "cookies": [], - "headers": [ - { - "name": "upgrade-insecure-requests", - "value": "1" - }, - { - "name": "user-agent", - "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.0 Safari/537.36" - }, - { - "name": "sec-fetch-user", - "value": "?1" - } - ], - "headersSize": 236, - "httpVersion": "HTTP/1.1", - "method": "GET", - "queryString": [], - "url": "https://sourcegraph.test:3443/search" - }, - "response": { - "bodySize": 1594, - "content": { - "mimeType": "text/html; charset=utf-8", - "size": 1594, - "text": "\n\n\n\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\t\n\t\n\tSourcegraph\n\t\n\t\n\t\n\t\n\t\n\t\n\n\n\n\t\n\t\n\t
\n\t\n\t\n\t\n\n\n\n" - }, - "cookies": [], - "headers": [ - { - "name": "date", - "value": "Wed, 08 Jul 2020 14:10:09 GMT" - }, - { - "name": "content-type", - "value": "text/html; charset=utf-8" - }, - { - "name": "content-length", - "value": "1594" - }, - { - "name": "connection", - "value": "keep-alive" - }, - { - "name": "x-powered-by", - "value": "Express" - }, - { - "name": "access-control-allow-credentials", - "value": "true" - }, - { - "name": "cache-control", - "value": "no-cache, max-age=0" - }, - { - "name": "content-encoding", - "value": "gzip" - }, - { - "name": "vary", - "value": "Authorization, Cookie, Cookie, Accept-Encoding" - }, - { - "name": "x-content-type-options", - "value": "nosniff" - }, - { - "name": "x-frame-options", - "value": "DENY" - }, - { - "name": "x-trace", - "value": "#tracer-not-enabled" - }, - { - "name": "x-xss-protection", - "value": "1; mode=block" - } - ], - "headersSize": 436, - "httpVersion": "HTTP/1.1", - "redirectURL": "", - "status": 200, - "statusText": "OK" - }, - "startedDateTime": "2020-07-08T14:10:09.665Z", - "time": 38, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 38 - } - } - ], - "pages": [], - "version": "1.2" - } -} diff --git a/web/src/integration/__fixtures__/search/structural_search_toggle/clicking_toggle_turns_on_structural_search_and_removes_existing_pattern_type_parameter_162733290/recording.har b/web/src/integration/__fixtures__/search/structural_search_toggle/clicking_toggle_turns_on_structural_search_and_removes_existing_pattern_type_parameter_162733290/recording.har deleted file mode 100644 index 7e362a21b18e54..00000000000000 --- a/web/src/integration/__fixtures__/search/structural_search_toggle/clicking_toggle_turns_on_structural_search_and_removes_existing_pattern_type_parameter_162733290/recording.har +++ /dev/null @@ -1,130 +0,0 @@ -{ - "log": { - "_recordingName": "clicking_toggle_turns_on_structural_search_and_removes_existing_pattern_type_parameter", - "creator": { - "comment": "persister:fs", - "name": "Polly.JS", - "version": "4.3.0" - }, - "entries": [ - { - "_id": "c9effc828e9a71b7e2cd4a0ebdd07188", - "_order": 0, - "cache": {}, - "request": { - "bodySize": 0, - "cookies": [], - "headers": [ - { - "name": "upgrade-insecure-requests", - "value": "1" - }, - { - "name": "user-agent", - "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.0 Safari/537.36" - }, - { - "name": "sec-fetch-user", - "value": "?1" - } - ], - "headersSize": 262, - "httpVersion": "HTTP/1.1", - "method": "GET", - "queryString": [ - { - "name": "q", - "value": "test" - }, - { - "name": "patternType", - "value": "regexp" - } - ], - "url": "https://sourcegraph.test:3443/search?q=test&patternType=regexp" - }, - "response": { - "bodySize": 1595, - "content": { - "mimeType": "text/html; charset=utf-8", - "size": 1595, - "text": "\n\n\n\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\t\n\t\n\ttest - Sourcegraph\n\t\n\t\n\t\n\t\n\t\n\t\n\n\n\n\t\n\t\n\t
\n\t\n\t\n\t\n\n\n\n" - }, - "cookies": [], - "headers": [ - { - "name": "date", - "value": "Wed, 08 Jul 2020 14:10:11 GMT" - }, - { - "name": "content-type", - "value": "text/html; charset=utf-8" - }, - { - "name": "content-length", - "value": "1595" - }, - { - "name": "connection", - "value": "keep-alive" - }, - { - "name": "x-powered-by", - "value": "Express" - }, - { - "name": "access-control-allow-credentials", - "value": "true" - }, - { - "name": "cache-control", - "value": "no-cache, max-age=0" - }, - { - "name": "content-encoding", - "value": "gzip" - }, - { - "name": "vary", - "value": "Authorization, Cookie, Cookie, Accept-Encoding" - }, - { - "name": "x-content-type-options", - "value": "nosniff" - }, - { - "name": "x-frame-options", - "value": "DENY" - }, - { - "name": "x-trace", - "value": "#tracer-not-enabled" - }, - { - "name": "x-xss-protection", - "value": "1; mode=block" - } - ], - "headersSize": 436, - "httpVersion": "HTTP/1.1", - "redirectURL": "", - "status": 200, - "statusText": "OK" - }, - "startedDateTime": "2020-07-08T14:10:11.884Z", - "time": 35, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 35 - } - } - ], - "pages": [], - "version": "1.2" - } -} diff --git a/web/src/integration/__fixtures__/settings/user_settings_page/updates_user_settings_3395606591/recording.har b/web/src/integration/__fixtures__/settings/user_settings_page/updates_user_settings_3395606591/recording.har deleted file mode 100644 index 5b5c09735fbd7c..00000000000000 --- a/web/src/integration/__fixtures__/settings/user_settings_page/updates_user_settings_3395606591/recording.har +++ /dev/null @@ -1,121 +0,0 @@ -{ - "log": { - "_recordingName": "updates_user_settings", - "creator": { - "comment": "persister:fs", - "name": "Polly.JS", - "version": "4.3.0" - }, - "entries": [ - { - "_id": "33db2839908eb7e0c61d928786bac673", - "_order": 0, - "cache": {}, - "request": { - "bodySize": 0, - "cookies": [], - "headers": [ - { - "name": "upgrade-insecure-requests", - "value": "1" - }, - { - "name": "user-agent", - "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.0 Safari/537.36" - }, - { - "name": "sec-fetch-user", - "value": "?1" - } - ], - "headersSize": 249, - "httpVersion": "HTTP/1.1", - "method": "GET", - "queryString": [], - "url": "https://sourcegraph.test:3443/users/test/settings" - }, - "response": { - "bodySize": 1603, - "content": { - "mimeType": "text/html; charset=utf-8", - "size": 1603, - "text": "\n\n\n\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\t\n\t\n\tUser settings - Sourcegraph\n\t\n\t\n\t\n\t\n\t\n\t\n\n\n\n\t\n\t\n\t
\n\t\n\t\n\t\n\n\n\n" - }, - "cookies": [], - "headers": [ - { - "name": "date", - "value": "Wed, 08 Jul 2020 14:10:30 GMT" - }, - { - "name": "content-type", - "value": "text/html; charset=utf-8" - }, - { - "name": "content-length", - "value": "1603" - }, - { - "name": "connection", - "value": "keep-alive" - }, - { - "name": "x-powered-by", - "value": "Express" - }, - { - "name": "access-control-allow-credentials", - "value": "true" - }, - { - "name": "cache-control", - "value": "no-cache, max-age=0" - }, - { - "name": "content-encoding", - "value": "gzip" - }, - { - "name": "vary", - "value": "Authorization, Cookie, Cookie, Accept-Encoding" - }, - { - "name": "x-content-type-options", - "value": "nosniff" - }, - { - "name": "x-frame-options", - "value": "DENY" - }, - { - "name": "x-trace", - "value": "#tracer-not-enabled" - }, - { - "name": "x-xss-protection", - "value": "1; mode=block" - } - ], - "headersSize": 436, - "httpVersion": "HTTP/1.1", - "redirectURL": "", - "status": 200, - "statusText": "OK" - }, - "startedDateTime": "2020-07-08T14:10:30.441Z", - "time": 41, - "timings": { - "blocked": -1, - "connect": -1, - "dns": -1, - "receive": 0, - "send": 0, - "ssl": -1, - "wait": 41 - } - } - ], - "pages": [], - "version": "1.2" - } -} diff --git a/web/src/integration/graphQlResults.ts b/web/src/integration/graphQlResults.ts index ffe6834a2a7548..bbc4970646b498 100644 --- a/web/src/integration/graphQlResults.ts +++ b/web/src/integration/graphQlResults.ts @@ -1,5 +1,6 @@ import { GraphQLOverrides } from './helpers' import { IQuery, StatusMessage, IOrg, IAlert, IMutation } from '../../../shared/src/graphql/schema' +import { builtinAuthProvider, siteID, siteGQLID } from './jscontext' export const testUserID = 'TestUserID' export const settingsID = 123 @@ -44,8 +45,8 @@ export const commonGraphQlResults: GraphQLOverrides = { }, { __typename: 'Site', - id: 'U2l0ZToic2l0ZSI=', - siteID: 'e00d94ff-adc1-432c-ab53-5181c664b1ed', + id: siteGQLID, + siteID, latestSettings: { id: 470, contents: JSON.stringify({}), @@ -78,16 +79,7 @@ export const commonGraphQlResults: GraphQLOverrides = { freeUsersExceeded: false, alerts: [] as IAlert[], authProviders: { - nodes: [ - { - serviceType: 'builtin', - serviceID: '', - clientID: '', - displayName: 'Builtin username-password authentication', - isBuiltin: true, - authenticationURL: null, - }, - ], + nodes: [builtinAuthProvider], }, disableBuiltInSearches: false, sendsEmailVerificationEmails: true, diff --git a/web/src/integration/helpers.ts b/web/src/integration/helpers.ts index 2edc419733eec1..b8a984781883b2 100644 --- a/web/src/integration/helpers.ts +++ b/web/src/integration/helpers.ts @@ -14,6 +14,9 @@ import * as path from 'path' import * as util from 'util' import { commonGraphQlResults } from './graphQlResults' import * as prettier from 'prettier' +import html from 'tagged-template-noop' +import { createJsContext } from './jscontext' +import { SourcegraphContext } from '../jscontext' // Reduce log verbosity util.inspect.defaultOptions.depth = 0 @@ -44,6 +47,11 @@ interface TestContext { */ overrideGraphQL: (overrides: GraphQLOverrides) => void + /** + * Overrides `window.context` from the default created by `createJsContext()`. + */ + overrideJsContext: (jsContext: SourcegraphContext) => void + /** * Waits for a specific GraphQL query to happen and returns the variables passed to the request. * If the query does not happen within a few seconds, it throws a timeout error. @@ -150,10 +158,11 @@ export function describeIntegration(description: string, testSuite: IntegrationT logging: false, }) const { server } = polly - server.get('/.assets/*path').passthrough() const errors = new Subject() + server.get(new URL('/.assets/*path', sourcegraphBaseUrl).href).passthrough() + // GraphQL requests are not handled by HARs, but configured per-test. let graphQlOverrides: GraphQLOverrides = commonGraphQlResults const graphQlRequests = new Subject<{ queryName: string; variables: unknown }>() @@ -175,6 +184,25 @@ export function describeIntegration(description: string, testSuite: IntegrationT response.json(result) }) + // Serve all requests for index.html (everything that does not match the handlers above) the same index.html + let jsContext = createJsContext({ sourcegraphBaseUrl }) + server.get(new URL('/*path', sourcegraphBaseUrl).href).intercept((request, response) => { + response.type('text/html').send(html` + + + Sourcegraph Test + + +
+ + + + + `) + }) + // Filter out 'server' header filled in by Caddy before persisting responses, // otherwise tests will hang when replayed from recordings. server @@ -196,6 +224,9 @@ export function describeIntegration(description: string, testSuite: IntegrationT overrideGraphQL: overrides => { graphQlOverrides = overrides }, + overrideJsContext: override => { + jsContext = override + }, waitForGraphQLRequest: async (triggerRequest, queryName) => { const requestPromise = graphQlRequests .pipe( diff --git a/web/src/integration/jscontext.ts b/web/src/integration/jscontext.ts new file mode 100644 index 00000000000000..28b6775979880a --- /dev/null +++ b/web/src/integration/jscontext.ts @@ -0,0 +1,39 @@ +import { SourcegraphContext } from '../jscontext' + +export const siteID = 'TestSiteID' +export const siteGQLID = 'TestGQLSiteID' + +export const builtinAuthProvider = { + serviceType: 'builtin', + serviceID: '', + clientID: '', + displayName: 'Builtin username-password authentication', + isBuiltin: true, + authenticationURL: '', +} + +export const createJsContext = ({ sourcegraphBaseUrl }: { sourcegraphBaseUrl: string }): SourcegraphContext => ({ + externalURL: sourcegraphBaseUrl, + accessTokensAllow: 'all-users-create', + allowSignup: false, + csrfToken: 'test-csrf-token', + assetsRoot: new URL('/.assets', sourcegraphBaseUrl).href, + deployType: 'dev', + debug: true, + emailEnabled: false, + experimentalFeatures: {}, + isAuthenticatedUser: true, + likelyDockerOnMac: false, + needServerRestart: false, + needsSiteInit: false, + resetPasswordEnabled: false, + sentryDSN: null, + site: {}, + siteID, + siteGQLID, + sourcegraphDotComMode: false, + userAgentIsBot: false, + version: '0.0.0', + xhrHeaders: {}, + authProviders: [builtinAuthProvider], +}) diff --git a/web/src/jscontext.ts b/web/src/jscontext.ts new file mode 100644 index 00000000000000..7407a506774f71 --- /dev/null +++ b/web/src/jscontext.ts @@ -0,0 +1,122 @@ +import { SiteConfiguration } from './schema/site.schema' + +export type DeployType = 'kubernetes' | 'docker-container' | 'docker-compose' | 'pure-docker' | 'dev' + +/** + * Defined in cmd/frontend/internal/app/jscontext/jscontext.go JSContext struct + */ +export interface SourcegraphContext extends Pick, 'experimentalFeatures'> { + xhrHeaders: { [key: string]: string } + csrfToken: string + userAgentIsBot: boolean + + /** + * Whether the user is authenticated. Use authenticatedUser in ./auth.ts to obtain information about the user. + */ + readonly isAuthenticatedUser: boolean + + readonly sentryDSN: string | null + + /** Externally accessible URL for Sourcegraph (e.g., https://sourcegraph.com or http://localhost:3080). */ + externalURL: string + + /** URL path to image/font/etc. assets on server */ + assetsRoot: string + + version: string + + /** + * Debug is whether debug mode is enabled. + */ + debug: boolean + + sourcegraphDotComMode: boolean + + /** + * siteID is the identifier of the Sourcegraph site. + */ + siteID: string + + /** The GraphQL ID of the Sourcegraph site. */ + siteGQLID: string + + /** + * Whether the site needs to be initialized. + */ + needsSiteInit: boolean + + /** + * Emails support enabled + */ + emailEnabled: boolean + + /** + * A subset of the site configuration. Not all fields are set. + */ + site: Pick< + SiteConfiguration, + | 'auth.public' + | 'update.channel' + | 'campaigns.readAccess.enabled' + | 'disableNonCriticalTelemetry' + | 'permissions.backgroundSync' + > + + /** Whether access tokens are enabled. */ + accessTokensAllow: 'all-users-create' | 'site-admin-create' | 'none' + + /** Whether the reset-password flow is enabled. */ + resetPasswordEnabled: boolean + + /** + * Likely running within a Docker container under a Mac host OS. + */ + likelyDockerOnMac: boolean + + /** + * Whether or not the server needs to restart in order to apply a pending + * configuration change. + */ + needServerRestart: boolean + + /** + * The kind of deployment. + */ + deployType: DeployType + + /** Whether signup is allowed on the site. */ + allowSignup: boolean + + /** Authentication provider instances in site config. */ + authProviders?: { + displayName: string + isBuiltin: boolean + authenticationURL?: string + }[] + + /** Custom branding for the homepage and search icon. */ + branding?: { + /** The URL of the favicon to be used for your instance */ + favicon?: string + + /** Override style for light themes */ + light?: BrandAssets + /** Override style for dark themes */ + dark?: BrandAssets + + /** Prevents the icon in the top-left corner of the screen from spinning. */ + disableSymbolSpin?: boolean + + brandName: string + } + + /** The publishable key for the billing service (Stripe). */ + billingPublishableKey?: string +} + +export interface BrandAssets { + /** The URL to the logo used on the homepage */ + logo?: string + /** The URL to the symbol used as the search icon */ + symbol?: string +} diff --git a/web/src/search/backend.tsx b/web/src/search/backend.tsx index d7a91cabfe603d..c81115fbea96b6 100644 --- a/web/src/search/backend.tsx +++ b/web/src/search/backend.tsx @@ -10,6 +10,7 @@ import { SearchSuggestion } from '../../../shared/src/search/suggestions' import { Remote } from 'comlink' import { FlatExtHostAPI } from '../../../shared/src/api/contract' import { wrapRemoteObservable } from '../../../shared/src/api/client/api/common' +import { DeployType } from '../jscontext' // TODO: Make this a proper fragment, blocked by https://github.com/graph-gophers/graphql-go/issues/241. const genericSearchResultInterfaceFields = ` diff --git a/web/src/search/results/SearchResults.tsx b/web/src/search/results/SearchResults.tsx index 43d6b77311966e..007761268982d6 100644 --- a/web/src/search/results/SearchResults.tsx +++ b/web/src/search/results/SearchResults.tsx @@ -37,6 +37,7 @@ import AlertOutlineIcon from 'mdi-react/AlertOutlineIcon' import CloseIcon from 'mdi-react/CloseIcon' import { Remote } from 'comlink' import { FlatExtHostAPI } from '../../../../shared/src/api/contract' +import { DeployType } from '../../jscontext' export interface SearchResultsProps extends ExtensionsControllerProps<'executeCommand' | 'extHostAPI' | 'services'>, diff --git a/web/src/search/results/SearchResultsList.tsx b/web/src/search/results/SearchResultsList.tsx index 025aaa2a57d3d0..568da2bf7c85ef 100644 --- a/web/src/search/results/SearchResultsList.tsx +++ b/web/src/search/results/SearchResultsList.tsx @@ -31,6 +31,7 @@ import { shouldDisplayPerformanceWarning } from '../backend' import { SearchResultsInfoBar } from './SearchResultsInfoBar' import { ErrorAlert } from '../../components/alerts' import { VersionContextProps } from '../../../../shared/src/search/util' +import { DeployType } from '../../jscontext' const isSearchResults = (value: unknown): value is GQL.ISearchResults => typeof value === 'object' &&