Skip to content

Commit

Permalink
Applying a walkaround patch for cypress-io/cypress#17288 (#1101)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Suszyński <ksuszyns@redhat.com>
  • Loading branch information
openshift-cherrypick-robot and cardil authored Jul 13, 2021
1 parent 9a948da commit a64ce1a
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 307 deletions.
3 changes: 2 additions & 1 deletion test/ui-e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ OCP_PASSWORD="${OCP_PASSWORD:-$(echo "$OCP_USERNAME" | sha1sum - | awk '{print $
OCP_LOGIN_PROVIDER="${OCP_LOGIN_PROVIDER:-my_htpasswd_provider}"
CYPRESS_BASE_URL="https://$(oc get route console -n openshift-console -o jsonpath='{.status.ingress[].host}')"
INSTALL_SERVERLESS="${INSTALL_SERVERLESS:-true}"
# use cypress:open to run test development UI
# use dev to run test development UI
NPM_TARGET="${NPM_TARGET:-test}"
export OCP_VERSION OCP_USERNAME OCP_PASSWORD OCP_LOGIN_PROVIDER CYPRESS_BASE_URL

Expand All @@ -53,4 +53,5 @@ logger.success '🚀 Cluster prepared for testing.'

pushd "$(dirname "${BASH_SOURCE[0]}")/ui" >/dev/null
npm install
npm run install
npm run "${NPM_TARGET}"
48 changes: 48 additions & 0 deletions test/ui/cypress/apply-patches.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const {getVersionDir} = require('cypress/lib/tasks/state')
const chalk = require('chalk')
const Diff = require('diff')
const fs = require('fs/promises')
const path = require('path')

async function applyPatches() {
const patchesDir = path.join('cypress', 'patches')
const patchesAbsDir = path.join(process.cwd(), patchesDir)
const patches = await fs.readdir(patchesAbsDir)
const installDir = getVersionDir()

console.log(`\n> Applying patches on to ${chalk.cyan(installDir)}\n`)

for (const filename of patches) {
if (!filename.endsWith('.patch')) {
continue;
}
const fullpath = path.join(patchesAbsDir, filename)
const enc = 'utf8'
const patch = await fs.readFile(fullpath, enc)
const relativeFilename = path.join(patchesDir, filename)
console.log(`>> Applying patch ${chalk.cyan(relativeFilename)}`)
await Diff.applyPatches(patch, {
loadFile: (index, callback) => {
console.debug(`>>> Loading old file: ${chalk.red(index.oldFileName)}`)
fs.readFile(path.join(installDir, index.oldFileName), enc)
.then((contents) => {
callback(null, contents)
}).catch(callback)
},
patched: (index, content, callback) => {
console.debug(`>>> Patched new file: ${chalk.green(index.newFileName)}`)
fs.writeFile(path.join(installDir, index.newFileName), content, enc)
.then(callback)
.catch(callback)
},
complete: () => {
console.log(`>> Successfully applied patch ${chalk.cyan(relativeFilename)}`)
}
})
}
}

applyPatches().catch(e => {
console.error(e)
process.exit(42)
})
12 changes: 12 additions & 0 deletions test/ui/cypress/patches/17288-check-socket-open.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# TODO: Workaround for cypress-io/cypress#17288, remove after fixed on upstream.
--- Cypress/resources/app/packages/server/node_modules/http-proxy/lib/http-proxy/passes/ws-incoming.js
+++ Cypress/resources/app/packages/server/node_modules/http-proxy/lib/http-proxy/passes/ws-incoming.js
@@ -111,7 +111,7 @@ module.exports = {
proxyReq.on('error', onOutgoingError);
proxyReq.on('response', function (res) {
// if upgrade event isn't going to happen, close the socket
- if (!res.upgrade && !socket.destroyed) {
+ if (!res.upgrade && socket.readyState === socket.OPEN && !socket.destroyed) {
socket.write(createHttpHeader('HTTP/' + res.httpVersion + ' ' + res.statusCode + ' ' + res.statusMessage, res.headers));
res.pipe(socket);
}
Loading

0 comments on commit a64ce1a

Please sign in to comment.