-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Applying a walkaround patch for cypress-io/cypress#17288 (#1101)
Co-authored-by: Chris Suszyński <ksuszyns@redhat.com>
- Loading branch information
1 parent
9a948da
commit a64ce1a
Showing
5 changed files
with
168 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.