From 9e9f890db16effd18558bb751d4a2cb08ef6350d Mon Sep 17 00:00:00 2001 From: Carl-Erik Kopseng Date: Mon, 9 Dec 2024 15:51:08 +0100 Subject: [PATCH 1/4] Use Node 22 LTS locally --- .tool-versions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.tool-versions b/.tool-versions index c2bc75a..42738c5 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -nodejs 20.16.0 +nodejs 22.12.0 From fea39ca7d7e028a117e7cdec92e9eb665e9619c6 Mon Sep 17 00:00:00 2001 From: Carl-Erik Kopseng Date: Mon, 9 Dec 2024 15:52:45 +0100 Subject: [PATCH 2/4] Drop Node 16 and add Node 22 in the builds --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f270a83..be7bfad 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -129,7 +129,7 @@ jobs: strategy: matrix: - node-version: [16, 18, 20] + node-version: [18, 20, 22] steps: - uses: actions/checkout@v3 From e21896f5e15111d49ba59a74c12eb182f02ba55e Mon Sep 17 00:00:00 2001 From: Carl-Erik Kopseng Date: Mon, 9 Dec 2024 16:08:13 +0100 Subject: [PATCH 3/4] Handle Navigator API (Node 21+) --- integration-test/fake-clock-integration-test.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/integration-test/fake-clock-integration-test.js b/integration-test/fake-clock-integration-test.js index cebfeea..8e66779 100644 --- a/integration-test/fake-clock-integration-test.js +++ b/integration-test/fake-clock-integration-test.js @@ -59,7 +59,7 @@ describe("withGlobal", function () { }); describe("globally configured browser objects", function () { - let withGlobal, originalDescriptors; + let withGlobal, originalDescriptors, originalNavigatorDescriptor; // We use a set up function instead of beforeEach to avoid Mocha's check leaks detector function setUpGlobal() { @@ -69,6 +69,11 @@ describe("globally configured browser objects", function () { ); const window = dom.window; + originalNavigatorDescriptor = Object.getOwnPropertyDescriptor( + global, + "navigator", + ); + function makeMutable(descriptor) { descriptor.configurable = true; } @@ -88,6 +93,8 @@ describe("globally configured browser objects", function () { global.window = window; global.document = window.document; + // navigator is a getter, so we need to remove it, as assigning does not work + delete global.navigator; global.navigator = window.navigator; global.requestAnimationFrame = function (callback) { return setTimeout(callback, 0); @@ -114,6 +121,9 @@ describe("globally configured browser objects", function () { delete global.navigator; delete global.requestAnimationFrame; delete global.cancelAnimationFrame; + + // restore + Object.defineProperty(global, "navigator", originalNavigatorDescriptor); } it("correctly instantiates and tears down", function () { From 6e19fc1964bff74e167fa4969e2a1a464cfbb4f7 Mon Sep 17 00:00:00 2001 From: Carl-Erik Kopseng Date: Mon, 9 Dec 2024 16:11:43 +0100 Subject: [PATCH 4/4] Handle logic in older Node versions --- .tool-versions | 2 +- integration-test/fake-clock-integration-test.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.tool-versions b/.tool-versions index 42738c5..c2ca3d3 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -nodejs 22.12.0 +nodejs 20.9.0 diff --git a/integration-test/fake-clock-integration-test.js b/integration-test/fake-clock-integration-test.js index 8e66779..c4e28cc 100644 --- a/integration-test/fake-clock-integration-test.js +++ b/integration-test/fake-clock-integration-test.js @@ -123,7 +123,13 @@ describe("globally configured browser objects", function () { delete global.cancelAnimationFrame; // restore - Object.defineProperty(global, "navigator", originalNavigatorDescriptor); + if (originalNavigatorDescriptor) { + Object.defineProperty( + global, + "navigator", + originalNavigatorDescriptor, + ); + } } it("correctly instantiates and tears down", function () {