prefer type-only imports in testing utilities
This commit is contained in:
parent
e7015d4f8e
commit
b013649a41
8 changed files with 27 additions and 25 deletions
|
|
@ -3,11 +3,11 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import * as Redis from 'ioredis';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { GodOfTimeService } from './GodOfTimeService.js';
|
||||
import { MockInternalEventService } from './MockInternalEventService.js';
|
||||
import { MockRedis } from './MockRedis.js';
|
||||
import type * as Redis from 'ioredis';
|
||||
import type { QuantumKVOpts } from '@/misc/QuantumKVCache.js';
|
||||
import type { RedisKVCacheOpts, RedisSingleCacheOpts, MemoryCacheOpts } from '@/misc/cache.js';
|
||||
import type { TimeService } from '@/global/TimeService.js';
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import * as Redis from 'ioredis';
|
||||
import { Redis as RedisConstructor } from 'ioredis';
|
||||
import type * as Redis from 'ioredis';
|
||||
|
||||
export type RedisKey = Redis.RedisKey;
|
||||
export type RedisString = Buffer | string;
|
||||
|
|
@ -14,7 +15,7 @@ export type RedisCallback<T = unknown> = Redis.Callback<T>;
|
|||
export type Ok = 'OK';
|
||||
export const ok = 'OK' as const;
|
||||
|
||||
export type FakeRedis = Redis.Redis;
|
||||
export type FakeRedis = RedisConstructor;
|
||||
export interface FakeRedisConstructor {
|
||||
new (): FakeRedis;
|
||||
}
|
||||
|
|
@ -25,7 +26,7 @@ export interface FakeRedisConstructor {
|
|||
export const FakeRedis: FakeRedisConstructor = createFakeRedis();
|
||||
|
||||
function createFakeRedis(): FakeRedisConstructor {
|
||||
class FakeRedis implements Partial<Redis.Redis> {
|
||||
class FakeRedis implements Partial<RedisConstructor> {
|
||||
async connect(callback?: RedisCallback<void>): Promise<void> {
|
||||
// no-op
|
||||
callback?.(null);
|
||||
|
|
@ -71,8 +72,8 @@ function createFakeRedis(): FakeRedisConstructor {
|
|||
}
|
||||
}
|
||||
|
||||
const fakeProto = FakeRedis.prototype as Partial<Redis.Redis>;
|
||||
const redisProto = Redis.Redis.prototype as Partial<Redis.Redis>;
|
||||
const fakeProto = FakeRedis.prototype as Partial<RedisConstructor>;
|
||||
const redisProto = RedisConstructor.prototype as Partial<RedisConstructor>;
|
||||
|
||||
// Override all methods and accessors from Redis
|
||||
for (const [key, property] of allProps(redisProto)) {
|
||||
|
|
@ -102,7 +103,7 @@ function createFakeRedis(): FakeRedisConstructor {
|
|||
|
||||
// test
|
||||
const test = new FakeRedis();
|
||||
if (!(test instanceof Redis.Redis)) {
|
||||
if (!(test instanceof RedisConstructor)) {
|
||||
throw new Error('failed to extend');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
*/
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { TimeService, Timer } from '@/global/TimeService.js';
|
||||
import { TimeService, type Timer } from '@/global/TimeService.js';
|
||||
import { addPatch, type DatePatch } from '@/misc/patch-date.js';
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { Injectable } from '@nestjs/common';
|
|||
import { FakeRedis, ok, type RedisString } from './FakeRedis.js';
|
||||
import type { RedisKey, RedisNumber, RedisValue, RedisCallback, Ok } from './FakeRedis.js';
|
||||
import type { ChainableCommander } from 'ioredis';
|
||||
import { TimeService, NativeTimeService } from '@/global/TimeService.js';
|
||||
import { NativeTimeService, type TimeService } from '@/global/TimeService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
export interface MockRedisConstructor {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue