From 9e69599cafc860fb7e62905b8130dbd4539f9719 Mon Sep 17 00:00:00 2001 From: Robert Kieffer Date: Wed, 7 Aug 2024 09:20:17 -1000 Subject: [PATCH] chore: fix TS lint errors in #786 (#788) --- src/test/v4.test.ts | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/test/v4.test.ts b/src/test/v4.test.ts index 602aa782..b46ddd67 100644 --- a/src/test/v4.test.ts +++ b/src/test/v4.test.ts @@ -1,7 +1,7 @@ import * as assert from 'assert'; -import test, { describe, mock } from 'node:test'; -import v4 from '../v4.js'; +import test, { describe } from 'node:test'; import native from '../native.js'; +import v4 from '../v4.js'; const randomBytesFixture = Uint8Array.of( 0x10, @@ -49,22 +49,38 @@ describe('v4', () => { assert.ok(id1 !== id2); }); - test('should uses native randomUUID() if no option is passed', () => { - mock.method(native, 'randomUUID'); + test('should uses native randomUUID() if no option is passed', async () => { + // TODO: `mock` is not supported until node@18, so we feature-detect it + // here. Once node@16 drops off our support matrix, we can just + // static-import it normally + const mock = (await import('node:test')).default.mock; + if (!mock) { + return; + } - assert.equal((native.randomUUID as any).mock.callCount(), 0); + const mockRandomUUID = mock.method(native, 'randomUUID'); + + assert.equal(mockRandomUUID.mock.callCount(), 0); v4(); - assert.equal((native.randomUUID as any).mock.callCount(), 1); + assert.equal(mockRandomUUID.mock.callCount(), 1); mock.restoreAll(); }); - test('should not use native randomUUID() if an option is passed', () => { - mock.method(native, 'randomUUID'); + test('should not use native randomUUID() if an option is passed', async () => { + // TODO: `mock` is not supported until node@18, so we feature-detect it + // here. Once node@16 drops off our support matrix, we can just + // static-import it normally + const mock = (await import('node:test')).default.mock; + if (!mock) { + return; + } + + const mockRandomUUID = mock.method(native, 'randomUUID'); - assert.equal((native.randomUUID as any).mock.callCount(), 0); + assert.equal(mockRandomUUID.mock.callCount(), 0); v4({}); - assert.equal((native.randomUUID as any).mock.callCount(), 0); + assert.equal(mockRandomUUID.mock.callCount(), 0); mock.restoreAll(); });