From 9d02c67ff8777507f00a07a3cc572112fbf69b73 Mon Sep 17 00:00:00 2001 From: Alexander Prokhorov Date: Mon, 9 Nov 2026 16:02:04 +0200 Subject: [PATCH 1/3] Inline V8 flags filter dependency Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- bin/testcafe-with-v8-flag-filter.js | 2 +- bin/v8-flags-filter.js | 141 ++++++++++++++++++++++++++++ package-lock.json | 7 -- package.json | 1 - test/node/v8-flags-filter-test.js | 35 +++++++ 5 files changed, 177 insertions(+), 9 deletions(-) create mode 100644 bin/v8-flags-filter.js create mode 100644 test/node/v8-flags-filter-test.js diff --git a/bin/testcafe-with-v8-flag-filter.js b/bin/testcafe-with-v8-flag-filter.js index ef5f6e80336..c39ae01e55d 100755 --- a/bin/testcafe-with-v8-flag-filter.js +++ b/bin/testcafe-with-v8-flag-filter.js @@ -4,7 +4,7 @@ const path = require('path'); const url = require('url'); -const v8FlagsFilter = require('@devexpress/bin-v8-flags-filter'); +const v8FlagsFilter = require('./v8-flags-filter'); const semver = require('semver'); const ESM_OPTION = '--esm'; diff --git a/bin/v8-flags-filter.js b/bin/v8-flags-filter.js new file mode 100644 index 00000000000..fa69f177b55 --- /dev/null +++ b/bin/v8-flags-filter.js @@ -0,0 +1,141 @@ +'use strict'; + +/* +The MIT License (MIT) + +Copyright (c) 2016 Ivan Nikulin (ifaaan@gmail.com, https://github.com/inikulin) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +const { spawn } = require('child_process'); + +const FLAGS = [ + 'debug', + '--debug', + '--debug-brk', + '--inspect', + '--inspect-brk', + '--expose-gc', + '--gc-global', + '--es_staging', + '--no-deprecation', + '--prof', + '--log-timer-events', + '--throw-deprecation', + '--trace-deprecation', + '--use_strict', + '--allow-natives-syntax', + '--perf-basic-prof', + '--experimental-repl-await', + '--experimental-loader', + '--no-warnings', +]; + +const FLAG_PREFIXES = [ + '--harmony', + '--trace', + '--icu-data-dir', + '--max-old-space-size', + '--preserve-symlinks', +]; + +const DEFAULT_FORCED_KILL_DELAY = 30000; + +function getChildArgs (cliPath, ignore) { + const args = [cliPath]; + + process.argv.slice(2).forEach(arg => { + const flag = arg.split('=')[0]; + + if (ignore.indexOf(flag) > -1) { + args.push(arg); + return; + } + + if (FLAGS.indexOf(flag) > -1) { + args.unshift(arg); + return; + } + + if (FLAG_PREFIXES.some(prefix => arg.indexOf(prefix) === 0)) { + args.unshift(arg); + return; + } + + args.push(arg); + }); + + return args; +} + +function setupSignalHandler (signal, childProcess, useShutdownMessage, forcedKillDelay) { + function forceKill () { + childProcess.kill('SIGTERM'); + } + + function handler () { + if (useShutdownMessage) + childProcess.send('shutdown'); + else + childProcess.kill(signal); + + setTimeout(forceKill, forcedKillDelay).unref(); + } + + process.on(signal, handler); +} + +module.exports = function (cliPath, opts) { + opts = opts || {}; + + const useShutdownMessage = opts.useShutdownMessage; + const forcedKillDelay = opts.forcedKillDelay || DEFAULT_FORCED_KILL_DELAY; + const ignore = opts.ignore || []; + const args = getChildArgs(cliPath, ignore); + + if (opts.forcedArgs && opts.forcedArgs.length > 0) + args.unshift(...opts.forcedArgs); + + const cliProc = spawn(process.execPath, args, { + stdio: [process.stdin, process.stdout, process.stderr, useShutdownMessage ? 'ipc' : null], + }); + + cliProc.on('exit', (code, signal) => { + if (useShutdownMessage && process.disconnect) + process.disconnect(); + + process.on('exit', () => { + if (signal) + process.kill(process.pid, signal); + else + process.exit(code); + }); + }); + + setupSignalHandler('SIGINT', cliProc, useShutdownMessage, forcedKillDelay); + setupSignalHandler('SIGBREAK', cliProc, useShutdownMessage, forcedKillDelay); + + if (useShutdownMessage) { + process.on('message', message => { + if (message === 'shutdown') + cliProc.send('shutdown'); + }); + } +}; diff --git a/package-lock.json b/package-lock.json index 9acd0a5e39b..2f178074d1b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,6 @@ "@babel/preset-flow": "^7.22.15", "@babel/preset-react": "^7.22.15", "@babel/runtime": "^7.23.2", - "@devexpress/bin-v8-flags-filter": "^1.3.0", "@types/node": "20.14.5", "address": "^2.0.2", "async-exit-hook": "^1.1.2", @@ -1947,12 +1946,6 @@ "node": ">=6.9.0" } }, - "node_modules/@devexpress/bin-v8-flags-filter": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/@devexpress/bin-v8-flags-filter/-/bin-v8-flags-filter-1.3.0.tgz", - "integrity": "sha512-LWLNfYGwVJKYpmHUDoODltnlqxdEAl5Qmw7ha1+TSpsABeF94NKSWkQTTV1TB4CM02j2pZyqn36nHgaFl8z7qw==", - "license": "MIT" - }, "node_modules/@devexpress/gulp-qunit-harness": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@devexpress/gulp-qunit-harness/-/gulp-qunit-harness-1.1.0.tgz", diff --git a/package.json b/package.json index 621bf584ab1..d0c4daf5cce 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,6 @@ "@babel/preset-flow": "^7.22.15", "@babel/preset-react": "^7.22.15", "@babel/runtime": "^7.23.2", - "@devexpress/bin-v8-flags-filter": "^1.3.0", "@types/node": "20.14.5", "address": "^2.0.2", "async-exit-hook": "^1.1.2", diff --git a/test/node/v8-flags-filter-test.js b/test/node/v8-flags-filter-test.js new file mode 100644 index 00000000000..79f3e782c91 --- /dev/null +++ b/test/node/v8-flags-filter-test.js @@ -0,0 +1,35 @@ +'use strict'; + +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const os = require('node:os'); +const path = require('node:path'); +const { spawnSync } = require('node:child_process'); +const { test } = require('node:test'); + +test('forwards V8 flags and forced arguments to the child process', t => { + const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'testcafe-v8-flags-filter-')); + const cliPath = path.join(tempDir, 'cli.js'); + + t.after(() => fs.rmSync(tempDir, { recursive: true, force: true })); + + fs.writeFileSync(cliPath, 'console.log(JSON.stringify({ args: process.argv.slice(2), execArgv: process.execArgv }));'); + + const filterPath = path.resolve(__dirname, '../../bin/v8-flags-filter.js'); + const runner = `require(${JSON.stringify(filterPath)})(process.argv[1], { forcedArgs: ['--no-deprecation'] });`; + const result = spawnSync(process.execPath, [ + '-e', + runner, + cliPath, + '--trace-gc', + '--allow-natives-syntax', + '--test-option', + ], { encoding: 'utf8' }); + + assert.equal(result.status, 0, result.stderr); + + const output = JSON.parse(result.stdout.trim().split(/\r?\n/).at(-1)); + + assert.deepEqual(output.args, ['--test-option']); + assert.deepEqual(output.execArgv, ['--no-deprecation', '--allow-natives-syntax', '--trace-gc']); +}); From 0903655cd9e4dd5a177aeb7e2f77afbaf0eec65e Mon Sep 17 00:00:00 2001 From: Alexander Prokhorov Date: Mon, 9 Nov 2026 16:41:40 +0200 Subject: [PATCH 2/3] move v8 flags filter test to server fiolder --- test/{node => server}/v8-flags-filter-test.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{node => server}/v8-flags-filter-test.js (100%) diff --git a/test/node/v8-flags-filter-test.js b/test/server/v8-flags-filter-test.js similarity index 100% rename from test/node/v8-flags-filter-test.js rename to test/server/v8-flags-filter-test.js From 688c6673c32b3502544ce3ad9853cc42c2b129b5 Mon Sep 17 00:00:00 2001 From: Alexander Prokhorov Date: Mon, 9 Nov 2026 17:16:03 +0200 Subject: [PATCH 3/3] . --- test/server/v8-flags-filter-test.js | 66 +++++++++++++++-------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/test/server/v8-flags-filter-test.js b/test/server/v8-flags-filter-test.js index 79f3e782c91..5a0f06d8794 100644 --- a/test/server/v8-flags-filter-test.js +++ b/test/server/v8-flags-filter-test.js @@ -1,35 +1,39 @@ 'use strict'; -const assert = require('node:assert/strict'); -const fs = require('node:fs'); -const os = require('node:os'); -const path = require('node:path'); +const fs = require('node:fs'); +const os = require('node:os'); +const path = require('node:path'); const { spawnSync } = require('node:child_process'); -const { test } = require('node:test'); - -test('forwards V8 flags and forced arguments to the child process', t => { - const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'testcafe-v8-flags-filter-')); - const cliPath = path.join(tempDir, 'cli.js'); - - t.after(() => fs.rmSync(tempDir, { recursive: true, force: true })); - - fs.writeFileSync(cliPath, 'console.log(JSON.stringify({ args: process.argv.slice(2), execArgv: process.execArgv }));'); - - const filterPath = path.resolve(__dirname, '../../bin/v8-flags-filter.js'); - const runner = `require(${JSON.stringify(filterPath)})(process.argv[1], { forcedArgs: ['--no-deprecation'] });`; - const result = spawnSync(process.execPath, [ - '-e', - runner, - cliPath, - '--trace-gc', - '--allow-natives-syntax', - '--test-option', - ], { encoding: 'utf8' }); - - assert.equal(result.status, 0, result.stderr); - - const output = JSON.parse(result.stdout.trim().split(/\r?\n/).at(-1)); - - assert.deepEqual(output.args, ['--test-option']); - assert.deepEqual(output.execArgv, ['--no-deprecation', '--allow-natives-syntax', '--trace-gc']); +const { expect } = require('chai'); + +describe('V8 flags filter', function () { + it('forwards V8 flags and forced arguments to the child process', function () { + const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'testcafe-v8-flags-filter-')); + const cliPath = path.join(tempDir, 'cli.js'); + + try { + fs.writeFileSync(cliPath, 'console.log(JSON.stringify({ args: process.argv.slice(2), execArgv: process.execArgv }));'); + + const filterPath = path.resolve(__dirname, '../../bin/v8-flags-filter.js'); + const runner = `require(${JSON.stringify(filterPath)})(process.argv[1], { forcedArgs: ['--no-deprecation'] });`; + const result = spawnSync(process.execPath, [ + '-e', + runner, + cliPath, + '--trace-gc', + '--allow-natives-syntax', + '--test-option', + ], { encoding: 'utf8' }); + + expect(result.status, result.stderr).to.equal(0); + + const output = JSON.parse(result.stdout.trim().split(/\r?\n/).at(-1)); + + expect(output.args).to.deep.equal(['--test-option']); + expect(output.execArgv).to.deep.equal(['--no-deprecation', '--allow-natives-syntax', '--trace-gc']); + } + finally { + fs.rmSync(tempDir, { recursive: true, force: true }); + } + }); });