Skip to content

Commit

Permalink
Use Node 22 LTS and update tests to handle the new Navigation API (#519)
Browse files Browse the repository at this point in the history
* Use Node 22 LTS locally

* Drop Node 16 and add Node 22 in the builds

* Handle Navigator API (Node 21+)

* Handle logic in older Node versions
  • Loading branch information
fatso83 authored Dec 9, 2024
1 parent 656733c commit 4516b5a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:

strategy:
matrix:
node-version: [16, 18, 20]
node-version: [18, 20, 22]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nodejs 20.16.0
nodejs 20.9.0
18 changes: 17 additions & 1 deletion integration-test/fake-clock-integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -114,6 +121,15 @@ describe("globally configured browser objects", function () {
delete global.navigator;
delete global.requestAnimationFrame;
delete global.cancelAnimationFrame;

// restore
if (originalNavigatorDescriptor) {
Object.defineProperty(
global,
"navigator",
originalNavigatorDescriptor,
);
}
}

it("correctly instantiates and tears down", function () {
Expand Down

0 comments on commit 4516b5a

Please sign in to comment.