From 53219993853c3cc37ad94272a2a6f995a2be95e7 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Fri, 29 Mar 2024 12:35:02 -0600 Subject: [PATCH] chore: better skipping of failing unit tests on NOde18+ --- ...ling_srv_records_for_mongos_discovery.prose.test.ts | 10 ++++------ test/unit/connection_string.spec.test.ts | 5 ++--- test/unit/sdam/monitor.test.ts | 5 ++--- test/unit/sdam/topology.test.ts | 10 ++++------ 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/test/unit/assorted/polling_srv_records_for_mongos_discovery.prose.test.ts b/test/unit/assorted/polling_srv_records_for_mongos_discovery.prose.test.ts index d60a81d034..8ec5cd8e29 100644 --- a/test/unit/assorted/polling_srv_records_for_mongos_discovery.prose.test.ts +++ b/test/unit/assorted/polling_srv_records_for_mongos_discovery.prose.test.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; import * as dns from 'dns'; import { once } from 'events'; -import { coerce } from 'semver'; +import { satisfies } from 'semver'; import * as sinon from 'sinon'; import { @@ -51,11 +51,9 @@ describe('Polling Srv Records for Mongos Discovery', () => { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const test = this.currentTest!; - const { major } = coerce(process.version); - test.skipReason = - major === 18 || major === 20 - ? 'TODO(NODE-5666): fix failing unit tests on Node18' - : undefined; + test.skipReason = satisfies(process.version, '>=18.0.0') + ? `TODO(NODE-5666): fix failing unit tests on Node18 (Running with Nodejs ${process.version})` + : undefined; if (test.skipReason) this.skip(); }); diff --git a/test/unit/connection_string.spec.test.ts b/test/unit/connection_string.spec.test.ts index cc4fbb7c69..a1b623dfeb 100644 --- a/test/unit/connection_string.spec.test.ts +++ b/test/unit/connection_string.spec.test.ts @@ -1,4 +1,4 @@ -import { coerce } from 'semver'; +import { satisfies } from 'semver'; import { loadSpecTests } from '../spec'; import { executeUriValidationTest } from '../tools/uri_spec_runner'; @@ -15,13 +15,12 @@ describe('Connection String spec tests', function () { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const test = this.currentTest!; - const { major } = coerce(process.version); const skippedTests = [ 'Invalid port (zero) with IP literal', 'Invalid port (zero) with hostname' ]; test.skipReason = - major === 20 && skippedTests.includes(test.title) + satisfies(process.version, '>=20.0.0') && skippedTests.includes(test.title) ? 'TODO(NODE-5666): fix failing unit tests on Node18' : undefined; diff --git a/test/unit/sdam/monitor.test.ts b/test/unit/sdam/monitor.test.ts index 3c6e02a134..c1bd8dc33c 100644 --- a/test/unit/sdam/monitor.test.ts +++ b/test/unit/sdam/monitor.test.ts @@ -1,7 +1,7 @@ import * as net from 'node:net'; import { expect } from 'chai'; -import { coerce } from 'semver'; +import { satisfies } from 'semver'; import * as sinon from 'sinon'; import { setTimeout } from 'timers'; @@ -49,7 +49,6 @@ describe('monitoring', function () { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const test = this.currentTest!; - const { major } = coerce(process.version); const failingTests = [ 'should connect and issue an initial server check', 'should ignore attempts to connect when not already closed', @@ -58,7 +57,7 @@ describe('monitoring', function () { 'should upgrade to hello from legacy hello when initial handshake contains helloOk' ]; test.skipReason = - (major === 18 || major === 20) && failingTests.includes(test.title) + satisfies(process.version, '>=18.0.0') && failingTests.includes(test.title) ? 'TODO(NODE-5666): fix failing unit tests on Node18' : undefined; diff --git a/test/unit/sdam/topology.test.ts b/test/unit/sdam/topology.test.ts index c6511d27c4..e4a34417d5 100644 --- a/test/unit/sdam/topology.test.ts +++ b/test/unit/sdam/topology.test.ts @@ -2,7 +2,7 @@ import { expect } from 'chai'; import { once } from 'events'; import * as net from 'net'; import { type AddressInfo } from 'net'; -import { coerce, type SemVer } from 'semver'; +import { satisfies } from 'semver'; import * as sinon from 'sinon'; import { clearTimeout } from 'timers'; @@ -284,11 +284,9 @@ describe('Topology (unit)', function () { it('should encounter a server selection timeout on garbled server responses', function () { const test = this.test; - const { major } = coerce(process.version) as SemVer; - test.skipReason = - major === 18 || major === 20 - ? 'TODO(NODE-5666): fix failing unit tests on Node18' - : undefined; + test.skipReason = satisfies(process.version, '>=18.0.0') + ? 'TODO(NODE-5666): fix failing unit tests on Node18' + : undefined; if (test.skipReason) this.skip();