From 8f801a9337304c521bf1ae125debe87405865fbf Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 14 Feb 2024 01:22:11 +0100 Subject: [PATCH] test: fix clone() test for latest node version MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- build-requirements.js | 4 ++-- package.json | 1 + pnpm-lock.yaml | 3 +++ tests/utils/Utils.test.ts | 13 ++++++++----- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/build-requirements.js b/build-requirements.js index e950b741..f73e3e89 100644 --- a/build-requirements.js +++ b/build-requirements.js @@ -1,5 +1,5 @@ import chalk from 'chalk' -import semVer from 'semver' +import { satisfies } from 'semver' import packageJson from './package.json' assert { type: 'json' } import { version, exit } from 'node:process' @@ -8,7 +8,7 @@ import { version, exit } from 'node:process' */ export const checkNodeVersion = () => { const enginesNodeVersion = packageJson.engines.node - if (semVer.satisfies(version, enginesNodeVersion) === false) { + if (satisfies(version, enginesNodeVersion) === false) { console.error( chalk.red( `Required node version ${enginesNodeVersion} not satisfied with current version ${version}` diff --git a/package.json b/package.json index 06e68b49..83f51b67 100644 --- a/package.json +++ b/package.json @@ -122,6 +122,7 @@ "@mikro-orm/cli": "^6.1.3", "@release-it/bumper": "^6.0.1", "@types/node": "^20.11.17", + "@types/semver": "^7.5.7", "@types/tar": "^6.1.11", "@types/ws": "^8.5.10", "@typescript-eslint/eslint-plugin": "^7.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3ef7bf3c..893a782f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -96,6 +96,9 @@ devDependencies: '@types/node': specifier: ^20.11.17 version: 20.11.17 + '@types/semver': + specifier: ^7.5.7 + version: 7.5.7 '@types/tar': specifier: ^6.1.11 version: 6.1.11 diff --git a/tests/utils/Utils.test.ts b/tests/utils/Utils.test.ts index 3622d8ae..0ed7d6b6 100644 --- a/tests/utils/Utils.test.ts +++ b/tests/utils/Utils.test.ts @@ -1,7 +1,9 @@ +import { version } from 'node:process' import { describe, it } from 'node:test' import { hoursToMilliseconds, hoursToSeconds } from 'date-fns' import { expect } from 'expect' +import { satisfies } from 'semver' import { Constants } from '../../src/utils/Constants.js' import { @@ -341,9 +343,10 @@ await describe('Utils test suite', async () => { const date = new Date() expect(clone(date)).toStrictEqual(date) expect(clone(date) === date).toBe(false) - // The URL object seems to have not enumerable properties - const url = new URL('https://domain.tld') - expect(clone(url)).toStrictEqual({}) + if (satisfies(version, '>=21.0.0')) { + const url = new URL('https://domain.tld') + expect(() => clone(url)).toThrowError(new Error('Cannot clone object of unsupported type.')) + } const map = new Map([['1', '2']]) expect(clone(map)).toStrictEqual(map) expect(clone(map) === map).toBe(false) @@ -351,9 +354,9 @@ await describe('Utils test suite', async () => { expect(clone(set)).toStrictEqual(set) expect(clone(set) === set).toBe(false) const weakMap = new WeakMap([[{ 1: 1 }, { 2: 2 }]]) - expect(() => clone(weakMap)).toThrow(new Error('# could not be cloned.')) + expect(() => clone(weakMap)).toThrowError(new Error('# could not be cloned.')) const weakSet = new WeakSet([{ 1: 1 }, { 2: 2 }]) - expect(() => clone(weakSet)).toThrow(new Error('# could not be cloned.')) + expect(() => clone(weakSet)).toThrowError(new Error('# could not be cloned.')) }) await it('Verify hasOwnProp()', () => { -- 2.34.1