tests: Remove download-puppeteer-browser script (#29104)

This commit is contained in:
Chris Wendt 2021-12-16 05:33:25 -07:00 committed by GitHub
parent 2e7a2fd561
commit 0db4e13aa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 8 additions and 91 deletions

View File

@ -7,7 +7,6 @@ env:
steps:
- command:
- COVERAGE_INSTRUMENT=true dev/ci/yarn-run.sh build-storybook
- yarn --cwd client/shared run download-puppeteer-browser
- yarn run cover-storybook
- yarn nyc report -r json
- bash <(curl -s https://codecov.io/bash) -c -F typescript -F storybook

View File

@ -11,8 +11,7 @@
"graphql": "gulp graphQlSchema",
"schema": "gulp schema",
"graphql-operations": "gulp graphQlOperations",
"watch-schema": "gulp watchSchema",
"download-puppeteer-browser": "TS_NODE_COMPILER_OPTIONS=\"{\\\"module\\\":\\\"commonjs\\\"}\" ts-node-transpile-only ./scripts/download-puppeteer-browser.ts"
"watch-schema": "gulp watchSchema"
},
"sideEffects": true
}

View File

@ -1,31 +0,0 @@
import puppeteer from 'puppeteer'
import { PUPPETEER_REVISIONS } from 'puppeteer/lib/cjs/puppeteer/revisions'
import signale from 'signale'
async function main(): Promise<void> {
const browserName = process.env.BROWSER || 'chrome'
if (browserName !== 'chrome' && browserName !== 'firefox') {
signale.error(`Puppeteer browser must be "chrome" or "firefox", but got: "${browserName}"`)
process.exit(1)
}
// Current puppeteer version (12.0.1) has a broken types
// See https://github.com/puppeteer/puppeteer/issues/7100
const browserFetcher = ((puppeteer as unknown) as puppeteer.PuppeteerNode).createBrowserFetcher({
product: browserName,
})
const revision = PUPPETEER_REVISIONS[browserName === 'chrome' ? 'chromium' : 'firefox']
const revisionInfo = browserFetcher.revisionInfo(revision)
if (!revisionInfo.local) {
signale.await(`Puppeteer browser: downloading ${browserName} revision ${revision}.`)
const revisionInfo = await browserFetcher.download(revision)
signale.success(`Done downloading browser to: ${revisionInfo.executablePath}`)
} else {
signale.success(`Puppeteer browser: found existing ${browserName} revision ${revision}, skipping download.`)
}
}
main().catch(error => {
console.error(error)
process.exit(1)
})

View File

@ -16,13 +16,11 @@ import puppeteer, {
LaunchOptions,
ConsoleMessage,
Target,
BrowserFetcherRevisionInfo,
PuppeteerNode,
BrowserLaunchArgumentOptions,
BrowserConnectOptions,
} from 'puppeteer'
import puppeteerFirefox from 'puppeteer-firefox'
import { PUPPETEER_REVISIONS } from 'puppeteer/lib/cjs/puppeteer/revisions'
import { from, fromEvent, merge, Subscription } from 'rxjs'
import { filter, map, concatAll, mergeMap, mergeAll, takeUntil } from 'rxjs/operators'
import { Key } from 'ts-key-enum'
@ -774,8 +772,7 @@ export async function createDriverForTest(options?: Partial<DriverOptions>): Pro
timeout: 300000,
}
let browser: puppeteer.Browser
const browserName = resolvedOptions.browser || 'chrome'
if (browserName === 'firefox') {
if (resolvedOptions.browser === 'firefox') {
// Make sure CSP is disabled in FF preferences,
// because Puppeteer uses new Function() to evaluate code
// which is not allowed by the github.com CSP.
@ -827,32 +824,10 @@ export async function createDriverForTest(options?: Partial<DriverOptions>): Pro
args.push(`--disable-extensions-except=${chromeExtensionPath}`, `--load-extension=${chromeExtensionPath}`)
}
const revision = PUPPETEER_REVISIONS.chromium
const revisionInfo = getPuppeteerBrowser(browserName, revision)
console.log(`Using ${browserName} (revision ${revision}) executable path:`, revisionInfo.executablePath)
browser = await puppeteer.launch({ ...launchOptions, executablePath: revisionInfo.executablePath })
browser = await puppeteer.launch({ ...launchOptions })
}
const page = await browser.newPage()
return new Driver(browser, page, resolvedOptions)
}
/**
* Get the RevisionInfo (which contains the executable path) for the given
* browser and revision string.
*/
export function getPuppeteerBrowser(browserName: string, revision: string): BrowserFetcherRevisionInfo {
const browserFetcher = ((puppeteer as unknown) as puppeteer.PuppeteerNode).createBrowserFetcher({
product: browserName,
})
const revisionInfo = browserFetcher.revisionInfo(revision)
if (!revisionInfo.local) {
throw new Error(
`No local executable found for Puppeteer browser: expected ${browserName} revision "${revision}". Run "yarn run download-puppeteer-browser".`
)
}
return revisionInfo
}

View File

@ -3,10 +3,8 @@ import { pathToFileURL } from 'url'
import initStoryshots from '@storybook/addon-storyshots'
import { puppeteerTest } from '@storybook/addon-storyshots-puppeteer'
import { PUPPETEER_REVISIONS } from 'puppeteer/lib/cjs/puppeteer/revisions'
import { recordCoverage } from '@sourcegraph/shared/src/testing/coverage'
import { getPuppeteerBrowser } from '@sourcegraph/shared/src/testing/driver'
// This test suite does not actually test anything.
// It just loads up the storybook in Puppeteer and records its coverage,
@ -16,7 +14,6 @@ initStoryshots({
configPath: __dirname,
suite: 'Storybook',
test: puppeteerTest({
chromeExecutablePath: getPuppeteerBrowser('chrome', PUPPETEER_REVISIONS.chromium).executablePath,
storybookUrl: pathToFileURL(path.resolve(__dirname, '../storybook-static')).href,
testBody: async page => {
await recordCoverage(page.browser())

View File

@ -6,7 +6,7 @@
"license": "Apache-2.0",
"scripts": {
"test": "jest --testPathIgnorePatterns end-to-end --testPathIgnorePatterns regression integration",
"task:mocha": "yarn --cwd ../.. download-puppeteer-browser && cross-env TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha",
"task:mocha": "cross-env TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha",
"test:regression": "yarn task:mocha './src/regression/**/*.test.ts' --exit",
"test:regression:codeintel": "yarn task:mocha ./src/regression/codeintel.test.ts",
"test:regression:config-settings": "yarn task:mocha ./src/regression/config-settings.test.ts",

View File

@ -65,8 +65,6 @@ set -e
echo "Waiting for $URL... done"
echo "--- yarn run test-e2e"
echo "TEST: Downloading Puppeteer"
yarn --cwd client/shared run download-puppeteer-browser
env SOURCEGRAPH_BASE_URL="$URL" PERCY_ON=true ./node_modules/.bin/percy exec -- yarn run cover-e2e
echo "--- coverage"

View File

@ -97,8 +97,6 @@ function test_setup() {
function e2e() {
pushd client/web
echo "--- TEST: Downloading Puppeteer"
yarn --cwd client/shared run download-puppeteer-browser
echo "$SOURCEGRAPH_BASE_URL"
echo "--- TEST: Running tests"
yarn run test:regression:core

View File

@ -55,8 +55,6 @@ set -x
echo "--- TEST: Checking Sourcegraph instance is accessible"
curl -f http://localhost:7080
curl -f http://localhost:7080/healthz
echo "--- TEST: Downloading Puppeteer"
yarn --cwd client/shared run download-puppeteer-browser
echo "--- TEST: Running tests"
# Run all tests, and error if one fails
test_status=0

View File

@ -88,8 +88,6 @@ sleep 15
echo "--- TEST: Checking Sourcegraph instance is accessible"
curl -f http://localhost:7080
curl -f http://localhost:7080/healthz
echo "--- TEST: Downloading Puppeteer"
yarn --cwd client/shared run download-puppeteer-browser
echo "--- TEST: Running tests"
pushd client/web
yarn run test:regression:core

View File

@ -10,9 +10,6 @@ echo "--- Yarn install in root"
# mutex is necessary since CI runs various yarn installs in parallel
yarn --mutex network --frozen-lockfile --network-timeout 60000
echo "--- Download Puppeteer browser"
yarn --cwd client/shared run download-puppeteer-browser
echo "--- Run integration test suite"
# Word splittinng is intentional here. $1 contains a string with test files separated by a space.
# shellcheck disable=SC2086

View File

@ -144,23 +144,18 @@ func addWebApp(pipeline *bk.Pipeline) {
bk.Cmd("dev/ci/codecov.sh -c -F typescript -F unit"))
}
// We provide our own Chromium instance that is installed through the `download-puppeteer-browser` script
var percyBrowserExecutableEnv = bk.Env("PERCY_BROWSER_EXECUTABLE", "node_modules/puppeteer/.local-chromium/linux-901812/chrome-linux/chrome")
// Builds and tests the browser extension.
func addBrowserExt(pipeline *bk.Pipeline) {
// Browser extension integration tests
for _, browser := range []string{"chrome"} {
pipeline.AddStep(
fmt.Sprintf(":%s: Puppeteer tests for %s extension", browser, browser),
percyBrowserExecutableEnv,
bk.Env("EXTENSION_PERMISSIONS_ALL_URLS", "true"),
bk.Env("BROWSER", browser),
bk.Env("LOG_BROWSER_CONSOLE", "true"),
bk.Env("SOURCEGRAPH_BASE_URL", "https://sourcegraph.com"),
bk.Env("POLLYJS_MODE", "replay"), // ensure that we use existing recordings
bk.Cmd("yarn --frozen-lockfile --network-timeout 60000"),
bk.Cmd("yarn --cwd client/shared run download-puppeteer-browser"),
bk.Cmd("yarn --cwd client/browser -s run build"),
bk.Cmd("yarn run cover-browser-integration"),
bk.Cmd("yarn nyc report -r json"),
@ -203,7 +198,6 @@ func clientIntegrationTests(pipeline *bk.Pipeline) {
bk.Key(stepKey),
bk.DependsOn(prepStepKey),
bk.DisableManualRetry("The Percy build is finalized even if one of the concurrent agents fails. To retry correctly, restart the entire pipeline."),
percyBrowserExecutableEnv,
bk.Env("PERCY_ON", "true"),
bk.Cmd(fmt.Sprintf(`dev/ci/yarn-web-integration.sh "%s"`, chunkTestFiles)),
bk.ArtifactPaths("./puppeteer/*.png"))
@ -320,13 +314,11 @@ func addBrowserExtensionE2ESteps(pipeline *bk.Pipeline) {
for _, browser := range []string{"chrome"} {
// Run e2e tests
pipeline.AddStep(fmt.Sprintf(":%s: E2E for %s extension", browser, browser),
percyBrowserExecutableEnv,
bk.Env("EXTENSION_PERMISSIONS_ALL_URLS", "true"),
bk.Env("BROWSER", browser),
bk.Env("LOG_BROWSER_CONSOLE", "true"),
bk.Env("SOURCEGRAPH_BASE_URL", "https://sourcegraph.com"),
bk.Cmd("yarn --frozen-lockfile --network-timeout 60000"),
bk.Cmd("yarn --cwd client/shared run download-puppeteer-browser"),
bk.Cmd("pushd client/browser"),
bk.Cmd("yarn -s run build"),
bk.Cmd("yarn -s mocha ./src/end-to-end/github.test.ts ./src/end-to-end/gitlab.test.ts"),

View File

@ -33,10 +33,9 @@ func GeneratePipeline(c Config) (*bk.Pipeline, error) {
"VERSION": c.Version,
// Additional flags
"GO111MODULE": "on",
"PUPPETEER_SKIP_CHROMIUM_DOWNLOAD": "true",
"FORCE_COLOR": "3",
"ENTERPRISE": "1",
"GO111MODULE": "on",
"FORCE_COLOR": "3",
"ENTERPRISE": "1",
// Add debug flags for scripts to consume
"CI_DEBUG_PROFILE": strconv.FormatBool(c.MessageFlags.ProfilingEnabled),
// Bump Node.js memory to prevent OOM crashes

View File

@ -43,7 +43,6 @@
"deduplicate": "yarn-deduplicate -s fewer",
"release": "cd dev/release && yarn run release",
"docsite:serve": "./dev/docsite.sh -config doc/docsite.json serve -http=localhost:5080",
"download-puppeteer-browser": "yarn --cwd client/shared download-puppeteer-browser",
"build-browser-extension": "yarn --cwd client/browser run build",
"install:sg": "dev/sg/install.sh",
"optimize-svg-assets": "svgo --multipass --config=\"./svgo.config.js\""

View File

@ -965,7 +965,7 @@ tests:
cmd: yarn --cwd client/browser test
bext-build:
cmd: yarn run download-puppeteer-browser && EXTENSION_PERMISSIONS_ALL_URLS=true yarn --cwd client/browser build
cmd: EXTENSION_PERMISSIONS_ALL_URLS=true yarn --cwd client/browser build
bext-integration:
cmd: yarn --cwd client/browser test-integration
@ -974,7 +974,6 @@ tests:
cmd: yarn --cwd client/browser mocha ./src/end-to-end/github.test.ts ./src/end-to-end/gitlab.test.ts
env:
SOURCEGRAPH_BASE_URL: https://sourcegraph.com
PERCY_BROWSER_EXECUTABLE: node_modules/puppeteer/.local-chromium/linux-901812/chrome-linux/chrome
frontend:
cmd: yarn run jest --testPathIgnorePatterns end-to-end regression integration storybook