web: mute Polly.js error logging on CI (#38406)

This commit is contained in:
Valery Bugakov 2022-07-11 01:24:53 -07:00 committed by GitHub
parent 77ecb394fc
commit 0ffa954b83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 179 additions and 96 deletions

View File

@ -1,5 +1,10 @@
module.exports = {
require: ['ts-node/register/transpile-only', 'abort-controller/polyfill', __dirname + '/client/shared/dev/fetch'],
require: [
'ts-node/register/transpile-only',
'abort-controller/polyfill',
__dirname + '/client/shared/dev/fetch',
__dirname + '/client/shared/dev/suppressPollyErrors',
],
extension: ['js', 'ts'],
// 1 minute test timeout. This must be greater than the default Puppeteer
// command timeout of 30s in order to get the stack trace to point to the

View File

@ -0,0 +1,52 @@
/**
* Mute Polly.js error output on CI that's happening despite having `logging: false`.
* It's a known bug that was fixed in the next major version.
*
* The PR that tries to fix the issue: https://github.com/Netflix/pollyjs/pull/377
* The PR that fixed the issue in the next major version: https://github.com/Netflix/pollyjs/pull/427
*
* Logger logic that is suppressed by this module:
* https://github.com/davidNHK/pollyjs/blob/3e876a8cc0b28e8ef422763762bdab10027bb25d/packages/%40pollyjs/core/src/-private/logger.js
*
*/
if (process.env.CI) {
const originalLog = console.log
const originalError = console.error
const originalGroup = console.group
const originalGroupEnd = console.groupEnd
let areLogsEnabled = true
console.group = title => {
if (areLogsEnabled === false) {
return
}
// Rely on the recording prefix used by Polly to group the error output.
if (typeof title === 'string' && (title.startsWith('[SG_POLLY]') || title.startsWith('Errored ➞'))) {
areLogsEnabled = false
// Re-enable logging on `groupEnd`.
console.groupEnd = () => {
areLogsEnabled = true
console.groupEnd = originalGroupEnd
}
return
}
return originalGroup(title)
}
console.log = (...args) => {
if (areLogsEnabled) {
originalLog(...args)
}
}
console.error = (...args) => {
if (areLogsEnabled) {
originalError(...args)
}
}
}

View File

@ -136,6 +136,20 @@ function getDebugExpressionFromRegexp(tag: string, regexp: string): string {
)})).filter(e => e.innerText && e.innerText.match(/${regexp}/))`
}
// Console logs with these keywords will be removed from the console output.
const MUTE_CONSOLE_KEYWORDS = [
'[webpack-dev-server]',
'Download the React DevTools',
'[HMR]',
'[WDS]',
'Warning: componentWillReceiveProps has been renamed',
'Download the Apollo DevTools',
'Compiled in DEBUG mode',
'Cache data may be lost',
'Failed to decode downloaded font',
'OTS parsing error',
]
export class Driver {
/** The pages that were visited since the creation of the driver. */
public visitedPages: Readonly<URL>[] = []
@ -174,19 +188,14 @@ export class Driver {
fromEvent<ConsoleMessage>(page, 'console').pipe(
filter(
message =>
!message.text().includes('Download the React DevTools') &&
!message.text().includes('[HMR]') &&
!message.text().includes('[WDS]') &&
!message
.text()
.includes('Warning: componentWillReceiveProps has been renamed') &&
!message.text().includes('Download the Apollo DevTools') &&
!message.text().includes('debug') &&
// These requests are expected to fail, we use them to check if the browser extension is installed.
message.location().url !== 'chrome-extension://invalid/'
message.location().url !== 'chrome-extension://invalid/' &&
// Ignore React development build warnings.
!message.text().startsWith('Warning: ') &&
!MUTE_CONSOLE_KEYWORDS.some(keyword => message.text().includes(keyword))
),
// Immediately format remote handles to strings, but maintain order.
map(message =>
// Immediately format remote handles to strings, but maintain order.
formatPuppeteerConsoleMessage(page, message, this.browserType === 'firefox')
),
concatAll(),
@ -291,12 +300,12 @@ export class Driver {
await this.browser.close()
}
console.log(
'\nVisited routes:\n' +
'\n Visited routes:\n' +
[
...new Set(
this.visitedPages
.filter(url => url.href.startsWith(this.sourcegraphBaseUrl))
.map(url => url.pathname)
.map(url => ` ${url.pathname}`)
),
].join('\n')
)

View File

@ -104,6 +104,9 @@ export interface IntegrationTestOptions {
const DISPOSE_ACTION_TIMEOUT = 5 * 1000
// Used in `suppressPollyErrors.js` to suppress error logging.
const POLLY_RECORDING_PREFIX = '[SG_POLLY] '
/**
* Should be called in a `beforeEach()` and saved into a local variable.
*/
@ -125,7 +128,8 @@ export const createSharedIntegrationTestContext = async <
const cdpAdapterOptions: CdpAdapterOptions = {
browser: driver.browser,
}
const polly = new Polly(snakeCase(currentTest.title), {
const polly = new Polly(POLLY_RECORDING_PREFIX + snakeCase(currentTest.title), {
adapters: [CdpAdapter.id],
adapterOptions: {
[CdpAdapter.id]: cdpAdapterOptions,
@ -155,7 +159,17 @@ export const createSharedIntegrationTestContext = async <
const cdpAdapter = polly.adapters.get(CdpAdapter.id) as CdpAdapter
subscriptions.add(
cdpAdapter.errors.subscribe(error => {
currentTest.emit('error', error)
/**
* Do not emit errors on completed tests.
*
* This can happen when GraphQL is not mocked and we throw an error about that but
* this mock is not required for test completion and test passes before we throw the error.
*
* These types of errors are irrelevant to the test output.
*/
if (currentTest.isPending()) {
currentTest.emit('error', error)
}
})
)

View File

@ -3,7 +3,7 @@ import expect from 'expect'
import { test } from 'mocha'
import { encodeURIPathComponent } from '@sourcegraph/common'
import { SearchGraphQlOperations } from '@sourcegraph/search'
import { mixedSearchStreamEvents, SearchGraphQlOperations } from '@sourcegraph/search'
import { SharedGraphQlOperations } from '@sourcegraph/shared/src/graphql-operations'
import { Driver, createDriverForTest } from '@sourcegraph/shared/src/testing/driver'
import { afterEachSaveScreenshotIfFailed } from '@sourcegraph/shared/src/testing/screenshotReporter'
@ -79,6 +79,7 @@ describe('GlobalNavbar', () => {
})
testContext.overrideGraphQL(commonSearchGraphQLResults)
testContext.overrideSearchStreamEvents(mixedSearchStreamEvents)
})
afterEachSaveScreenshotIfFailed(() => driver.page)

View File

@ -277,7 +277,6 @@ export const StreamingSearchResults: React.FunctionComponent<
telemetryService.log('SearchResultsFetchFailed', {
code_search: { error_message: asError(results.error).message },
})
console.error(results.error)
}
}, [results, telemetryService])

View File

@ -11,7 +11,7 @@ echo "--- Yarn install in root"
yarn --mutex network --frozen-lockfile --network-timeout 60000 --silent
echo "--- Run integration test suite"
yarn percy exec --quiet yarn _cover-integration "$@"
yarn percy exec --quiet -- yarn _cover-integration "$@"
echo "--- Process NYC report"
yarn nyc report -r json

View File

@ -461,12 +461,15 @@ _Solution:_ Double-check mocks required for rendering the snapshotted UI.
_Problem:_ The screenshot is taken without waiting for the UI to settle down. E.g., a snapshot taken after clicking an input element doesnt wait for the focus state on it.
_Solution:_ Wait for the UI to settle using tools provided by Puppeteer.
#### Visual regression flakes caused by test logic
#### Integration test flakes caused by test logic
_Problem:_ `Error: GraphQL query "XXX" has no configured mock response. Make sure the call to overrideGraphQL() includes a result for the "XXX" query.` This error can be flaky because some GraphQL mocks are not required for an integration test to pass because the request with a missing mock can be processed by our test driver _after_ the test already passed. In that case, it won't cause the test to fail.
_Solution:_ All GraphQL requests happening on tested pages should have GraphQL mocks to avoid such flakes.
_Problem examples:_
1. `Navigation timeout of 30000 ms exceeded.`
2. `Error: GraphQL query "XXX" has no configured mock response. Make sure the call to overrideGraphQL() includes a result for the "XXX" query.`
2. `TimeoutError: waiting for selector '.theme.theme-dark' failed: timeout 30000ms exceeded`
_Solution:_ These should be disabled immediately and fixed later by owning teams.

View File

@ -122,7 +122,7 @@
"@mermaid-js/mermaid-cli": "^8.13.4",
"@octokit/rest": "^16.36.0",
"@peculiar/webcrypto": "^1.1.7",
"@percy/cli": "^1.2.1",
"@percy/cli": "^1.6.0",
"@percy/puppeteer": "^2.0.0",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.0-rc.1",
"@pollyjs/adapter": "^5.0.0",

150
yarn.lock
View File

@ -3157,96 +3157,96 @@
tslib "^2.2.0"
webcrypto-core "^1.2.0"
"@percy/cli-build@1.3.0":
version "1.3.0"
resolved "https://registry.npmjs.org/@percy/cli-build/-/cli-build-1.3.0.tgz#abfb8350cbd2c93688eb6e5340c521c346dca952"
integrity sha512-iq8aAE+PgQ7m8M37uOFTCj6a46c2eNZudxJLePN+qNtIwtWtoFa/UL+QyWEsxl1a+jEQ8qZZLPSvLPs8bofClw==
"@percy/cli-build@1.6.0":
version "1.6.0"
resolved "https://registry.npmjs.org/@percy/cli-build/-/cli-build-1.6.0.tgz#4e82b081fea993ece789f102ea9cc5ad71a20edb"
integrity sha512-ABMnWccKENvvLX7n7xgUyNDlApxWmDLBUPq2kMrWkNNcLmpVrFFWiRu2eRCa2jFh772ceFkDLNpxueVRIq8pTw==
dependencies:
"@percy/cli-command" "1.3.0"
"@percy/cli-command" "1.6.0"
"@percy/cli-command@1.3.0":
version "1.3.0"
resolved "https://registry.npmjs.org/@percy/cli-command/-/cli-command-1.3.0.tgz#d82c190f2f0a27e9e59d30415ed5de42ca836f7c"
integrity sha512-0mZ0s/HdVM/sfQA0wiRPKvPoZiG59/U3+oEYLjkz/4x7OymP1cGymTRSVypHT7ZmBGg1Q928gosgjpzWrzM5AA==
"@percy/cli-command@1.6.0":
version "1.6.0"
resolved "https://registry.npmjs.org/@percy/cli-command/-/cli-command-1.6.0.tgz#3227e5429adfaf1ff8bd170df571f72c46286beb"
integrity sha512-seJ3bkRKS1Nmf9GLE1K5Mqvl01MdejmWD9c6kuYcJndGGkwp6xqUDjhbtIHPxFp1UOTa7b6cb0CT6o01C7VjmQ==
dependencies:
"@percy/config" "1.3.0"
"@percy/core" "1.3.0"
"@percy/logger" "1.3.0"
"@percy/config" "1.6.0"
"@percy/core" "1.6.0"
"@percy/logger" "1.6.0"
"@percy/cli-config@1.3.0":
version "1.3.0"
resolved "https://registry.npmjs.org/@percy/cli-config/-/cli-config-1.3.0.tgz#dbd6dcbb29100e796a0c45d38ee25d037a935b80"
integrity sha512-Ad3XMQldyu3U6KxJPjYmROoKyadRw9c/8doDjMEkPVcFdsHoHnqyYPL0BFmLBoWwJOaDgjOrsjdp17HLbNsOqQ==
"@percy/cli-config@1.6.0":
version "1.6.0"
resolved "https://registry.npmjs.org/@percy/cli-config/-/cli-config-1.6.0.tgz#19e65dad1385f533e577743b80c4974fdf7b2c86"
integrity sha512-GRj6yiL0SDC37Cg70gFibiIBQ5vDxQPeYVqTeXxT2jnGzcQokTLvI/qz9q1WrJhVxf6NZozuWCCE1XO5iisFjA==
dependencies:
"@percy/cli-command" "1.3.0"
"@percy/cli-command" "1.6.0"
"@percy/cli-exec@1.3.0":
version "1.3.0"
resolved "https://registry.npmjs.org/@percy/cli-exec/-/cli-exec-1.3.0.tgz#4fbbe37939c81ceadfd3f3f853df494b3f3c13dd"
integrity sha512-dCI1ED/WbQcYrUFGYaCI54PHfOADOkAKeKLlE7WLDCmLJvjx2JIoO+a/VJE2EVh0+j1zOUItMq20ejzoRe6a/A==
"@percy/cli-exec@1.6.0":
version "1.6.0"
resolved "https://registry.npmjs.org/@percy/cli-exec/-/cli-exec-1.6.0.tgz#c9fbb67f7f0c797fb2b766ef86ade102b606a8d5"
integrity sha512-Tm5XosxBR48n+byOVU18H9avYKD1c1oAj0celROGoq4sE0nG0Mus7O/JlwShvEzwQLXaHemmAEqt7n4pdX8peA==
dependencies:
"@percy/cli-command" "1.3.0"
"@percy/cli-command" "1.6.0"
cross-spawn "^7.0.3"
which "^2.0.2"
"@percy/cli-snapshot@1.3.0":
version "1.3.0"
resolved "https://registry.npmjs.org/@percy/cli-snapshot/-/cli-snapshot-1.3.0.tgz#24836b2a1cc7ead2533631dce70a5e22b76cdc2f"
integrity sha512-t2cu4stv5th94I2eeIku4KUn3YvI+Pzu2W0S0rCwT5wEaJUo7sBB+EptXKNrPyWrrZvFnZoly7DA41z5hyQP8w==
"@percy/cli-snapshot@1.6.0":
version "1.6.0"
resolved "https://registry.npmjs.org/@percy/cli-snapshot/-/cli-snapshot-1.6.0.tgz#9be14d4c5046a373d0f91ef3fe46cc83c2418984"
integrity sha512-sf9VdPepJEPyPDySfJXQ4WEbWZ5Dqsbh8QYRm9NOHQazmaHZ+mdtccnN9lCwNNuulm78hixA0Ahv0C6L3YiB9g==
dependencies:
"@percy/cli-command" "1.3.0"
"@percy/cli-command" "1.6.0"
yaml "^2.0.0"
"@percy/cli-upload@1.3.0":
version "1.3.0"
resolved "https://registry.npmjs.org/@percy/cli-upload/-/cli-upload-1.3.0.tgz#d828f768e79e028e2a9504b54dee4279e9f1cc7d"
integrity sha512-4MlZMDFIyXb53Yg3GdZSR29AlGQltM3jwlG3z7lr6rueBJjo5IflvWUPsfAQ8Lu+oEqYj3y2j8PZfSimHKuE4w==
"@percy/cli-upload@1.6.0":
version "1.6.0"
resolved "https://registry.npmjs.org/@percy/cli-upload/-/cli-upload-1.6.0.tgz#3ee9a3adec1b62ca9f91a647e9e323fcf8f11345"
integrity sha512-k1Hy/Q4W/OV5+Qqf5bzDUt2v2In0+tM6XZWfAR89GxZuxTWpIQ15tYtd3/FsSVOdPPE8sPfYbMXnBuaSjp2ooQ==
dependencies:
"@percy/cli-command" "1.3.0"
"@percy/cli-command" "1.6.0"
fast-glob "^3.2.11"
image-size "^1.0.0"
"@percy/cli@^1.2.1":
version "1.3.0"
resolved "https://registry.npmjs.org/@percy/cli/-/cli-1.3.0.tgz#bf9807809dc1192139a61ba4799cf1b5da1a2f19"
integrity sha512-33u8dGTG0APVQKOSZIq/uxA77xCcR65BZ2KhxRtEZCSKDUuF5WbSzBRspCj4dpvlnSlIQrTFJv8TEt22COI5EQ==
"@percy/cli@^1.6.0":
version "1.6.0"
resolved "https://registry.npmjs.org/@percy/cli/-/cli-1.6.0.tgz#4c584939ff275fbb1974f69de61286777e489b1b"
integrity sha512-mto3ds3iRbl2nzqJQMhPX9BNARDInydfqkGlaeAZi1q+VfMAbNuSpi1AoT1OLNYWCRrbvQgcJ0NRPTMIq9Ll4Q==
dependencies:
"@percy/cli-build" "1.3.0"
"@percy/cli-command" "1.3.0"
"@percy/cli-config" "1.3.0"
"@percy/cli-exec" "1.3.0"
"@percy/cli-snapshot" "1.3.0"
"@percy/cli-upload" "1.3.0"
"@percy/client" "1.3.0"
"@percy/logger" "1.3.0"
"@percy/cli-build" "1.6.0"
"@percy/cli-command" "1.6.0"
"@percy/cli-config" "1.6.0"
"@percy/cli-exec" "1.6.0"
"@percy/cli-snapshot" "1.6.0"
"@percy/cli-upload" "1.6.0"
"@percy/client" "1.6.0"
"@percy/logger" "1.6.0"
"@percy/client@1.3.0":
version "1.3.0"
resolved "https://registry.npmjs.org/@percy/client/-/client-1.3.0.tgz#1cabc6787ebe7824b67dd82e710d4da84ff82598"
integrity sha512-qkXC183vyY9QhGrD1AbXwtYftor9D/T6I+BoO1dcxt3S4U+S4+FHhmPKFstLfGxzleEn2MhWVN3mMaMQYd0g5g==
"@percy/client@1.6.0":
version "1.6.0"
resolved "https://registry.npmjs.org/@percy/client/-/client-1.6.0.tgz#33470d20891ddfcfc4a3f1a6d3c2b0c404eada75"
integrity sha512-pUC1ZUaCpHcKCORIOrE/Y2+7LgELGX/s0X3INCFMIiFcgQK+FyQAjV+0x4MG+FJJvtxfj5WoP4LVu1XWlbyHrg==
dependencies:
"@percy/env" "1.3.0"
"@percy/logger" "1.3.0"
"@percy/env" "1.6.0"
"@percy/logger" "1.6.0"
"@percy/config@1.3.0":
version "1.3.0"
resolved "https://registry.npmjs.org/@percy/config/-/config-1.3.0.tgz#62879d915915b542a795f2919e1c9da6eb34419c"
integrity sha512-H1nVxinIg4yjOfXovNA0pbQ78ac/xdib2XkR7EwgDPrHbBdcTqkJ2EjPNImuL9b67QHkkz7U4lqR8cUUjyDqmA==
"@percy/config@1.6.0":
version "1.6.0"
resolved "https://registry.npmjs.org/@percy/config/-/config-1.6.0.tgz#5e720c76fca8cb8872257b3a6630ffad1fce4e36"
integrity sha512-g5wDYRqyrSxoTszLxmw/cb1DIjuc91uYQZNVjNc7TWtX8Rvlvbr1fOhaLq5/bmB8N6kLP2sXmcdz9zO4Fuw53g==
dependencies:
"@percy/logger" "1.3.0"
"@percy/logger" "1.6.0"
ajv "^8.6.2"
cosmiconfig "^7.0.0"
yaml "^2.0.0"
"@percy/core@1.3.0":
version "1.3.0"
resolved "https://registry.npmjs.org/@percy/core/-/core-1.3.0.tgz#1c1503ba24d63e7678cddabc5dcbb98bb7503ddf"
integrity sha512-kCpJr9AT0qFOaVbrGhx14qJCZiOUvJVxejUOcqk02Vzj99Q+DGvLUyd/Cg/lw3fyJdlEhTytZzz2WuPYkNRQrg==
"@percy/core@1.6.0":
version "1.6.0"
resolved "https://registry.npmjs.org/@percy/core/-/core-1.6.0.tgz#ff2c29a11883f6251a5e664dfb130a1296f69a99"
integrity sha512-pXqzmg84cQO39xAT90RChnh7R2Xfv7e3Tu0z1/pEO7/TbxAbMFN5xjLYEXExmbvRlBZ1aMlhjfeHMcMWodyC8A==
dependencies:
"@percy/client" "1.3.0"
"@percy/config" "1.3.0"
"@percy/dom" "1.3.0"
"@percy/logger" "1.3.0"
"@percy/client" "1.6.0"
"@percy/config" "1.6.0"
"@percy/dom" "1.6.0"
"@percy/logger" "1.6.0"
content-disposition "^0.5.4"
cross-spawn "^7.0.3"
extract-zip "^2.0.1"
@ -3257,25 +3257,25 @@
rimraf "^3.0.2"
ws "^8.0.0"
"@percy/dom@1.3.0":
version "1.3.0"
resolved "https://registry.npmjs.org/@percy/dom/-/dom-1.3.0.tgz#e928e526a5ebfc37b61c59b8409e920e6813e240"
integrity sha512-wY6nIXD8zhwfHXROOYYfU9qht9yWn5GgOdDWZAbcOe2qxpivfuKF4qOubKD9iwCgUZhFxRc5xUSciCGKdOm1TQ==
"@percy/dom@1.6.0":
version "1.6.0"
resolved "https://registry.npmjs.org/@percy/dom/-/dom-1.6.0.tgz#15a9363ad45757b71287fa0ef982f58d69877311"
integrity sha512-yy5BCSTS6q0aOaA0v5kthgl/Ap8GPTJNfjmMTZxOjsxZ5WpVWWgMItkLo/sWcV77YJQG+Q343xCd/+thH393NA==
"@percy/env@1.3.0":
version "1.3.0"
resolved "https://registry.npmjs.org/@percy/env/-/env-1.3.0.tgz#1413a1c4207d40418fbbc3f3367bc33835a2d970"
integrity sha512-sAOKdUGYEYPf2TRgCL8P5INqwXuqaczTWICQ2G90pLzUFV0mHo+5ih+XHGtAi5wdv1Tpz088nia+eXYXpwi4og==
"@percy/env@1.6.0":
version "1.6.0"
resolved "https://registry.npmjs.org/@percy/env/-/env-1.6.0.tgz#47cc9a886a3ab1045c1bbff30831fad16abb485a"
integrity sha512-nQpAspFtKdU7fwyVyEY+JtWMohrRfPug6osLRV6DmZnBvT9SLJ4Fh67W06xOGL6PBGiWLuCKyS5d7tJi+WWkUw==
"@percy/logger@1.0.0-beta.68":
version "1.0.0-beta.68"
resolved "https://registry.npmjs.org/@percy/logger/-/logger-1.0.0-beta.68.tgz#6c42ba7d7b4350db99c3ba5fa622db7daf27e442"
integrity sha512-PmKMLOexQUlsPASy4vQEQRYa0KHec/6xWsAg/wnWhGgmnQA4l9EKcz7ZvjDWA6H+wrErLM+FdvMsd8POf417CQ==
"@percy/logger@1.3.0":
version "1.3.0"
resolved "https://registry.npmjs.org/@percy/logger/-/logger-1.3.0.tgz#2453816f5463e9864eb0ae3c837e82d3b35bd598"
integrity sha512-fCuhFBXRuJruz9PNdeMZXgEhUODmhXt4hiMLBWAn1cpV8evQah3tXbHqwxEqWzLHGfbPYCKZmgk49NJvwHQKmw==
"@percy/logger@1.6.0":
version "1.6.0"
resolved "https://registry.npmjs.org/@percy/logger/-/logger-1.6.0.tgz#09653444013ba3bae152543c8721e6c9e025d2d5"
integrity sha512-4Y3dQdVDgFtEHtou2IVSNqaxGNOp0QeVWGx/4wbxchrPh8fXpBcXuYRHQRgpH+vDlb8pdx7cOFSlGJuOXN8LMw==
"@percy/puppeteer@^2.0.0":
version "2.0.0"