From e90267b69a76e39c3675ddc770fdd6e6f09d5fc0 Mon Sep 17 00:00:00 2001 From: Julien Mounier Date: Sun, 17 Dec 2023 15:23:47 +0100 Subject: [PATCH 1/3] chore: upgrade fetch-cookie from 0.11.0 to 2.1.0 Mitigates CVE-2023-26136: https://github.com/advisories/GHSA-72xf-g2v4-qvf3 Only one breaking change according to changelog: - the redirect logic is now included in the main export and the node-fetch wrapper (require('fetch-cookie/node-fetch')) was removed. Just require('node-fetch') and you're good to go with redirects! cf. https://github.com/valeriangalliat/fetch-cookie/blob/master/CHANGELOG.md --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a283289395..0517a97535 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "abort-controller": "3.0.0", "clone-buffer": "1.0.0", "double-ended-queue": "2.1.0-0", - "fetch-cookie": "0.11.0", + "fetch-cookie": "2.1.0", "fruitdown": "1.0.2", "immediate": "3.3.0", "level": "6.0.1", From 519e33168e27f8e44eb6e56a9facdcaae2d19cea Mon Sep 17 00:00:00 2001 From: Alex Anderson <191496+alxndrsn@users.noreply.github.com> Date: Sat, 30 Dec 2023 13:35:13 +0300 Subject: [PATCH 2/3] playwright: handle externally-triggered browser-close event (#8836) Previously if the browser is closed during a playwright test run by an external event, the tests would hang indefinitely. This commit makes the test run fail immediately. --- bin/test-browser.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bin/test-browser.js b/bin/test-browser.js index f0f91e2826..6f231ba63b 100755 --- a/bin/test-browser.js +++ b/bin/test-browser.js @@ -12,6 +12,9 @@ var devserver = require('./dev-server.js'); // BAIL=0 to disable bailing var bail = process.env.BAIL !== '0'; +// Track if the browser has closed at the request of this script, or due to an external event. +let closeRequested; + // Playwright BrowserType whitelist. // See: https://playwright.dev/docs/api/class-playwright const SUPPORTED_BROWSERS = [ 'chromium', 'firefox', 'webkit' ]; @@ -91,12 +94,14 @@ class RemoteRunner { } catch (e) { console.error('Tests failed:', e); + closeRequested = true; await this.browser.close(); process.exit(3); } } async handleEnd(failed) { + closeRequested = true; await this.browser.close(); process.exit(!process.env.PERF && failed ? 1 : 0); } @@ -147,8 +152,20 @@ async function startTest() { headless: true, }; const browser = await playwright[browserName].launch(options); + const page = await browser.newPage(); + // Playwright's Browser.on('close') event handler would be the more obvious + // choice here, but it does not seem to be triggered if the browser is closed + // by an external event (e.g. process is killed, user closes non-headless + // browser window). + page.on('close', () => { + if (!closeRequested) { + console.log('!!! Browser closed by external event.'); + process.exit(1); + } + }); + const runner = new RemoteRunner(browser); new MochaSpecReporter(runner); new BenchmarkConsoleReporter(runner); From a6b47e291ff210c05d2e767b6ca70c2eb7467e66 Mon Sep 17 00:00:00 2001 From: Alex Anderson <191496+alxndrsn@users.noreply.github.com> Date: Sat, 30 Dec 2023 14:36:05 +0300 Subject: [PATCH 3/3] chore(test): update mocha from v3.5 to v10 (#8838) Co-authored-by: Gareth Bowen --- bin/test-browser.js | 34 ++++++++++++++++++++++++---------- bin/test-node.sh | 4 ++++ package.json | 4 ++-- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/bin/test-browser.js b/bin/test-browser.js index 6f231ba63b..eeadce56c8 100755 --- a/bin/test-browser.js +++ b/bin/test-browser.js @@ -6,6 +6,7 @@ const playwright = require('playwright'); const { identity, pickBy } = require('lodash'); var MochaSpecReporter = require('mocha').reporters.Spec; +const createMochaStatsCollector = require('mocha/lib/stats-collector'); var devserver = require('./dev-server.js'); @@ -59,20 +60,30 @@ const qs = { testUrl += '?'; testUrl += new URLSearchParams(pickBy(qs, identity)); +class ArrayMap extends Map { + get(key) { + if (!this.has(key)) { + this.set(key, []); + } + return super.get(key); + } +} + class RemoteRunner { constructor(browser) { this.browser = browser; - this.handlers = {}; + this.handlers = new ArrayMap(); + this.onceHandlers = new ArrayMap(); this.handleEvent = this.handleEvent.bind(this); + createMochaStatsCollector(this); } - on(name, handler) { - var handlers = this.handlers; + once(name, handler) { + this.onceHandlers.get(name).push(handler); + } - if (!handlers[name]) { - handlers[name] = []; - } - handlers[name].push(handler); + on(name, handler) { + this.handlers.get(name).push(handler); } async handleEvent(event) { @@ -83,9 +94,12 @@ class RemoteRunner { }; var obj = Object.assign({}, event.obj, additionalProps); - this.handlers[event.name].forEach(function (handler) { - handler(obj, event.err); - }); + const triggerHandler = handler => handler(obj, event.err); + + this.onceHandlers.get(event.name).forEach(triggerHandler); + this.onceHandlers.delete(event.name); + + this.handlers.get(event.name).forEach(triggerHandler); switch (event.name) { case 'fail': this.handleFailed(); break; diff --git a/bin/test-node.sh b/bin/test-node.sh index 98a7887416..abffba2efb 100755 --- a/bin/test-node.sh +++ b/bin/test-node.sh @@ -37,7 +37,9 @@ fi if [ $PERF ]; then node tests/performance/index.js elif [ ! $COVERAGE ]; then + # --exit required to workaround #8839 ./node_modules/.bin/mocha \ + --exit \ $BAIL_OPT \ --timeout "$TIMEOUT" \ --require=./tests/integration/node.setup.js \ @@ -45,9 +47,11 @@ elif [ ! $COVERAGE ]; then --grep="$GREP" \ $TESTS_PATH else + # --exit required to workaround #8839 ./node_modules/.bin/istanbul cover \ --no-default-excludes -x 'tests/**' -x 'node_modules/**' \ ./node_modules/mocha/bin/_mocha -- \ + --exit \ $BAIL_OPT \ --timeout "$TIMEOUT" \ --require=./tests/integration/node.setup.js \ diff --git a/package.json b/package.json index 0517a97535..2b9662fcc4 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "build-modules": "node bin/build-modules.js", "test-unit": "mocha tests/unit", "test-node": "./bin/test-node.sh", - "test-component": "mocha tests/component", + "test-component": "mocha --exit tests/component # --exit for #8839", "test-fuzzy": "TYPE=fuzzy npm run test", "test-browser": "npm run build-test && node ./bin/test-browser.js", "test-memleak": "mocha -gc tests/memleak", @@ -90,7 +90,7 @@ "marky": "1.2.0", "median": "0.0.2", "mkdirp": "0.5.1", - "mocha": "3.5.0", + "mocha": "10.2.0", "mockery": "2.1.0", "ncp": "2.0.0", "playwright": "1.36.1",