diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 6c5b05a6..09b784c0 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -45,7 +45,7 @@ jobs: node-version: ${{ matrix.node-version }} - name: Install Dependencies - run: npm i + run: npm i -g npminstall && npminstall - name: Continuous Integration run: npm run ci diff --git a/.gitignore b/.gitignore index e226e38f..13fa0f64 100644 --- a/.gitignore +++ b/.gitignore @@ -117,4 +117,6 @@ dist .tern-port .idea +.DS_Store run +!test/ctx_register.js diff --git a/DEVELOPER.md b/DEVELOPER.md index ca0294d1..c020db8e 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -8,31 +8,30 @@ ```bash # 启动本地依赖服务 -$ docker-compose up -d +docker-compose up -d # 关闭本地依赖服务 -$ docker-compose down +docker-compose down ``` > 手动初始化依赖服务参见[文档](./docs/setup.md) - ## 本地开发 ### 安装依赖 ```bash -$ npm install +npm install ``` ### 开发运行 ```bash # 初始化数据库 -$ MYSQL_DATABASE=cnpmcore npm run prepare-database +MYSQL_DATABASE=cnpmcore npm run prepare-database # 启动 Web 服务 -$ npm run dev +npm run dev # 访问 curl -v http://127.0.0.1:7001 @@ -41,22 +40,9 @@ curl -v http://127.0.0.1:7001 ### 单元测试 ```bash -$ npm run test +npm run test ``` -编写单测规范: - -- assert 断言库必须使用 require 引入 - -```ts -import assert = require('assert'); -``` - -> CAUTION: don't use `import assert from 'assert'` -> Just use old style import assert = require('assert') for assert module. This is limitation. -> See https://github.com/power-assert-js/espower-typescript#caution-dont-use-import-assert-from-assert - - ## 项目结构 ``` @@ -80,29 +66,32 @@ app ``` common: + - util:全局工具类 - adapter:外部服务调用 core: + - entity:核心模型,实现业务行为 - event:异步事件定义,以及消费,串联业务 - service:核心业务 - util:服务 core 内部,不对外暴露 repository: + - model:ORM 模型,数据定义 - XXXRepository: 仓储接口,存储、查询过程 port: -- controller:HTTP controller +- controller:HTTP controller ## Controller 开发指南 目前只支持 HTTP 协议的 Controller,代码在 `app/port/controller` 目录下。 基于类继承的模式来实现,类关系大致如下: -``` +```txt +----------------------+ +----------------------+ +---------------+ | PackageController.ts | | PackageTagController | | XxxController | +---------------+------+ +---+------------------+ +--+------------+ @@ -130,15 +119,15 @@ port: 例如会封装 PackageEntity、PackageVersionEntity 等查询方法。 ```ts - // try to get package entity, throw NotFoundError when package not exists - private async getPackageEntity(scope: string, name: string) { - const packageEntity = await this.packageRepository.findPackage(scope, name); - if (!packageEntity) { - const fullname = getFullname(scope, name); - throw new NotFoundError(`${fullname} not found`); - } - return packageEntity; +// try to get package entity, throw NotFoundError when package not exists +private async getPackageEntity(scope: string, name: string) { + const packageEntity = await this.packageRepository.findPackage(scope, name); + if (!packageEntity) { + const fullname = getFullname(scope, name); + throw new NotFoundError(`${fullname} not found`); } + return packageEntity; +} ``` ### 请求合法性校验三部曲 diff --git a/app/common/FileUtil.ts b/app/common/FileUtil.ts index d7d4704e..48523161 100644 --- a/app/common/FileUtil.ts +++ b/app/common/FileUtil.ts @@ -4,7 +4,7 @@ import { setTimeout } from 'timers/promises'; import path from 'path'; import url from 'url'; import { randomBytes } from 'crypto'; -import { EggContextHttpClient } from 'egg'; +import { EggContextHttpClient, HttpClientResponse } from 'egg'; import dayjs from './dayjs'; export async function createTempfile(dataDir: string, filename: string) { @@ -37,9 +37,13 @@ export async function downloadToTempfile(httpclient: EggContextHttpClient, } throw lastError; } - +export interface Tempfile { + tmpfile: string; + headers: HttpClientResponse['res']['headers']; + timing: HttpClientResponse['res']['timing']; +} async function _downloadToTempfile(httpclient: EggContextHttpClient, - dataDir: string, url: string, ignoreDownloadStatuses?: number[]) { + dataDir: string, url: string, ignoreDownloadStatuses?: number[]): Promise { const tmpfile = await createTempfile(dataDir, url); const writeStream = createWriteStream(tmpfile); try { @@ -50,7 +54,7 @@ async function _downloadToTempfile(httpclient: EggContextHttpClient, writeStream, timing: true, followRedirect: true, - }); + }) as HttpClientResponse; if (status === 404 || (ignoreDownloadStatuses && ignoreDownloadStatuses.includes(status))) { const err = new Error(`Not found, status(${status})`); err.name = 'DownloadNotFoundError'; diff --git a/app/common/adapter/CacheAdapter.ts b/app/common/adapter/CacheAdapter.ts index 43aa950c..a92297c6 100644 --- a/app/common/adapter/CacheAdapter.ts +++ b/app/common/adapter/CacheAdapter.ts @@ -1,5 +1,5 @@ import { - ContextProto, + SingletonProto, AccessLevel, Inject, } from '@eggjs/tegg'; @@ -7,7 +7,7 @@ import { Redis } from 'ioredis'; const ONE_DAY = 3600 * 24; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class CacheAdapter { diff --git a/app/common/adapter/NFSAdapter.ts b/app/common/adapter/NFSAdapter.ts index 1d5dc4e4..c1de0303 100644 --- a/app/common/adapter/NFSAdapter.ts +++ b/app/common/adapter/NFSAdapter.ts @@ -1,6 +1,6 @@ import { Readable } from 'stream'; import { - ContextProto, + SingletonProto, AccessLevel, Inject, } from '@eggjs/tegg'; @@ -12,7 +12,7 @@ import { IncomingHttpHeaders } from 'http'; const INSTANCE_NAME = 'nfsAdapter'; -@ContextProto({ +@SingletonProto({ name: INSTANCE_NAME, accessLevel: AccessLevel.PUBLIC, }) diff --git a/app/common/adapter/NPMRegistry.ts b/app/common/adapter/NPMRegistry.ts index 7c60bb60..8a9786f5 100644 --- a/app/common/adapter/NPMRegistry.ts +++ b/app/common/adapter/NPMRegistry.ts @@ -8,11 +8,16 @@ import { EggLogger, EggContextHttpClient, EggAppConfig, + HttpClientRequestOptions, + HttpClientResponse, } from 'egg'; -import { HttpMethod } from 'urllib/src/Request'; + +type HttpMethod = HttpClientRequestOptions['method']; const INSTANCE_NAME = 'npmRegistry'; +export type RegistryResponse = { method: HttpMethod } & HttpClientResponse; + @ContextProto({ name: INSTANCE_NAME, accessLevel: AccessLevel.PUBLIC, @@ -35,7 +40,7 @@ export class NPMRegistry { this.registryHost = registryHost; } - public async getFullManifests(fullname: string, retries = 3) { + public async getFullManifests(fullname: string, retries = 3): Promise { // set query t=timestamp, make sure CDN cache disable // cache=0 is sync worker request flag const url = `${this.registry}/${encodeURIComponent(fullname)}?t=${Date.now()}&cache=0`; @@ -60,7 +65,7 @@ export class NPMRegistry { } // app.put('/:name/sync', sync.sync); - public async createSyncTask(fullname: string) { + public async createSyncTask(fullname: string): Promise { const url = `${this.registry}/${encodeURIComponent(fullname)}/sync?sync_upstream=true&nodeps=true`; // { // ok: true, @@ -70,18 +75,18 @@ export class NPMRegistry { } // app.get('/:name/sync/log/:id', sync.getSyncLog); - public async getSyncTask(fullname: string, id: string, offset: number) { + public async getSyncTask(fullname: string, id: string, offset: number): Promise { const url = `${this.registry}/${encodeURIComponent(fullname)}/sync/log/${id}?offset=${offset}`; // { ok: true, syncDone: syncDone, log: log } return await this.request('GET', url); } - public async getDownloadRanges(registry: string, fullname: string, start: string, end: string) { + public async getDownloadRanges(registry: string, fullname: string, start: string, end: string): Promise { const url = `${registry}/downloads/range/${start}:${end}/${encodeURIComponent(fullname)}`; return await this.request('GET', url); } - private async request(method: HttpMethod, url: string, params?: object, options?: object) { + private async request(method: HttpMethod, url: string, params?: object, options?: object): Promise { const res = await this.httpclient.request(url, { method, data: params, @@ -91,11 +96,10 @@ export class NPMRegistry { followRedirect: true, gzip: true, ...options, - }); + }) as HttpClientResponse; this.logger.info('[NPMRegistry:request] %s %s, status: %s', method, url, res.status); return { method, - url, ...res, }; } diff --git a/app/common/adapter/changesStream/CnpmcoreChangesStream.ts b/app/common/adapter/changesStream/CnpmcoreChangesStream.ts index abca92e5..f4a913f7 100644 --- a/app/common/adapter/changesStream/CnpmcoreChangesStream.ts +++ b/app/common/adapter/changesStream/CnpmcoreChangesStream.ts @@ -1,10 +1,10 @@ -import { ContextProto } from '@eggjs/tegg'; +import { SingletonProto } from '@eggjs/tegg'; import { RegistryType } from '../../../common/enum/Registry'; import { Registry } from '../../../core/entity/Registry'; import { E500 } from 'egg-errors'; import { AbstractChangeStream, RegistryChangesStream } from './AbstractChangesStream'; -@ContextProto() +@SingletonProto() @RegistryChangesStream(RegistryType.Cnpmcore) export class CnpmcoreChangesStream extends AbstractChangeStream { diff --git a/app/common/adapter/changesStream/CnpmjsorgChangesStream.ts b/app/common/adapter/changesStream/CnpmjsorgChangesStream.ts index 18943b44..ac253353 100644 --- a/app/common/adapter/changesStream/CnpmjsorgChangesStream.ts +++ b/app/common/adapter/changesStream/CnpmjsorgChangesStream.ts @@ -1,4 +1,4 @@ -import { ContextProto } from '@eggjs/tegg'; +import { SingletonProto } from '@eggjs/tegg'; import { RegistryType } from '../../../common/enum/Registry'; import { Registry } from '../../../core/entity/Registry'; import { E500 } from 'egg-errors'; @@ -6,7 +6,7 @@ import { AbstractChangeStream, RegistryChangesStream } from './AbstractChangesSt const MAX_LIMIT = 10000; -@ContextProto() +@SingletonProto() @RegistryChangesStream(RegistryType.Cnpmjsorg) export class CnpmjsorgChangesStream extends AbstractChangeStream { diff --git a/app/common/adapter/changesStream/NpmChangesStream.ts b/app/common/adapter/changesStream/NpmChangesStream.ts index 179c4b27..04231b74 100644 --- a/app/common/adapter/changesStream/NpmChangesStream.ts +++ b/app/common/adapter/changesStream/NpmChangesStream.ts @@ -1,10 +1,10 @@ -import { ContextProto } from '@eggjs/tegg'; +import { SingletonProto } from '@eggjs/tegg'; import { E500 } from 'egg-errors'; import { RegistryType } from '../../../common/enum/Registry'; import { Registry } from '../../../core/entity/Registry'; import { AbstractChangeStream, ChangesStreamChange, RegistryChangesStream } from './AbstractChangesStream'; -@ContextProto() +@SingletonProto() @RegistryChangesStream(RegistryType.Npm) export class NpmChangesStream extends AbstractChangeStream { diff --git a/app/core/service/BinarySyncerService.ts b/app/core/service/BinarySyncerService.ts index 814907a2..48ad8ce3 100644 --- a/app/core/service/BinarySyncerService.ts +++ b/app/core/service/BinarySyncerService.ts @@ -1,7 +1,7 @@ import { rm } from 'fs/promises'; import { AccessLevel, - ContextProto, + SingletonProto, Inject, } from '@eggjs/tegg'; import { @@ -50,7 +50,7 @@ function isoNow() { return new Date().toISOString(); } -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class BinarySyncerService extends AbstractService { diff --git a/app/core/service/BugVersionService.ts b/app/core/service/BugVersionService.ts index d98fad1b..74b2e8e0 100644 --- a/app/core/service/BugVersionService.ts +++ b/app/core/service/BugVersionService.ts @@ -1,4 +1,4 @@ -import { AccessLevel, ContextProto, Inject } from '@eggjs/tegg'; +import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; import { EggLogger } from 'egg'; import pMap from 'p-map'; import { BugVersion } from '../entity/BugVersion'; @@ -7,7 +7,7 @@ import { DistRepository } from '../../repository/DistRepository'; import { getScopeAndName } from '../../common/PackageUtil'; import { CacheService } from './CacheService'; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class BugVersionService { diff --git a/app/core/service/CacheService.ts b/app/core/service/CacheService.ts index 5056aa64..053b8575 100644 --- a/app/core/service/CacheService.ts +++ b/app/core/service/CacheService.ts @@ -1,6 +1,6 @@ import { AccessLevel, - ContextProto, + SingletonProto, Inject, } from '@eggjs/tegg'; import { CacheAdapter } from '../../common/adapter/CacheAdapter'; @@ -30,7 +30,7 @@ type TotalData = { }; const TOTAL_DATA_KEY = '__TOTAL_DATA__'; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class CacheService extends AbstractService { diff --git a/app/core/service/ChangesStreamService.ts b/app/core/service/ChangesStreamService.ts index b951ed61..68046ce7 100644 --- a/app/core/service/ChangesStreamService.ts +++ b/app/core/service/ChangesStreamService.ts @@ -2,7 +2,7 @@ import os from 'os'; import { setTimeout } from 'timers/promises'; import { AccessLevel, - ContextProto, + SingletonProto, EggObjectFactory, Inject, } from '@eggjs/tegg'; @@ -21,7 +21,7 @@ import { getScopeAndName } from '../../common/PackageUtil'; import { ScopeManagerService } from './ScopeManagerService'; import { PackageRepository } from '../../repository/PackageRepository'; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class ChangesStreamService extends AbstractService { diff --git a/app/core/service/CreateHookTriggerService.ts b/app/core/service/CreateHookTriggerService.ts index cc1b687f..6762d0c0 100644 --- a/app/core/service/CreateHookTriggerService.ts +++ b/app/core/service/CreateHookTriggerService.ts @@ -1,4 +1,4 @@ -import { AccessLevel, ContextProto, Inject } from '@eggjs/tegg'; +import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; import { AbstractService } from '../../common/AbstractService'; import { HookType } from '../../common/enum/Hook'; import { TaskState } from '../../common/enum/Task'; @@ -12,7 +12,7 @@ import { TaskService } from './TaskService'; import { isoNow } from '../../common/LogUtil'; import { getScopeAndName } from '../../common/PackageUtil'; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class CreateHookTriggerService extends AbstractService { diff --git a/app/core/service/HookManageService.ts b/app/core/service/HookManageService.ts index ba2248e0..80262bbf 100644 --- a/app/core/service/HookManageService.ts +++ b/app/core/service/HookManageService.ts @@ -1,4 +1,4 @@ -import { AccessLevel, ContextProto, Inject } from '@eggjs/tegg'; +import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; import { Hook } from '../entity/Hook'; import { HookType } from '../../common/enum/Hook'; import { @@ -28,7 +28,7 @@ export interface DeleteHookCommand { hookId: string; } -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class HookManageService { diff --git a/app/core/service/HookTriggerService.ts b/app/core/service/HookTriggerService.ts index 60fd1b96..c6d88571 100644 --- a/app/core/service/HookTriggerService.ts +++ b/app/core/service/HookTriggerService.ts @@ -1,4 +1,4 @@ -import { AccessLevel, ContextProto, Inject } from '@eggjs/tegg'; +import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; import { TriggerHookTask } from '../entity/Task'; import { HookEvent } from '../entity/HookEvent'; import { HookRepository } from '../../repository/HookRepository'; @@ -12,7 +12,7 @@ import { TaskState } from '../../common/enum/Task'; import { TaskService } from './TaskService'; import { getScopeAndName } from '../../common/PackageUtil'; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class HookTriggerService { diff --git a/app/core/service/PackageManagerService.ts b/app/core/service/PackageManagerService.ts index 363ba9f6..29e20c97 100644 --- a/app/core/service/PackageManagerService.ts +++ b/app/core/service/PackageManagerService.ts @@ -1,7 +1,7 @@ import { stat } from 'fs/promises'; import { AccessLevel, - ContextProto, + SingletonProto, EventBus, Inject, } from '@eggjs/tegg'; @@ -67,7 +67,7 @@ const TOTAL = '@@TOTAL@@'; const SCOPE_TOTAL_PREFIX = '@@SCOPE@@:'; const DESCRIPTION_LIMIT = 1024 * 10; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class PackageManagerService extends AbstractService { diff --git a/app/core/service/PackageSyncerService.ts b/app/core/service/PackageSyncerService.ts index 991d4d5d..8ad19f3e 100644 --- a/app/core/service/PackageSyncerService.ts +++ b/app/core/service/PackageSyncerService.ts @@ -1,7 +1,7 @@ import os from 'os'; import { AccessLevel, - ContextProto, + SingletonProto, Inject, } from '@eggjs/tegg'; import { Pointcut } from '@eggjs/tegg/aop'; @@ -39,7 +39,7 @@ function isoNow() { export class RegistryNotMatchError extends BadRequestError { } -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class PackageSyncerService extends AbstractService { diff --git a/app/core/service/RegistryManagerService.ts b/app/core/service/RegistryManagerService.ts index bb8d2b5a..3003fae0 100644 --- a/app/core/service/RegistryManagerService.ts +++ b/app/core/service/RegistryManagerService.ts @@ -1,6 +1,6 @@ import { AccessLevel, - ContextProto, + SingletonProto, Inject, } from '@eggjs/tegg'; import { E400, NotFoundError } from 'egg-errors'; @@ -28,7 +28,7 @@ export interface StartSyncCmd { operatorId?: string; } -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class RegistryManagerService extends AbstractService { diff --git a/app/core/service/ScopeManagerService.ts b/app/core/service/ScopeManagerService.ts index 80cec6d9..35d009ed 100644 --- a/app/core/service/ScopeManagerService.ts +++ b/app/core/service/ScopeManagerService.ts @@ -1,6 +1,6 @@ import { AccessLevel, - ContextProto, + SingletonProto, Inject, } from '@eggjs/tegg'; import { ScopeRepository } from '../../repository/ScopeRepository'; @@ -24,7 +24,7 @@ export interface RemoveScopeByRegistryIdCmd { registryId: string; operatorId?: string; } -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class ScopeManagerService extends AbstractService { diff --git a/app/core/service/TaskService.ts b/app/core/service/TaskService.ts index d066c198..2082ee6f 100644 --- a/app/core/service/TaskService.ts +++ b/app/core/service/TaskService.ts @@ -1,6 +1,6 @@ import { AccessLevel, - ContextProto, + SingletonProto, Inject, } from '@eggjs/tegg'; import { NFSAdapter } from '../../common/adapter/NFSAdapter'; @@ -10,7 +10,7 @@ import { TaskRepository } from '../../repository/TaskRepository'; import { Task } from '../entity/Task'; import { QueueAdapter } from '../../common/typing'; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class TaskService extends AbstractService { diff --git a/app/core/service/UserService.ts b/app/core/service/UserService.ts index 89aa3276..cdbd48b8 100644 --- a/app/core/service/UserService.ts +++ b/app/core/service/UserService.ts @@ -1,7 +1,7 @@ import crypto from 'crypto'; import { AccessLevel, - ContextProto, + SingletonProto, Inject, } from '@eggjs/tegg'; import { NotFoundError, ForbiddenError } from 'egg-errors'; @@ -31,7 +31,7 @@ type CreateTokenOptions = { cidrWhitelist?: string[]; }; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class UserService extends AbstractService { diff --git a/app/infra/NFSClientAdapter.ts b/app/infra/NFSClientAdapter.ts index 92036bff..9b8517cc 100644 --- a/app/infra/NFSClientAdapter.ts +++ b/app/infra/NFSClientAdapter.ts @@ -1,13 +1,12 @@ import { - SingletonProto, AccessLevel, - Inject, EggObjectLifecycle, + InitTypeQualifier, + Inject, + ObjectInitType, + SingletonProto, } from '@eggjs/tegg'; -import { - EggLogger, - EggAppConfig, -} from 'egg'; +import { EggAppConfig, EggLogger } from 'egg'; import FSClient from 'fs-cnpm'; import { AppendResult, NFSClient, UploadOptions, UploadResult } from '../common/typing'; import { Readable } from 'stream'; @@ -18,6 +17,7 @@ import { Readable } from 'stream'; }) export class NFSClientAdapter implements EggObjectLifecycle, NFSClient { @Inject() + @InitTypeQualifier(ObjectInitType.SINGLETON) private logger: EggLogger; @Inject() diff --git a/app/infra/QueueAdapter.ts b/app/infra/QueueAdapter.ts index cad513e9..869e6302 100644 --- a/app/infra/QueueAdapter.ts +++ b/app/infra/QueueAdapter.ts @@ -1,7 +1,7 @@ import { AccessLevel, Inject, - ContextProto, + SingletonProto, } from '@eggjs/tegg'; import { Redis } from 'ioredis'; import { QueueAdapter } from '../common/typing'; @@ -9,7 +9,7 @@ import { QueueAdapter } from '../common/typing'; /** * Use sort set to keep queue in order and keep same value only insert once */ -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, name: 'queueAdapter', }) diff --git a/app/repository/BinaryRepository.ts b/app/repository/BinaryRepository.ts index 094a1f43..5a539ab2 100644 --- a/app/repository/BinaryRepository.ts +++ b/app/repository/BinaryRepository.ts @@ -1,10 +1,10 @@ -import { AccessLevel, ContextProto, Inject } from '@eggjs/tegg'; +import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; import { ModelConvertor } from './util/ModelConvertor'; import type { Binary as BinaryModel } from './model/Binary'; import { Binary as BinaryEntity } from '../core/entity/Binary'; import { AbstractRepository } from './AbstractRepository'; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class BinaryRepository extends AbstractRepository { diff --git a/app/repository/ChangeRepository.ts b/app/repository/ChangeRepository.ts index b9cbf1bc..950ffcf6 100644 --- a/app/repository/ChangeRepository.ts +++ b/app/repository/ChangeRepository.ts @@ -1,10 +1,10 @@ -import { AccessLevel, ContextProto, Inject } from '@eggjs/tegg'; +import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; import { ModelConvertor } from './util/ModelConvertor'; import type { Change as ChangeModel } from './model/Change'; import { Change as ChangeEntity } from '../core/entity/Change'; import { AbstractRepository } from './AbstractRepository'; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class ChangeRepository extends AbstractRepository { diff --git a/app/repository/DistRepository.ts b/app/repository/DistRepository.ts index cc37c1c1..f4037ae6 100644 --- a/app/repository/DistRepository.ts +++ b/app/repository/DistRepository.ts @@ -1,9 +1,9 @@ -import { AccessLevel, ContextProto, Inject } from '@eggjs/tegg'; +import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; import { NFSAdapter } from '../common/adapter/NFSAdapter'; import { PackageRepository } from './PackageRepository'; import { Dist } from '../core/entity/Dist'; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class DistRepository { diff --git a/app/repository/HookRepository.ts b/app/repository/HookRepository.ts index a8228fdb..1d6b2453 100644 --- a/app/repository/HookRepository.ts +++ b/app/repository/HookRepository.ts @@ -1,4 +1,4 @@ -import { AccessLevel, ContextProto, Inject } from '@eggjs/tegg'; +import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; import { Hook } from '../core/entity/Hook'; import type { Hook as HookModel } from './model/Hook'; import { ModelConvertor } from './util/ModelConvertor'; @@ -10,7 +10,7 @@ export interface UpdateHookCommand { secret: string; } -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class HookRepository { diff --git a/app/repository/PackageRepository.ts b/app/repository/PackageRepository.ts index 6fb829d2..de9ff97f 100644 --- a/app/repository/PackageRepository.ts +++ b/app/repository/PackageRepository.ts @@ -1,4 +1,4 @@ -import { AccessLevel, ContextProto, Inject } from '@eggjs/tegg'; +import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; import type { Package as PackageModel } from './model/Package'; import { Package as PackageEntity } from '../core/entity/Package'; import { ModelConvertor } from './util/ModelConvertor'; @@ -15,7 +15,7 @@ import type { User as UserModel } from './model/User'; import { User as UserEntity } from '../core/entity/User'; import { AbstractRepository } from './AbstractRepository'; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class PackageRepository extends AbstractRepository { diff --git a/app/repository/PackageVersionBlockRepository.ts b/app/repository/PackageVersionBlockRepository.ts index 05a9b6f7..5359f3e9 100644 --- a/app/repository/PackageVersionBlockRepository.ts +++ b/app/repository/PackageVersionBlockRepository.ts @@ -1,10 +1,10 @@ -import { AccessLevel, ContextProto, Inject } from '@eggjs/tegg'; +import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; import { ModelConvertor } from './util/ModelConvertor'; import type { PackageVersionBlock as PackageVersionBlockModel } from './model/PackageVersionBlock'; import { PackageVersionBlock as PackageVersionBlockEntity } from '../core/entity/PackageVersionBlock'; import { AbstractRepository } from './AbstractRepository'; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class PackageVersionBlockRepository extends AbstractRepository { diff --git a/app/repository/PackageVersionDownloadRepository.ts b/app/repository/PackageVersionDownloadRepository.ts index 35e33513..c6553679 100644 --- a/app/repository/PackageVersionDownloadRepository.ts +++ b/app/repository/PackageVersionDownloadRepository.ts @@ -1,8 +1,8 @@ -import { AccessLevel, ContextProto, Inject } from '@eggjs/tegg'; +import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; import { AbstractRepository } from './AbstractRepository'; import type { PackageVersionDownload as PackageVersionDownloadModel } from './model/PackageVersionDownload'; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class PackageVersionDownloadRepository extends AbstractRepository { diff --git a/app/repository/RegistryRepository.ts b/app/repository/RegistryRepository.ts index 7aef2f33..41889bbf 100644 --- a/app/repository/RegistryRepository.ts +++ b/app/repository/RegistryRepository.ts @@ -1,11 +1,11 @@ -import { AccessLevel, ContextProto, Inject } from '@eggjs/tegg'; +import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; import { ModelConvertor } from './util/ModelConvertor'; import { Registry, Registry as RegistryEntity } from '../core/entity/Registry'; import { AbstractRepository } from './AbstractRepository'; import type { Registry as RegistryModel } from './model/Registry'; import { EntityUtil, PageOptions, PageResult } from '../core/util/EntityUtil'; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class RegistryRepository extends AbstractRepository { diff --git a/app/repository/ScopeRepository.ts b/app/repository/ScopeRepository.ts index ea512433..8e9fbfa4 100644 --- a/app/repository/ScopeRepository.ts +++ b/app/repository/ScopeRepository.ts @@ -1,11 +1,11 @@ -import { AccessLevel, ContextProto, Inject } from '@eggjs/tegg'; +import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; import { ModelConvertor } from './util/ModelConvertor'; import { AbstractRepository } from './AbstractRepository'; import { Scope as ScopeModel } from './model/Scope'; import { Scope } from '../core/entity/Scope'; import { EntityUtil, PageOptions, PageResult } from '../core/util/EntityUtil'; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class ScopeRepository extends AbstractRepository { diff --git a/app/repository/TaskRepository.ts b/app/repository/TaskRepository.ts index 07119fb3..17cb3e1b 100644 --- a/app/repository/TaskRepository.ts +++ b/app/repository/TaskRepository.ts @@ -1,5 +1,5 @@ import assert from 'assert'; -import { AccessLevel, ContextProto, Inject } from '@eggjs/tegg'; +import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; import { ModelConvertor } from './util/ModelConvertor'; import type { Task as TaskModel } from './model/Task'; import type { HistoryTask as HistoryTaskModel } from './model/HistoryTask'; @@ -7,7 +7,7 @@ import { Task as TaskEntity, TaskUpdateCondition } from '../core/entity/Task'; import { AbstractRepository } from './AbstractRepository'; import { TaskType, TaskState } from '../../app/common/enum/Task'; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class TaskRepository extends AbstractRepository { diff --git a/app/repository/UserRepository.ts b/app/repository/UserRepository.ts index 3c0b84f3..1c6fab13 100644 --- a/app/repository/UserRepository.ts +++ b/app/repository/UserRepository.ts @@ -1,4 +1,4 @@ -import { AccessLevel, ContextProto, Inject } from '@eggjs/tegg'; +import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; import { ModelConvertor } from './util/ModelConvertor'; import type { User as UserModel } from './model/User'; import type { Token as TokenModel } from './model/Token'; @@ -6,7 +6,7 @@ import { User as UserEntity } from '../core/entity/User'; import { Token as TokenEntity } from '../core/entity/Token'; import { AbstractRepository } from './AbstractRepository'; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class UserRepository extends AbstractRepository { diff --git a/app/repository/model/Binary.ts b/app/repository/model/Binary.ts index 547b253a..b389ac76 100644 --- a/app/repository/model/Binary.ts +++ b/app/repository/model/Binary.ts @@ -1,4 +1,4 @@ -import { Attribute, Model } from '@eggjs/tegg-orm-decorator'; +import { Attribute, Model } from '@eggjs/tegg/orm'; import { DataTypes, Bone } from 'leoric'; @Model() diff --git a/app/repository/model/Change.ts b/app/repository/model/Change.ts index 431c2201..61ef8272 100644 --- a/app/repository/model/Change.ts +++ b/app/repository/model/Change.ts @@ -1,4 +1,4 @@ -import { Attribute, Model } from '@eggjs/tegg-orm-decorator'; +import { Attribute, Model } from '@eggjs/tegg/orm'; import { DataTypes, Bone } from 'leoric'; @Model() diff --git a/app/repository/model/Dist.ts b/app/repository/model/Dist.ts index 9c178e0e..ea769bbd 100644 --- a/app/repository/model/Dist.ts +++ b/app/repository/model/Dist.ts @@ -1,4 +1,4 @@ -import { Attribute, Model } from '@eggjs/tegg-orm-decorator'; +import { Attribute, Model } from '@eggjs/tegg/orm'; import { DataTypes, Bone } from 'leoric'; @Model() diff --git a/app/repository/model/HistoryTask.ts b/app/repository/model/HistoryTask.ts index f8804ab8..88fb4561 100644 --- a/app/repository/model/HistoryTask.ts +++ b/app/repository/model/HistoryTask.ts @@ -1,4 +1,4 @@ -import { Attribute, Model } from '@eggjs/tegg-orm-decorator'; +import { Attribute, Model } from '@eggjs/tegg/orm'; import { DataTypes, Bone, LENGTH_VARIANTS } from 'leoric'; import { TaskState, TaskType } from '../../common/enum/Task'; diff --git a/app/repository/model/Hook.ts b/app/repository/model/Hook.ts index 083210f1..9edefeea 100644 --- a/app/repository/model/Hook.ts +++ b/app/repository/model/Hook.ts @@ -1,4 +1,4 @@ -import { Attribute, Model } from '@eggjs/tegg-orm-decorator'; +import { Attribute, Model } from '@eggjs/tegg/orm'; import { DataTypes, Bone } from 'leoric'; import { HookType } from '../../common/enum/Hook'; diff --git a/app/repository/model/Maintainer.ts b/app/repository/model/Maintainer.ts index 5828abb8..ca1a12b9 100644 --- a/app/repository/model/Maintainer.ts +++ b/app/repository/model/Maintainer.ts @@ -1,4 +1,4 @@ -import { Attribute, Model } from '@eggjs/tegg-orm-decorator'; +import { Attribute, Model } from '@eggjs/tegg/orm'; import { DataTypes, Bone } from 'leoric'; @Model() diff --git a/app/repository/model/Package.ts b/app/repository/model/Package.ts index 018fc65d..2c8d460d 100644 --- a/app/repository/model/Package.ts +++ b/app/repository/model/Package.ts @@ -1,4 +1,4 @@ -import { Attribute, Model } from '@eggjs/tegg-orm-decorator'; +import { Attribute, Model } from '@eggjs/tegg/orm'; import { DataTypes, Bone } from 'leoric'; import { EntityProperty } from '../util/EntityProperty'; diff --git a/app/repository/model/PackageDep.ts b/app/repository/model/PackageDep.ts index 42fb0192..5259620b 100644 --- a/app/repository/model/PackageDep.ts +++ b/app/repository/model/PackageDep.ts @@ -1,4 +1,4 @@ -import { Attribute, Model } from '@eggjs/tegg-orm-decorator'; +import { Attribute, Model } from '@eggjs/tegg/orm'; import { DataTypes, Bone } from 'leoric'; @Model() diff --git a/app/repository/model/PackageTag.ts b/app/repository/model/PackageTag.ts index 452a0d0d..91f15b8d 100644 --- a/app/repository/model/PackageTag.ts +++ b/app/repository/model/PackageTag.ts @@ -1,4 +1,4 @@ -import { Attribute, Model } from '@eggjs/tegg-orm-decorator'; +import { Attribute, Model } from '@eggjs/tegg/orm'; import { DataTypes, Bone } from 'leoric'; @Model() diff --git a/app/repository/model/PackageVersion.ts b/app/repository/model/PackageVersion.ts index ebc08333..2d69fb21 100644 --- a/app/repository/model/PackageVersion.ts +++ b/app/repository/model/PackageVersion.ts @@ -1,4 +1,4 @@ -import { Attribute, Model } from '@eggjs/tegg-orm-decorator'; +import { Attribute, Model } from '@eggjs/tegg/orm'; import { DataTypes, Bone } from 'leoric'; import { EntityProperty } from '../util/EntityProperty'; diff --git a/app/repository/model/PackageVersionBlock.ts b/app/repository/model/PackageVersionBlock.ts index daf7d094..bb1abe43 100644 --- a/app/repository/model/PackageVersionBlock.ts +++ b/app/repository/model/PackageVersionBlock.ts @@ -1,4 +1,4 @@ -import { Attribute, Model } from '@eggjs/tegg-orm-decorator'; +import { Attribute, Model } from '@eggjs/tegg/orm'; import { DataTypes, Bone, LENGTH_VARIANTS } from 'leoric'; @Model() diff --git a/app/repository/model/PackageVersionDownload.ts b/app/repository/model/PackageVersionDownload.ts index 66dfff49..d3471b5d 100644 --- a/app/repository/model/PackageVersionDownload.ts +++ b/app/repository/model/PackageVersionDownload.ts @@ -1,4 +1,4 @@ -import { Attribute, Model } from '@eggjs/tegg-orm-decorator'; +import { Attribute, Model } from '@eggjs/tegg/orm'; import { DataTypes, Bone } from 'leoric'; @Model() diff --git a/app/repository/model/PackageVersionManifest.ts b/app/repository/model/PackageVersionManifest.ts index ab3fdad2..368da07e 100644 --- a/app/repository/model/PackageVersionManifest.ts +++ b/app/repository/model/PackageVersionManifest.ts @@ -1,4 +1,4 @@ -import { Attribute, Model } from '@eggjs/tegg-orm-decorator'; +import { Attribute, Model } from '@eggjs/tegg/orm'; import { DataTypes, Bone } from 'leoric'; @Model() diff --git a/app/repository/model/Registry.ts b/app/repository/model/Registry.ts index c822163c..b5497ee5 100644 --- a/app/repository/model/Registry.ts +++ b/app/repository/model/Registry.ts @@ -1,4 +1,4 @@ -import { Attribute, Model } from '@eggjs/tegg-orm-decorator'; +import { Attribute, Model } from '@eggjs/tegg/orm'; import { RegistryType } from '../../common/enum/Registry'; import { DataTypes, Bone } from 'leoric'; diff --git a/app/repository/model/Scope.ts b/app/repository/model/Scope.ts index e40d1e17..b9370597 100644 --- a/app/repository/model/Scope.ts +++ b/app/repository/model/Scope.ts @@ -1,4 +1,4 @@ -import { Attribute, Model } from '@eggjs/tegg-orm-decorator'; +import { Attribute, Model } from '@eggjs/tegg/orm'; import { DataTypes, Bone } from 'leoric'; @Model() diff --git a/app/repository/model/Task.ts b/app/repository/model/Task.ts index 96d32827..01f2ef7f 100644 --- a/app/repository/model/Task.ts +++ b/app/repository/model/Task.ts @@ -1,4 +1,4 @@ -import { Attribute, Model } from '@eggjs/tegg-orm-decorator'; +import { Attribute, Model } from '@eggjs/tegg/orm'; import { DataTypes, Bone, LENGTH_VARIANTS } from 'leoric'; import { TaskState, TaskType } from '../../common/enum/Task'; diff --git a/app/repository/model/Token.ts b/app/repository/model/Token.ts index 04b3ecee..a5a62e82 100644 --- a/app/repository/model/Token.ts +++ b/app/repository/model/Token.ts @@ -1,4 +1,4 @@ -import { Attribute, Model } from '@eggjs/tegg-orm-decorator'; +import { Attribute, Model } from '@eggjs/tegg/orm'; import { DataTypes, Bone } from 'leoric'; @Model() diff --git a/app/repository/model/User.ts b/app/repository/model/User.ts index fa9a2d3c..f6058b82 100644 --- a/app/repository/model/User.ts +++ b/app/repository/model/User.ts @@ -1,4 +1,4 @@ -import { Attribute, Model } from '@eggjs/tegg-orm-decorator'; +import { Attribute, Model } from '@eggjs/tegg/orm'; import { DataTypes, Bone } from 'leoric'; @Model() diff --git a/app/repository/util/ModelConvertor.ts b/app/repository/util/ModelConvertor.ts index 0434c740..57835861 100644 --- a/app/repository/util/ModelConvertor.ts +++ b/app/repository/util/ModelConvertor.ts @@ -1,4 +1,4 @@ -import { ModelMetadataUtil } from '@eggjs/tegg-orm-decorator'; +import { ModelMetadataUtil } from '@eggjs/tegg/orm'; import { Bone } from 'leoric'; import { EggProtoImplClass } from '@eggjs/tegg'; import _ from 'lodash'; diff --git a/package.json b/package.json index 895ac968..8d2008fd 100644 --- a/package.json +++ b/package.json @@ -38,8 +38,8 @@ "contributor": "git-contributor", "dev": "DEBUG_LOCAL_SQL=true egg-bin dev", "debug": "egg-bin debug", - "lint": "eslint . --ext .ts", - "lint:fix": "eslint . --ext .ts --fix", + "lint": "eslint --cache --ext .ts .", + "lint:fix": "eslint --cache --ext .ts --fix .", "test": "npm run lint:fix && npm run test-local", "prepare-database": "rm -rf dist && ts-node test/prepare.ts", "test-local": "npm run prepare-database && egg-bin test --full-trace", @@ -65,22 +65,21 @@ "npm" ], "dependencies": { - "@eggjs/tegg": "^1.4.0", - "@eggjs/tegg-aop-plugin": "^1.3.2", - "@eggjs/tegg-config": "^1.0.0", - "@eggjs/tegg-controller-plugin": "^1.3.2", - "@eggjs/tegg-eventbus-plugin": "^1.3.2", - "@eggjs/tegg-orm-decorator": "^1.4.0", - "@eggjs/tegg-orm-plugin": "^2.1.0", - "@eggjs/tegg-plugin": "^1.3.2", - "@eggjs/tegg-schedule-plugin": "^2.2.0", + "@eggjs/tegg": "^3.2.1", + "@eggjs/tegg-aop-plugin": "^3.2.1", + "@eggjs/tegg-config": "^3.1.0", + "@eggjs/tegg-controller-plugin": "^3.2.1", + "@eggjs/tegg-eventbus-plugin": "^3.2.1", + "@eggjs/tegg-orm-plugin": "^3.2.1", + "@eggjs/tegg-plugin": "^3.2.1", + "@eggjs/tegg-schedule-plugin": "^3.2.1", "@eggjs/tsconfig": "^1.0.0", "@node-rs/crc32": "^1.2.2", "@sinclair/typebox": "^0.23.0", "base-x": "^3.0.9", "bson-objectid": "^2.0.1", "dayjs": "^1.10.7", - "egg": "^3.9.0", + "egg": "^3.9.2", "egg-cors": "^2.2.3", "egg-errors": "^2.3.0", "egg-redis": "^2.4.0", @@ -98,7 +97,6 @@ "semver": "^7.3.5", "ssri": "^8.0.1", "type-fest": "^2.5.3", - "urllib": "^3.3.0", "validate-npm-package-name": "^3.0.0" }, "devDependencies": { @@ -110,7 +108,7 @@ "egg-mock": "^5.0.1", "eslint": "^8.29.0", "eslint-config-egg": "^12.1.0", - "git-contributor": "^1.0.10", + "git-contributor": "2", "npm-cli-login": "^1.0.0", "ts-node": "^10.9.1", "typescript": "^4.9.4" diff --git a/test/cli/npm/install.test.ts b/test/cli/npm/install.test.ts index 2aa5ce14..5ede5e04 100644 --- a/test/cli/npm/install.test.ts +++ b/test/cli/npm/install.test.ts @@ -1,4 +1,4 @@ -import assert = require('assert'); +import assert from 'assert'; import path from 'path'; import { app } from 'egg-mock/bootstrap'; import coffee from 'coffee'; @@ -12,7 +12,7 @@ describe('test/cli/npm/install.test.ts', () => { let demoDir; let userconfig; let cacheDir; - before(done => { + before(async () => { cacheDir = TestUtil.mkdtemp(); fooPkgDir = TestUtil.getFixtures('@cnpm/foo'); demoDir = TestUtil.getFixtures('demo'); @@ -20,10 +20,12 @@ describe('test/cli/npm/install.test.ts', () => { TestUtil.rm(userconfig); TestUtil.rm(path.join(demoDir, 'node_modules')); - server = app.listen(0, () => { - registry = `http://localhost:${server.address().port}`; - console.log(`registry ${registry} ready`); - done(); + return new Promise(resolve => { + server = app.listen(0, () => { + registry = `http://localhost:${server.address().port}`; + console.log(`registry ${registry} ready`); + resolve(); + }); }); }); diff --git a/test/common/PackageUtil.test.ts b/test/common/PackageUtil.test.ts index d6dbfc5b..7b9b8b3f 100644 --- a/test/common/PackageUtil.test.ts +++ b/test/common/PackageUtil.test.ts @@ -1,4 +1,4 @@ -import assert = require('assert'); +import assert from 'assert'; import { formatTarball } from '../../app/common/PackageUtil'; describe('test/common/PackageUtil.test.ts', () => { diff --git a/test/common/UserUtil.test.ts b/test/common/UserUtil.test.ts index 60df3fb4..fa686461 100644 --- a/test/common/UserUtil.test.ts +++ b/test/common/UserUtil.test.ts @@ -1,4 +1,4 @@ -import assert = require('assert'); +import assert from 'assert'; import { randomToken, checkToken } from '../../app/common/UserUtil'; describe('test/common/UserUtil.test.ts', () => { diff --git a/test/common/adapter/BugVersionStore.test.ts b/test/common/adapter/BugVersionStore.test.ts index 1e35e759..8e16f581 100644 --- a/test/common/adapter/BugVersionStore.test.ts +++ b/test/common/adapter/BugVersionStore.test.ts @@ -1,4 +1,4 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; import { BugVersionStore } from '../../../app/common/adapter/BugVersionStore'; import { BugVersion } from '../../../app/core/entity/BugVersion'; diff --git a/test/common/adapter/CacheAdapter.test.ts b/test/common/adapter/CacheAdapter.test.ts index 9e65aad3..28b42505 100644 --- a/test/common/adapter/CacheAdapter.test.ts +++ b/test/common/adapter/CacheAdapter.test.ts @@ -1,14 +1,13 @@ -import assert = require('assert'); +import assert from 'assert'; import { setTimeout } from 'timers/promises'; import { app } from 'egg-mock/bootstrap'; -import { CacheAdapter } from '../../../app/common/adapter/CacheAdapter'; +import { CacheAdapter } from 'app/common/adapter/CacheAdapter'; describe('test/common/adapter/CacheAdapter.test.ts', () => { let cache: CacheAdapter; beforeEach(async () => { - const ctx = await app.mockModuleContext(); - cache = await ctx.getEggObject(CacheAdapter); + cache = await app.getEggObject(CacheAdapter); }); describe('lock(), unlock()', () => { diff --git a/test/common/adapter/NpmRegistry.test.ts b/test/common/adapter/NpmRegistry.test.ts index 3ab5878e..884afa0a 100644 --- a/test/common/adapter/NpmRegistry.test.ts +++ b/test/common/adapter/NpmRegistry.test.ts @@ -1,13 +1,12 @@ -import assert = require('assert'); +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; -import { NPMRegistry } from '../../../app/common/adapter/NPMRegistry'; +import { NPMRegistry } from 'app/common/adapter/NPMRegistry'; describe('test/common/adapter/CacheAdapter.test.ts', () => { let npmRegistry: NPMRegistry; beforeEach(async () => { - const ctx = await app.mockModuleContext(); - npmRegistry = await ctx.getEggObject(NPMRegistry); + npmRegistry = await app.getEggObject(NPMRegistry); mock(app.config.cnpmcore, 'registry', 'https://registry.npmjs.org'); }); diff --git a/test/common/adapter/binary/ApiBinary.test.ts b/test/common/adapter/binary/ApiBinary.test.ts index c7646ffe..279ebf9a 100644 --- a/test/common/adapter/binary/ApiBinary.test.ts +++ b/test/common/adapter/binary/ApiBinary.test.ts @@ -1,28 +1,17 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { ApiBinary } from 'app/common/adapter/binary/ApiBinary'; import binaries from 'config/binaries'; import { TestUtil } from 'test/TestUtil'; describe('test/common/adapter/binary/ApiBinary.test.ts', () => { - let ctx: Context; - - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('fetch()', () => { it('should fetch root: / work', async () => { app.mockHttpclient('https://cnpmjs.org/mirrors/apis/node/', 'GET', { data: await TestUtil.readFixturesFile('cnpmjs.org/mirrors/apis/node.json'), persist: false, }); - const binary = new ApiBinary(ctx.httpclient, ctx.logger, binaries.node, 'https://cnpmjs.org/mirrors/apis', 'node'); + const binary = new ApiBinary(app.httpclient, app.logger, binaries.node, 'https://cnpmjs.org/mirrors/apis', 'node'); const result = await binary.fetch('/'); assert(result); assert(result.items.length > 0); @@ -56,7 +45,7 @@ describe('test/common/adapter/binary/ApiBinary.test.ts', () => { data: await TestUtil.readFixturesFile('r.cnpmjs.org/-/binary/node/v16.13.1.json'), persist: false, }); - const binary = new ApiBinary(ctx.httpclient, ctx.logger, binaries.node, 'https://r.cnpmjs.org/-/binary', 'node'); + const binary = new ApiBinary(app.httpclient, app.logger, binaries.node, 'https://r.cnpmjs.org/-/binary', 'node'); const result = await binary.fetch('/v16.13.1/'); assert(result); assert(result.items.length > 0); diff --git a/test/common/adapter/binary/BucketBinary.test.ts b/test/common/adapter/binary/BucketBinary.test.ts index cb2da2b0..2d65dca1 100644 --- a/test/common/adapter/binary/BucketBinary.test.ts +++ b/test/common/adapter/binary/BucketBinary.test.ts @@ -1,28 +1,17 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { BucketBinary } from 'app/common/adapter/binary/BucketBinary'; import binaries from 'config/binaries'; import { TestUtil } from 'test/TestUtil'; describe('test/common/adapter/binary/BucketBinary.test.ts', () => { - let ctx: Context; - - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('fetch()', () => { it('should fetch root: / work', async () => { app.mockHttpclient('https://chromedriver.storage.googleapis.com/', 'GET', { data: await TestUtil.readFixturesFile('chromedriver.storage.googleapis.com/index.xml'), persist: false, }); - const binary = new BucketBinary(ctx.httpclient, ctx.logger, binaries.chromedriver, 'chromedriver'); + const binary = new BucketBinary(app.httpclient, app.logger, binaries.chromedriver, 'chromedriver'); const result = await binary.fetch('/'); assert(result); assert(result.items.length > 0); @@ -51,7 +40,7 @@ describe('test/common/adapter/binary/BucketBinary.test.ts', () => { data: await TestUtil.readFixturesFile('chromedriver.storage.googleapis.com/97.0.4692.71.xml'), persist: false, }); - const binary = new BucketBinary(ctx.httpclient, ctx.logger, binaries.chromedriver, 'chromedriver'); + const binary = new BucketBinary(app.httpclient, app.logger, binaries.chromedriver, 'chromedriver'); const result = await binary.fetch('/97.0.4692.71/'); assert(result); assert(result.items.length > 0); @@ -77,7 +66,7 @@ describe('test/common/adapter/binary/BucketBinary.test.ts', () => { persist: false, }); // https://selenium-release.storage.googleapis.com/?delimiter=/&prefix=2.43/ - const binary = new BucketBinary(ctx.httpclient, ctx.logger, binaries.selenium, 'selenium'); + const binary = new BucketBinary(app.httpclient, app.logger, binaries.selenium, 'selenium'); const result = await binary.fetch('/2.43/'); assert(result); assert(result.items.length > 0); @@ -91,7 +80,7 @@ describe('test/common/adapter/binary/BucketBinary.test.ts', () => { data: await TestUtil.readFixturesFile('node-inspector.s3.amazonaws.com/index.xml'), persist: false, }); - const binary = new BucketBinary(ctx.httpclient, ctx.logger, binaries['node-inspector'], 'node-inspector'); + const binary = new BucketBinary(app.httpclient, app.logger, binaries['node-inspector'], 'node-inspector'); const result = await binary.fetch('/'); assert(result); assert(result.items.length > 0); @@ -105,7 +94,7 @@ describe('test/common/adapter/binary/BucketBinary.test.ts', () => { data: await TestUtil.readFixturesFile('prisma-builds.s3-eu-west-1.amazonaws.com/index.xml'), persist: false, }); - const binary = new BucketBinary(ctx.httpclient, ctx.logger, binaries.prisma, 'prisma'); + const binary = new BucketBinary(app.httpclient, app.logger, binaries.prisma, 'prisma'); const result = await binary.fetch('/'); assert(result); assert(result.items.length > 0); diff --git a/test/common/adapter/binary/CypressBinary.test.ts b/test/common/adapter/binary/CypressBinary.test.ts index df25bdf8..180371e4 100644 --- a/test/common/adapter/binary/CypressBinary.test.ts +++ b/test/common/adapter/binary/CypressBinary.test.ts @@ -1,28 +1,17 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { CypressBinary } from 'app/common/adapter/binary/CypressBinary'; import binaries from 'config/binaries'; import { TestUtil } from 'test/TestUtil'; describe('test/common/adapter/binary/CypressBinary.test.ts', () => { - let ctx: Context; - - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('fetch()', () => { it('should fetch root: / work', async () => { app.mockHttpclient('https://registry.npmjs.com/cypress', 'GET', { data: await TestUtil.readFixturesFile('registry.npmjs.com/cypress.json'), persist: false, }); - const binary = new CypressBinary(ctx.httpclient, ctx.logger, binaries.cypress, 'cypress'); + const binary = new CypressBinary(app.httpclient, app.logger, binaries.cypress, 'cypress'); const result = await binary.fetch('/'); assert(result); assert(result.items.length > 0); @@ -51,7 +40,7 @@ describe('test/common/adapter/binary/CypressBinary.test.ts', () => { data: await TestUtil.readFixturesFile('registry.npmjs.com/cypress.json'), persist: false, }); - const binary = new CypressBinary(ctx.httpclient, ctx.logger, binaries.cypress, 'cypress'); + const binary = new CypressBinary(app.httpclient, app.logger, binaries.cypress, 'cypress'); let result = await binary.fetch('/4.0.0/'); assert(result); assert(result.items.length === 4); diff --git a/test/common/adapter/binary/ElectronBinary.test.ts b/test/common/adapter/binary/ElectronBinary.test.ts index 69796aeb..bf77d556 100644 --- a/test/common/adapter/binary/ElectronBinary.test.ts +++ b/test/common/adapter/binary/ElectronBinary.test.ts @@ -1,21 +1,10 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { ElectronBinary } from 'app/common/adapter/binary/ElectronBinary'; import { TestUtil } from 'test/TestUtil'; import binaries from 'config/binaries'; describe('test/common/adapter/binary/ElectronBinary.test.ts', () => { - let ctx: Context; - - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('fetch()', () => { it('should fetch root and subdir work', async () => { const response = await TestUtil.readJSONFile(TestUtil.getFixtures('electron-releases.json')); @@ -23,7 +12,7 @@ describe('test/common/adapter/binary/ElectronBinary.test.ts', () => { data: response, status: 200, }); - const binary = new ElectronBinary(ctx.httpclient, ctx.logger, binaries.electron, 'electron'); + const binary = new ElectronBinary(app.httpclient, app.logger, binaries.electron, 'electron'); let result = await binary.fetch('/'); assert(result); assert(result.items.length > 0); diff --git a/test/common/adapter/binary/GithubBinary.test.ts b/test/common/adapter/binary/GithubBinary.test.ts index 16425dce..6f1469c2 100644 --- a/test/common/adapter/binary/GithubBinary.test.ts +++ b/test/common/adapter/binary/GithubBinary.test.ts @@ -1,21 +1,10 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { GithubBinary } from 'app/common/adapter/binary/GithubBinary'; import { TestUtil } from 'test/TestUtil'; import binaries from 'config/binaries'; describe('test/common/adapter/binary/GithubBinary.test.ts', () => { - let ctx: Context; - - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('fetch()', () => { it('should fetch root and subdir work', async () => { const response = await TestUtil.readJSONFile(TestUtil.getFixtures('electron-releases.json')); @@ -23,7 +12,7 @@ describe('test/common/adapter/binary/GithubBinary.test.ts', () => { data: response, status: 200, }); - const binary = new GithubBinary(ctx.httpclient, ctx.logger, binaries.electron, 'electron'); + const binary = new GithubBinary(app.httpclient, app.logger, binaries.electron, 'electron'); let result = await binary.fetch('/'); assert(result); assert(result.items.length > 0); diff --git a/test/common/adapter/binary/ImageminBinary.test.ts b/test/common/adapter/binary/ImageminBinary.test.ts index 443efc90..040fc11f 100644 --- a/test/common/adapter/binary/ImageminBinary.test.ts +++ b/test/common/adapter/binary/ImageminBinary.test.ts @@ -1,26 +1,15 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { ImageminBinary } from 'app/common/adapter/binary/ImageminBinary'; import binaries from 'config/binaries'; import { TestUtil } from 'test/TestUtil'; describe('test/common/adapter/binary/ImageminBinary.test.ts', () => { - let ctx: Context; - - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - it('should fetch jpegtran-bin', async () => { app.mockHttpclient('https://registry.npmjs.com/jpegtran-bin', 'GET', { data: await TestUtil.readFixturesFile('registry.npmjs.com/jpegtran-bin.json'), }); - const binary = new ImageminBinary(ctx.httpclient, ctx.logger, binaries['jpegtran-bin'], 'jpegtran-bin'); + const binary = new ImageminBinary(app.httpclient, app.logger, binaries['jpegtran-bin'], 'jpegtran-bin'); let result = await binary.fetch('/'); assert(result); assert(result.items.length > 0); @@ -88,7 +77,7 @@ describe('test/common/adapter/binary/ImageminBinary.test.ts', () => { app.mockHttpclient('https://registry.npmjs.com/advpng-bin', 'GET', { data: await TestUtil.readFixturesFile('registry.npmjs.com/advpng-bin.json'), }); - const binary = new ImageminBinary(ctx.httpclient, ctx.logger, binaries['advpng-bin'], 'advpng-bin'); + const binary = new ImageminBinary(app.httpclient, app.logger, binaries['advpng-bin'], 'advpng-bin'); let result = await binary.fetch('/'); assert(result); assert(result.items.length > 0); @@ -141,7 +130,7 @@ describe('test/common/adapter/binary/ImageminBinary.test.ts', () => { app.mockHttpclient('https://registry.npmjs.com/mozjpeg', 'GET', { data: await TestUtil.readFixturesFile('registry.npmjs.com/mozjpeg.json'), }); - const binary = new ImageminBinary(ctx.httpclient, ctx.logger, binaries['mozjpeg-bin'], 'mozjpeg-bin'); + const binary = new ImageminBinary(app.httpclient, app.logger, binaries['mozjpeg-bin'], 'mozjpeg-bin'); let result = await binary.fetch('/'); assert(result); // console.log(result.items); @@ -205,7 +194,7 @@ describe('test/common/adapter/binary/ImageminBinary.test.ts', () => { app.mockHttpclient('https://registry.npmjs.com/gifsicle', 'GET', { data: await TestUtil.readFixturesFile('registry.npmjs.com/gifsicle.json'), }); - const binary = new ImageminBinary(ctx.httpclient, ctx.logger, binaries['gifsicle-bin'], 'gifsicle-bin'); + const binary = new ImageminBinary(app.httpclient, app.logger, binaries['gifsicle-bin'], 'gifsicle-bin'); const result = await binary.fetch('/'); assert(result); // console.log(result.items); @@ -234,7 +223,7 @@ describe('test/common/adapter/binary/ImageminBinary.test.ts', () => { app.mockHttpclient('https://registry.npmjs.com/optipng-bin', 'GET', { data: await TestUtil.readFixturesFile('registry.npmjs.com/optipng-bin.json'), }); - const binary = new ImageminBinary(ctx.httpclient, ctx.logger, binaries['optipng-bin'], 'optipng-bin'); + const binary = new ImageminBinary(app.httpclient, app.logger, binaries['optipng-bin'], 'optipng-bin'); const result = await binary.fetch('/'); assert(result); // console.log(result.items); @@ -263,7 +252,7 @@ describe('test/common/adapter/binary/ImageminBinary.test.ts', () => { app.mockHttpclient('https://registry.npmjs.com/zopflipng-bin', 'GET', { data: await TestUtil.readFixturesFile('registry.npmjs.com/zopflipng-bin.json'), }); - const binary = new ImageminBinary(ctx.httpclient, ctx.logger, binaries['zopflipng-bin'], 'zopflipng-bin'); + const binary = new ImageminBinary(app.httpclient, app.logger, binaries['zopflipng-bin'], 'zopflipng-bin'); const result = await binary.fetch('/'); assert(result); // console.log(result.items); @@ -292,7 +281,7 @@ describe('test/common/adapter/binary/ImageminBinary.test.ts', () => { app.mockHttpclient('https://registry.npmjs.com/jpegoptim-bin', 'GET', { data: await TestUtil.readFixturesFile('registry.npmjs.com/jpegoptim-bin.json'), }); - const binary = new ImageminBinary(ctx.httpclient, ctx.logger, binaries['jpegoptim-bin'], 'jpegoptim-bin'); + const binary = new ImageminBinary(app.httpclient, app.logger, binaries['jpegoptim-bin'], 'jpegoptim-bin'); const result = await binary.fetch('/'); assert(result); // console.log(result.items); @@ -321,7 +310,7 @@ describe('test/common/adapter/binary/ImageminBinary.test.ts', () => { app.mockHttpclient('https://registry.npmjs.com/guetzli', 'GET', { data: await TestUtil.readFixturesFile('registry.npmjs.com/guetzli.json'), }); - const binary = new ImageminBinary(ctx.httpclient, ctx.logger, binaries['guetzli-bin'], 'guetzli-bin'); + const binary = new ImageminBinary(app.httpclient, app.logger, binaries['guetzli-bin'], 'guetzli-bin'); const result = await binary.fetch('/'); assert(result); // console.log(result.items); diff --git a/test/common/adapter/binary/NodeBinary.test.ts b/test/common/adapter/binary/NodeBinary.test.ts index 25eec544..420435ec 100644 --- a/test/common/adapter/binary/NodeBinary.test.ts +++ b/test/common/adapter/binary/NodeBinary.test.ts @@ -1,27 +1,16 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { NodeBinary } from 'app/common/adapter/binary/NodeBinary'; import binaries from 'config/binaries'; import { TestUtil } from 'test/TestUtil'; describe('test/common/adapter/binary/NodeBinary.test.ts', () => { - let ctx: Context; - - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('fetch()', () => { it('should fetch root: / work', async () => { app.mockHttpclient('https://nodejs.org/dist/', 'GET', { data: await TestUtil.readFixturesFile('nodejs.org/site/index.html'), }); - const binary = new NodeBinary(ctx.httpclient, ctx.logger, binaries.node, 'node'); + const binary = new NodeBinary(app.httpclient, app.logger, binaries.node, 'node'); const result = await binary.fetch('/'); assert(result); assert(result.items.length > 0); @@ -54,7 +43,7 @@ describe('test/common/adapter/binary/NodeBinary.test.ts', () => { app.mockHttpclient('https://nodejs.org/dist/v16.13.1/', 'GET', { data: await TestUtil.readFixturesFile('nodejs.org/site/v16.13.1/index.html'), }); - const binary = new NodeBinary(ctx.httpclient, ctx.logger, binaries.node, 'node'); + const binary = new NodeBinary(app.httpclient, app.logger, binaries.node, 'node'); const result = await binary.fetch('/v16.13.1/'); assert(result); assert(result.items.length > 0); @@ -87,7 +76,7 @@ describe('test/common/adapter/binary/NodeBinary.test.ts', () => { app.mockHttpclient('https://nodejs.org/download/nightly/v14.0.0-nightly20200119b318926634/', 'GET', { data: await TestUtil.readFixturesFile('nodejs.org/download/nightly/v14.0.0-nightly20200119b318926634/index.html'), }); - const binary = new NodeBinary(ctx.httpclient, ctx.logger, binaries['node-nightly'], 'node-nightly'); + const binary = new NodeBinary(app.httpclient, app.logger, binaries['node-nightly'], 'node-nightly'); const result = await binary.fetch('/v14.0.0-nightly20200119b318926634/'); assert(result); assert(result.items.length > 0); @@ -129,7 +118,7 @@ describe('test/common/adapter/binary/NodeBinary.test.ts', () => { app.mockHttpclient('https://nodejs.org/download/nightly/v14.0.0-nightly20200204ee9e689df2/', 'GET', { data: await TestUtil.readFixturesFile('nodejs.org/download/nightly/v14.0.0-nightly20200204ee9e689df2/index.html'), }); - const binary = new NodeBinary(ctx.httpclient, ctx.logger, binaries['node-nightly'], 'node-nightly'); + const binary = new NodeBinary(app.httpclient, app.logger, binaries['node-nightly'], 'node-nightly'); const result = await binary.fetch('/v14.0.0-nightly20200204ee9e689df2/'); assert(result); assert(result.items.length > 0); @@ -184,7 +173,7 @@ describe('test/common/adapter/binary/NodeBinary.test.ts', () => { persist: false, }); - const binary = new NodeBinary(ctx.httpclient, ctx.logger, binaries.python, 'python'); + const binary = new NodeBinary(app.httpclient, app.logger, binaries.python, 'python'); let result = await binary.fetch('/'); assert(result); assert(result.items.length > 0); diff --git a/test/common/adapter/binary/NodePreGypBinary.test.ts b/test/common/adapter/binary/NodePreGypBinary.test.ts index 82f5b483..5ffa2274 100644 --- a/test/common/adapter/binary/NodePreGypBinary.test.ts +++ b/test/common/adapter/binary/NodePreGypBinary.test.ts @@ -1,21 +1,10 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { NodePreGypBinary } from 'app/common/adapter/binary/NodePreGypBinary'; import binaries from 'config/binaries'; import { TestUtil } from 'test/TestUtil'; describe('test/common/adapter/binary/NodePreGypBinary.test.ts', () => { - let ctx: Context; - - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('fetch()', () => { it('should fetch grpc', async () => { app.mockHttpclient('https://registry.npmjs.com/grpc', 'GET', { @@ -24,7 +13,7 @@ describe('test/common/adapter/binary/NodePreGypBinary.test.ts', () => { app.mockHttpclient('https://nodejs.org/dist/index.json', 'GET', { data: await TestUtil.readFixturesFile('nodejs.org/site/index.json'), }); - const binary = new NodePreGypBinary(ctx.httpclient, ctx.logger, binaries.grpc, 'grpc'); + const binary = new NodePreGypBinary(app.httpclient, app.logger, binaries.grpc, 'grpc'); let result = await binary.fetch('/'); assert(result); assert(result.items.length > 0); @@ -67,7 +56,7 @@ describe('test/common/adapter/binary/NodePreGypBinary.test.ts', () => { app.mockHttpclient('https://nodejs.org/dist/index.json', 'GET', { data: await TestUtil.readFixturesFile('nodejs.org/site/index.json'), }); - const binary = new NodePreGypBinary(ctx.httpclient, ctx.logger, binaries['grpc-tools'], 'grpc-tools'); + const binary = new NodePreGypBinary(app.httpclient, app.logger, binaries['grpc-tools'], 'grpc-tools'); let result = await binary.fetch('/'); assert(result); assert(result.items.length > 0); @@ -111,7 +100,7 @@ describe('test/common/adapter/binary/NodePreGypBinary.test.ts', () => { app.mockHttpclient('https://nodejs.org/dist/index.json', 'GET', { data: await TestUtil.readFixturesFile('nodejs.org/site/index.json'), }); - const binary = new NodePreGypBinary(ctx.httpclient, ctx.logger, binaries.nodegit, 'nodegit'); + const binary = new NodePreGypBinary(app.httpclient, app.logger, binaries.nodegit, 'nodegit'); const result = await binary.fetch('/'); assert(result); assert(result.items.length > 0); @@ -155,7 +144,7 @@ describe('test/common/adapter/binary/NodePreGypBinary.test.ts', () => { app.mockHttpclient('https://nodejs.org/dist/index.json', 'GET', { data: await TestUtil.readFixturesFile('nodejs.org/site/index.json'), }); - const binary = new NodePreGypBinary(ctx.httpclient, ctx.logger, binaries['skia-canvas'], 'skia-canvas'); + const binary = new NodePreGypBinary(app.httpclient, app.logger, binaries['skia-canvas'], 'skia-canvas'); let result = await binary.fetch('/'); assert(result); assert(result.items.length > 0); @@ -210,7 +199,7 @@ describe('test/common/adapter/binary/NodePreGypBinary.test.ts', () => { app.mockHttpclient('https://nodejs.org/dist/index.json', 'GET', { data: await TestUtil.readFixturesFile('nodejs.org/site/index.json'), }); - const binary = new NodePreGypBinary(ctx.httpclient, ctx.logger, binaries.wrtc, 'wrtc'); + const binary = new NodePreGypBinary(app.httpclient, app.logger, binaries.wrtc, 'wrtc'); let result = await binary.fetch('/'); assert(result); assert(result.items.length > 0); diff --git a/test/common/adapter/binary/NwjsBinary.test.ts b/test/common/adapter/binary/NwjsBinary.test.ts index e65f00c6..ae2d3035 100644 --- a/test/common/adapter/binary/NwjsBinary.test.ts +++ b/test/common/adapter/binary/NwjsBinary.test.ts @@ -1,28 +1,17 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { NwjsBinary } from 'app/common/adapter/binary/NwjsBinary'; import binaries from 'config/binaries'; import { TestUtil } from 'test/TestUtil'; describe('test/common/adapter/binary/NwjsBinary.test.ts', () => { - let ctx: Context; - - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('fetch()', () => { it('should fetch root: / work', async () => { app.mockHttpclient('https://dl.nwjs.io/', 'GET', { data: await TestUtil.readFixturesFile('dl.nwjs.io/index.html'), persist: false, }); - const binary = new NwjsBinary(ctx.httpclient, ctx.logger, binaries.nwjs, 'nwjs'); + const binary = new NwjsBinary(app.httpclient, app.logger, binaries.nwjs, 'nwjs'); const result = await binary.fetch('/'); assert(result); assert(result.items.length > 0); @@ -44,7 +33,7 @@ describe('test/common/adapter/binary/NwjsBinary.test.ts', () => { data: await TestUtil.readFixturesFile('nwjs2.s3.amazonaws.com/v0.59.0.xml'), persist: false, }); - const binary = new NwjsBinary(ctx.httpclient, ctx.logger, binaries.nwjs, 'nwjs'); + const binary = new NwjsBinary(app.httpclient, app.logger, binaries.nwjs, 'nwjs'); let result = await binary.fetch('/v0.59.0/'); assert(result); assert(result.items.length > 0); diff --git a/test/common/adapter/binary/PlaywrightBinary.test.ts b/test/common/adapter/binary/PlaywrightBinary.test.ts index 07f513ea..e513376c 100644 --- a/test/common/adapter/binary/PlaywrightBinary.test.ts +++ b/test/common/adapter/binary/PlaywrightBinary.test.ts @@ -1,21 +1,10 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { PlaywrightBinary } from 'app/common/adapter/binary/PlaywrightBinary'; import binaries from 'config/binaries'; import { TestUtil } from 'test/TestUtil'; describe('test/common/adapter/binary/PlaywrightBinary.test.ts', () => { - let ctx: Context; - - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('fetch()', () => { it('should fetch root: / work', async () => { app.mockHttpclient('https://registry.npmjs.com/playwright-core', 'GET', { @@ -29,7 +18,7 @@ describe('test/common/adapter/binary/PlaywrightBinary.test.ts', () => { }) .reply(200, await TestUtil.readFixturesFile('unpkg.com/playwright-core-browsers.json')) .persist(); - const binary = new PlaywrightBinary(ctx.httpclient, ctx.logger, binaries.playwright, 'playwright'); + const binary = new PlaywrightBinary(app.httpclient, app.logger, binaries.playwright, 'playwright'); const result = await binary.fetch('/'); assert(result); assert(result.items.length > 0); @@ -57,7 +46,7 @@ describe('test/common/adapter/binary/PlaywrightBinary.test.ts', () => { }) .reply(200, await TestUtil.readFixturesFile('unpkg.com/playwright-core-browsers.json')) .persist(); - const binary = new PlaywrightBinary(ctx.httpclient, ctx.logger, binaries.playwright, 'playwright'); + const binary = new PlaywrightBinary(app.httpclient, app.logger, binaries.playwright, 'playwright'); let result = await binary.fetch('/builds/'); assert(result); // console.log(result.items); diff --git a/test/common/adapter/binary/PuppeteerBinary.test.ts b/test/common/adapter/binary/PuppeteerBinary.test.ts index f89ca482..d8babebd 100644 --- a/test/common/adapter/binary/PuppeteerBinary.test.ts +++ b/test/common/adapter/binary/PuppeteerBinary.test.ts @@ -1,21 +1,10 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { PuppeteerBinary } from 'app/common/adapter/binary/PuppeteerBinary'; import binaries from 'config/binaries'; import { TestUtil } from 'test/TestUtil'; describe('test/common/adapter/binary/PuppeteerBinary.test.ts', () => { - let ctx: Context; - - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('fetch()', () => { it('should fetch work', async () => { app.mockHttpclient('https://registry.npmjs.com/puppeteer', 'GET', { @@ -30,7 +19,7 @@ describe('test/common/adapter/binary/PuppeteerBinary.test.ts', () => { data: '1055816', persist: false, }); - const binary = new PuppeteerBinary(ctx.httpclient, ctx.logger, binaries['chromium-browser-snapshots'], 'chromium-browser-snapshots'); + const binary = new PuppeteerBinary(app.httpclient, app.logger, binaries['chromium-browser-snapshots'], 'chromium-browser-snapshots'); let result = await binary.fetch('/'); assert(result); assert(result.items.length === 5); diff --git a/test/common/adapter/binary/SqlcipherBinary.test.ts b/test/common/adapter/binary/SqlcipherBinary.test.ts index 2ac7b0ee..afe2dfa7 100644 --- a/test/common/adapter/binary/SqlcipherBinary.test.ts +++ b/test/common/adapter/binary/SqlcipherBinary.test.ts @@ -1,28 +1,17 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { SqlcipherBinary } from 'app/common/adapter/binary/SqlcipherBinary'; import binaries from 'config/binaries'; import { TestUtil } from 'test/TestUtil'; describe('test/common/adapter/binary/SqlcipherBinary.test.ts', () => { - let ctx: Context; - - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('fetch()', () => { it('should fetch root: / work', async () => { app.mockHttpclient('https://registry.npmjs.com/@journeyapps/sqlcipher', 'GET', { data: await TestUtil.readFixturesFile('registry.npmjs.com/@journeyapps/sqlcipher.json'), persist: false, }); - const binary = new SqlcipherBinary(ctx.httpclient, ctx.logger, binaries['@journeyapps/sqlcipher'], '@journeyapps/sqlcipher'); + const binary = new SqlcipherBinary(app.httpclient, app.logger, binaries['@journeyapps/sqlcipher'], '@journeyapps/sqlcipher'); const result = await binary.fetch('/'); assert(result); assert(result.items.length > 0); @@ -52,7 +41,7 @@ describe('test/common/adapter/binary/SqlcipherBinary.test.ts', () => { data: await TestUtil.readFixturesFile('registry.npmjs.com/@journeyapps/sqlcipher.json'), persist: false, }); - const binary = new SqlcipherBinary(ctx.httpclient, ctx.logger, binaries['@journeyapps/sqlcipher'], '@journeyapps/sqlcipher'); + const binary = new SqlcipherBinary(app.httpclient, app.logger, binaries['@journeyapps/sqlcipher'], '@journeyapps/sqlcipher'); const result = await binary.fetch('/v5.3.1/'); assert(result); assert(result.items.length > 0); diff --git a/test/common/adapter/changesStream/CnpmcoreChangesStream.test.ts b/test/common/adapter/changesStream/CnpmcoreChangesStream.test.ts index 09a9b611..d84461e5 100644 --- a/test/common/adapter/changesStream/CnpmcoreChangesStream.test.ts +++ b/test/common/adapter/changesStream/CnpmcoreChangesStream.test.ts @@ -1,21 +1,18 @@ +import assert from 'assert'; +import { app } from 'egg-mock/bootstrap'; import { ChangesStreamChange } from 'app/common/adapter/changesStream/AbstractChangesStream'; import { CnpmcoreChangesStream } from 'app/common/adapter/changesStream/CnpmcoreChangesStream'; import { RegistryType } from 'app/common/enum/Registry'; import { Registry } from 'app/core/entity/Registry'; import { RegistryManagerService } from 'app/core/service/RegistryManagerService'; -import assert = require('assert'); -import { Context } from 'egg'; -import { app } from 'egg-mock/bootstrap'; describe('test/common/adapter/changesStream/CnpmcoreChangesStream.test.ts', () => { - let ctx: Context; let cnpmcoreChangesStream: CnpmcoreChangesStream; let registryManagerService: RegistryManagerService; let registry: Registry; beforeEach(async () => { - ctx = await app.mockModuleContext(); - cnpmcoreChangesStream = await ctx.getEggObject(CnpmcoreChangesStream); - registryManagerService = await ctx.getEggObject(RegistryManagerService); + cnpmcoreChangesStream = await app.getEggObject(CnpmcoreChangesStream); + registryManagerService = await app.getEggObject(RegistryManagerService); registry = await registryManagerService.createRegistry({ name: 'cnpmcore', changeStream: 'https://r.cnpmjs.org/_changes', diff --git a/test/common/adapter/changesStream/CnpmjsorgChangesStream.test.ts b/test/common/adapter/changesStream/CnpmjsorgChangesStream.test.ts index 6002edbb..1eca12f2 100644 --- a/test/common/adapter/changesStream/CnpmjsorgChangesStream.test.ts +++ b/test/common/adapter/changesStream/CnpmjsorgChangesStream.test.ts @@ -1,21 +1,18 @@ +import assert from 'assert'; +import { app } from 'egg-mock/bootstrap'; import { ChangesStreamChange } from 'app/common/adapter/changesStream/AbstractChangesStream'; import { CnpmjsorgChangesStream } from 'app/common/adapter/changesStream/CnpmjsorgChangesStream'; import { RegistryType } from 'app/common/enum/Registry'; import { Registry } from 'app/core/entity/Registry'; import { RegistryManagerService } from 'app/core/service/RegistryManagerService'; -import assert = require('assert'); -import { Context } from 'egg'; -import { app } from 'egg-mock/bootstrap'; describe('test/common/adapter/changesStream/CnpmjsorgChangesStream.test.ts', () => { - let ctx: Context; let cnpmjsorgChangesStream: CnpmjsorgChangesStream; let registryManagerService: RegistryManagerService; let registry: Registry; beforeEach(async () => { - ctx = await app.mockModuleContext(); - cnpmjsorgChangesStream = await ctx.getEggObject(CnpmjsorgChangesStream); - registryManagerService = await ctx.getEggObject(RegistryManagerService); + cnpmjsorgChangesStream = await app.getEggObject(CnpmjsorgChangesStream); + registryManagerService = await app.getEggObject(RegistryManagerService); registry = await registryManagerService.createRegistry({ name: 'cnpmcore', changeStream: 'https://r2.cnpmjs.org/_changes', @@ -31,7 +28,6 @@ describe('test/common/adapter/changesStream/CnpmjsorgChangesStream.test.ts', () const now = new Date().getTime(); assert(now - Number(since) < 10000); }); - }); describe('fetchChanges()', () => { diff --git a/test/common/adapter/changesStream/NpmChangesStream.test.ts b/test/common/adapter/changesStream/NpmChangesStream.test.ts index a5564bf5..3bab349b 100644 --- a/test/common/adapter/changesStream/NpmChangesStream.test.ts +++ b/test/common/adapter/changesStream/NpmChangesStream.test.ts @@ -1,22 +1,19 @@ import { Readable, Duplex } from 'node:stream'; +import assert from 'assert'; +import { app, mock } from 'egg-mock/bootstrap'; import { ChangesStreamChange } from 'app/common/adapter/changesStream/AbstractChangesStream'; import { NpmChangesStream } from 'app/common/adapter/changesStream/NpmChangesStream'; import { RegistryType } from 'app/common/enum/Registry'; import { Registry } from 'app/core/entity/Registry'; import { RegistryManagerService } from 'app/core/service/RegistryManagerService'; -import assert = require('assert'); -import { Context } from 'egg'; -import { app, mock } from 'egg-mock/bootstrap'; describe('test/common/adapter/changesStream/NpmChangesStream.test.ts', () => { - let ctx: Context; let npmChangesStream: NpmChangesStream; let registryManagerService: RegistryManagerService; let registry: Registry; beforeEach(async () => { - ctx = await app.mockModuleContext(); - npmChangesStream = await ctx.getEggObject(NpmChangesStream); - registryManagerService = await ctx.getEggObject(RegistryManagerService); + npmChangesStream = await app.getEggObject(NpmChangesStream); + registryManagerService = await app.getEggObject(RegistryManagerService); registry = await registryManagerService.createRegistry({ name: 'npm', changeStream: 'https://replicate.npmjs.com/_changes', @@ -53,7 +50,7 @@ describe('test/common/adapter/changesStream/NpmChangesStream.test.ts', () => { describe('fetchChanges()', () => { it('should work', async () => { - mock(ctx.httpclient, 'request', async () => { + mock(app.httpclient, 'request', async () => { return { res: Readable.from(` {"seq":2,"id":"backbone.websql.deferred","changes":[{"rev":"4-f5150b238ab62cd890211fb57fc9eca5"}],"deleted":true}, @@ -71,7 +68,7 @@ describe('test/common/adapter/changesStream/NpmChangesStream.test.ts', () => { it('should work for broken chunk', async () => { const rStream = Duplex.from(''); - mock(ctx.httpclient, 'request', async () => { + mock(app.httpclient, 'request', async () => { return { res: rStream, }; @@ -88,5 +85,4 @@ describe('test/common/adapter/changesStream/NpmChangesStream.test.ts', () => { assert(res.length === 1); }); }); - }); diff --git a/test/core/event/BugVersionFixHandler.test.ts b/test/core/event/BugVersionFixHandler.test.ts index 05661b24..5ade8d56 100644 --- a/test/core/event/BugVersionFixHandler.test.ts +++ b/test/core/event/BugVersionFixHandler.test.ts @@ -1,22 +1,19 @@ -import assert = require('assert'); +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; -import { BUG_VERSIONS } from '../../../app/common/constants'; -import { CacheService } from '../../../app/core/service/CacheService'; -import { BugVersionFixHandler } from '../../../app/core/event/BugVersionFixHandler'; -import { PackageManagerService } from '../../../app/core/service/PackageManagerService'; -import { BugVersion } from '../../../app/core/entity/BugVersion'; +import { BUG_VERSIONS } from 'app/common/constants'; +import { CacheService } from 'app/core/service/CacheService'; +import { BugVersionFixHandler } from 'app/core/event/BugVersionFixHandler'; +import { PackageManagerService } from 'app/core/service/PackageManagerService'; +import { BugVersion } from 'app/core/entity/BugVersion'; describe('test/core/event/BugVersionFixHandler.test.ts', () => { - let ctx: Context; let cacheService: CacheService; let packageManagerService: PackageManagerService; const fullnames: string[] = []; beforeEach(async () => { - ctx = await app.mockModuleContext(); - cacheService = await ctx.getEggObject(CacheService); - packageManagerService = await ctx.getEggObject(PackageManagerService); + cacheService = await app.getEggObject(CacheService); + packageManagerService = await app.getEggObject(PackageManagerService); mock(app.config.cnpmcore, 'allowPublishNonScopePackage', true); mock(cacheService, 'removeCache', async fullname => { fullnames.push(fullname); @@ -33,12 +30,8 @@ describe('test/core/event/BugVersionFixHandler.test.ts', () => { }); }); - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - it('should clean packages cache', async () => { - const bugVersionFixHandler = await ctx.getEggObject(BugVersionFixHandler); + const bugVersionFixHandler = await app.getEggObject(BugVersionFixHandler); await bugVersionFixHandler.handle(BUG_VERSIONS); assert.deepStrictEqual(fullnames, [ 'faker', diff --git a/test/core/event/StoreManifest.test.ts b/test/core/event/StoreManifest.test.ts index 2352545a..556c5f1a 100644 --- a/test/core/event/StoreManifest.test.ts +++ b/test/core/event/StoreManifest.test.ts @@ -1,21 +1,14 @@ -import assert = require('assert'); +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { TestUtil } from 'test/TestUtil'; import { getScopeAndName } from 'app/common/PackageUtil'; import { PackageRepository } from 'app/repository/PackageRepository'; describe('test/core/event/StoreManifest.test.ts', () => { - let ctx: Context; let packageRepository: PackageRepository; beforeEach(async () => { - ctx = await app.mockModuleContext(); - packageRepository = await ctx.getEggObject(PackageRepository); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); + packageRepository = await app.getEggObject(PackageRepository); }); describe('savePackageVersionManifest()', () => { diff --git a/test/core/service/BinarySyncerService/createTask.test.ts b/test/core/service/BinarySyncerService/createTask.test.ts index 50069eb8..b46a9a93 100644 --- a/test/core/service/BinarySyncerService/createTask.test.ts +++ b/test/core/service/BinarySyncerService/createTask.test.ts @@ -1,19 +1,12 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { BinarySyncerService } from 'app/core/service/BinarySyncerService'; describe('test/core/service/BinarySyncerService/createTask.test.ts', () => { - let ctx: Context; let binarySyncerService: BinarySyncerService; beforeEach(async () => { - ctx = await app.mockModuleContext(); - binarySyncerService = await ctx.getEggObject(BinarySyncerService); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); + binarySyncerService = await app.getEggObject(BinarySyncerService); }); describe('createTask()', () => { diff --git a/test/core/service/BinarySyncerService/executeTask.test.ts b/test/core/service/BinarySyncerService/executeTask.test.ts index 090a6f42..07a188f8 100644 --- a/test/core/service/BinarySyncerService/executeTask.test.ts +++ b/test/core/service/BinarySyncerService/executeTask.test.ts @@ -1,24 +1,17 @@ -import assert = require('assert'); +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; +import { TestUtil } from 'test/TestUtil'; import { BinarySyncerService } from 'app/core/service/BinarySyncerService'; import { Task as TaskModel } from 'app/repository/model/Task'; import { HistoryTask as HistoryTaskModel } from 'app/repository/model/HistoryTask'; -import { TestUtil } from 'test/TestUtil'; import { NodeBinary } from 'app/common/adapter/binary/NodeBinary'; import { ApiBinary } from 'app/common/adapter/binary/ApiBinary'; describe('test/core/service/BinarySyncerService/executeTask.test.ts', () => { - let ctx: Context; let binarySyncerService: BinarySyncerService; beforeEach(async () => { - ctx = await app.mockModuleContext(); - binarySyncerService = await ctx.getEggObject(BinarySyncerService); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); + binarySyncerService = await app.getEggObject(BinarySyncerService); }); describe('executeTask()', () => { diff --git a/test/core/service/BugVersionService/cleanBugVersionPackageCache.test.ts b/test/core/service/BugVersionService/cleanBugVersionPackageCache.test.ts index 92e3428b..6c8cb9d6 100644 --- a/test/core/service/BugVersionService/cleanBugVersionPackageCache.test.ts +++ b/test/core/service/BugVersionService/cleanBugVersionPackageCache.test.ts @@ -1,23 +1,20 @@ -import assert = require('assert'); +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; -import { TestUtil } from '../../../TestUtil'; -import { BugVersionService } from '../../../../app/core/service/BugVersionService'; -import { CacheService } from '../../../../app/core/service/CacheService'; -import { BugVersion } from '../../../../app/core/entity/BugVersion'; +import { TestUtil } from 'test/TestUtil'; +import { BugVersionService } from 'app/core/service/BugVersionService'; +import { CacheService } from 'app/core/service/CacheService'; +import { BugVersion } from 'app/core/entity/BugVersion'; describe('test/core/service/BugVersionService/cleanBugVersionPackageCache.test.ts', () => { - let ctx: Context; let bugVersionService: BugVersionService; let cacheService: CacheService; let bugVersion: BugVersion; let cleanPkgs: string[]; beforeEach(async () => { - ctx = await app.mockModuleContext(); cleanPkgs = []; - bugVersionService = await ctx.getEggObject(BugVersionService); - cacheService = await ctx.getEggObject(CacheService); + bugVersionService = await app.getEggObject(BugVersionService); + cacheService = await app.getEggObject(CacheService); bugVersion = new BugVersion({ faker: { '6.6.6': { @@ -46,7 +43,6 @@ describe('test/core/service/BugVersionService/cleanBugVersionPackageCache.test.t }); afterEach(async () => { - await app.destroyModuleContext(ctx); mock.restore(); await TestUtil.truncateDatabase(); }); diff --git a/test/core/service/BugVersionService/fixPackageBugVersion.test.ts b/test/core/service/BugVersionService/fixPackageBugVersion.test.ts index cd9d63d5..8e0e32d2 100644 --- a/test/core/service/BugVersionService/fixPackageBugVersion.test.ts +++ b/test/core/service/BugVersionService/fixPackageBugVersion.test.ts @@ -1,27 +1,24 @@ -import assert = require('assert'); +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; -import { TestUtil } from '../../../TestUtil'; -import { BugVersionService } from '../../../../app/core/service/BugVersionService'; -import { DistRepository } from '../../../../app/repository/DistRepository'; -import { PackageRepository } from '../../../../app/repository/PackageRepository'; -import { BugVersion } from '../../../../app/core/entity/BugVersion'; -import { Package } from '../../../../app/core/entity/Package'; -import { PackageVersion } from '../../../../app/core/entity/PackageVersion'; -import { Dist } from '../../../../app/core/entity/Dist'; +import { TestUtil } from 'test/TestUtil'; +import { BugVersionService } from 'app/core/service/BugVersionService'; +import { DistRepository } from 'app/repository/DistRepository'; +import { PackageRepository } from 'app/repository/PackageRepository'; +import { BugVersion } from 'app/core/entity/BugVersion'; +import { Package } from 'app/core/entity/Package'; +import { PackageVersion } from 'app/core/entity/PackageVersion'; +import { Dist } from 'app/core/entity/Dist'; describe('test/core/service/BugVersionService/fixPackageBugVersion.test.ts', () => { - let ctx: Context; let bugVersionService: BugVersionService; let bugVersion: BugVersion; let distRepository: DistRepository; let packageRepository: PackageRepository; beforeEach(async () => { - ctx = await app.mockModuleContext(); - bugVersionService = await ctx.getEggObject(BugVersionService); - distRepository = await ctx.getEggObject(DistRepository); - packageRepository = await ctx.getEggObject(PackageRepository); + bugVersionService = await app.getEggObject(BugVersionService); + distRepository = await app.getEggObject(DistRepository); + packageRepository = await app.getEggObject(PackageRepository); bugVersion = new BugVersion({ faker: { '6.6.6': { @@ -109,7 +106,6 @@ describe('test/core/service/BugVersionService/fixPackageBugVersion.test.ts', () }); afterEach(async () => { - await app.destroyModuleContext(ctx); mock.restore(); await TestUtil.truncateDatabase(); }); diff --git a/test/core/service/BugVersionService/fixPackageBugVersions.test.ts b/test/core/service/BugVersionService/fixPackageBugVersions.test.ts index 72408da9..13aade44 100644 --- a/test/core/service/BugVersionService/fixPackageBugVersions.test.ts +++ b/test/core/service/BugVersionService/fixPackageBugVersions.test.ts @@ -1,18 +1,15 @@ -import assert = require('assert'); +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; -import { TestUtil } from '../../../TestUtil'; -import { BugVersionService } from '../../../../app/core/service/BugVersionService'; -import { BugVersion } from '../../../../app/core/entity/BugVersion'; +import { TestUtil } from 'test/TestUtil'; +import { BugVersionService } from 'app/core/service/BugVersionService'; +import { BugVersion } from 'app/core/entity/BugVersion'; describe('test/core/service/BugVersionService/fixPackageBugVersions.test.ts', () => { - let ctx: Context; let bugVersionService: BugVersionService; let bugVersion: BugVersion; beforeEach(async () => { - ctx = await app.mockModuleContext(); - bugVersionService = await ctx.getEggObject(BugVersionService); + bugVersionService = await app.getEggObject(BugVersionService); bugVersion = new BugVersion({ faker: { '6.6.6': { @@ -38,7 +35,6 @@ describe('test/core/service/BugVersionService/fixPackageBugVersions.test.ts', () }); afterEach(async () => { - await app.destroyModuleContext(ctx); mock.restore(); await TestUtil.truncateDatabase(); }); diff --git a/test/core/service/ChangesStreamService.test.ts b/test/core/service/ChangesStreamService.test.ts index d2339e68..68b3066a 100644 --- a/test/core/service/ChangesStreamService.test.ts +++ b/test/core/service/ChangesStreamService.test.ts @@ -1,7 +1,7 @@ -import assert = require('assert'); +import assert from 'assert'; import { Readable } from 'node:stream'; import { app, mock } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; +import { TestUtil } from 'test/TestUtil'; import { ChangesStreamService } from 'app/core/service/ChangesStreamService'; import { TaskService } from 'app/core/service/TaskService'; import { ChangesStreamTask, Task } from 'app/core/entity/Task'; @@ -9,11 +9,9 @@ import { RegistryManagerService } from 'app/core/service/RegistryManagerService' import { RegistryType } from 'app/common/enum/Registry'; import { ScopeManagerService } from 'app/core/service/ScopeManagerService'; import { Registry } from 'app/core/entity/Registry'; -import { TestUtil } from 'test/TestUtil'; import { RedisQueueAdapter } from 'app/infra/QueueAdapter'; describe('test/core/service/ChangesStreamService.test.ts', () => { - let ctx: Context; let changesStreamService: ChangesStreamService; let scopeManagerService: ScopeManagerService; let registryManagerService: RegistryManagerService; @@ -23,12 +21,11 @@ describe('test/core/service/ChangesStreamService.test.ts', () => { let cnpmRegistry: Registry; let queueAdapter: RedisQueueAdapter; beforeEach(async () => { - ctx = await app.mockModuleContext(); - changesStreamService = await ctx.getEggObject(ChangesStreamService); - taskService = await ctx.getEggObject(TaskService); - registryManagerService = await ctx.getEggObject(RegistryManagerService); - scopeManagerService = await ctx.getEggObject(ScopeManagerService); - queueAdapter = await ctx.getEggObject(RedisQueueAdapter); + changesStreamService = await app.getEggObject(ChangesStreamService); + taskService = await app.getEggObject(TaskService); + registryManagerService = await app.getEggObject(RegistryManagerService); + scopeManagerService = await app.getEggObject(ScopeManagerService); + queueAdapter = await app.getEggObject(RedisQueueAdapter); assert(changesStreamService); task = Task.createChangesStream('GLOBAL_WORKER', '', '9527'); taskService.createTask(task, false); @@ -166,7 +163,7 @@ describe('test/core/service/ChangesStreamService.test.ts', () => { describe('fetchChanges()', () => { it('should work', async () => { - mock(ctx.httpclient, 'request', async () => { + mock(app.httpclient, 'request', async () => { return { res: Readable.from(` {"seq":2,"id":"backbone.websql.deferred","changes":[{"rev":"4-f5150b238ab62cd890211fb57fc9eca5"}],"deleted":true}, @@ -183,7 +180,7 @@ describe('test/core/service/ChangesStreamService.test.ts', () => { mock(ChangesStreamService.prototype, 'needSync', async () => { return false; }); - mock(ctx.httpclient, 'request', async () => { + mock(app.httpclient, 'request', async () => { return { res: Readable.from(` {"seq":2,"id":"backbone.websql.deferred","changes":[{"rev":"4-f5150b238ab62cd890211fb57fc9eca5"}],"deleted":true}, diff --git a/test/core/service/CreateHookTriggerService.test.ts b/test/core/service/CreateHookTriggerService.test.ts index cec882a9..2d2e0f30 100644 --- a/test/core/service/CreateHookTriggerService.test.ts +++ b/test/core/service/CreateHookTriggerService.test.ts @@ -1,21 +1,19 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; -import { TestUtil } from '../../TestUtil'; -import { HookManageService } from '../../../app/core/service/HookManageService'; -import { HookType } from '../../../app/common/enum/Hook'; -import { UserRepository } from '../../../app/repository/UserRepository'; -import { PACKAGE_VERSION_ADDED } from '../../../app/core/event'; -import { Change } from '../../../app/core/entity/Change'; -import { ChangeRepository } from '../../../app/repository/ChangeRepository'; -import { Task } from '../../../app/core/entity/Task'; -import { HookEvent } from '../../../app/core/entity/HookEvent'; -import { CreateHookTriggerService } from '../../../app/core/service/CreateHookTriggerService'; -import { TaskRepository } from '../../../app/repository/TaskRepository'; -import { Hook } from '../../../app/core/entity/Hook'; +import { TestUtil } from 'test/TestUtil'; +import { HookManageService } from 'app/core/service/HookManageService'; +import { HookType } from 'app/common/enum/Hook'; +import { UserRepository } from 'app/repository/UserRepository'; +import { PACKAGE_VERSION_ADDED } from 'app/core/event'; +import { Change } from 'app/core/entity/Change'; +import { ChangeRepository } from 'app/repository/ChangeRepository'; +import { Task } from 'app/core/entity/Task'; +import { HookEvent } from 'app/core/entity/HookEvent'; +import { CreateHookTriggerService } from 'app/core/service/CreateHookTriggerService'; +import { TaskRepository } from 'app/repository/TaskRepository'; +import { Hook } from 'app/core/entity/Hook'; describe('test/core/service/CreateHookTriggerService.test.ts', () => { - let ctx: Context; let hookManageService: HookManageService; let changeRepository: ChangeRepository; let createHookTriggerService: CreateHookTriggerService; @@ -25,12 +23,11 @@ describe('test/core/service/CreateHookTriggerService.test.ts', () => { let userId: string; beforeEach(async () => { - ctx = await app.mockModuleContext(); - hookManageService = await ctx.getEggObject(HookManageService); - changeRepository = await ctx.getEggObject(ChangeRepository); - createHookTriggerService = await ctx.getEggObject(CreateHookTriggerService); - taskRepository = await ctx.getEggObject(TaskRepository); - const userRepository = await ctx.getEggObject(UserRepository); + hookManageService = await app.getEggObject(HookManageService); + changeRepository = await app.getEggObject(ChangeRepository); + createHookTriggerService = await app.getEggObject(CreateHookTriggerService); + taskRepository = await app.getEggObject(TaskRepository); + const userRepository = await app.getEggObject(UserRepository); await TestUtil.createPackage({ name: pkgName, }, { diff --git a/test/core/service/HookManageService/createHook.test.ts b/test/core/service/HookManageService/createHook.test.ts index fcd365e2..3717a768 100644 --- a/test/core/service/HookManageService/createHook.test.ts +++ b/test/core/service/HookManageService/createHook.test.ts @@ -1,28 +1,24 @@ -import assert = require('assert'); +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; -import { HookManageService } from '../../../../app/core/service/HookManageService'; -import { TestUtil } from '../../../TestUtil'; -import { HookType } from '../../../../app/common/enum/Hook'; +import { TestUtil } from 'test/TestUtil'; +import { HookManageService } from 'app/core/service/HookManageService'; +import { HookType } from 'app/common/enum/Hook'; describe('test/core/service/HookManageService/createHook.test.ts', () => { - let ctx: Context; let hookManageService: HookManageService; beforeEach(async () => { - ctx = await app.mockModuleContext(); - hookManageService = await ctx.getEggObject(HookManageService); + hookManageService = await app.getEggObject(HookManageService); }); afterEach(async () => { await TestUtil.truncateDatabase(); - await app.destroyModuleContext(ctx); mock.restore(); }); describe('limit exceeded', () => { beforeEach(() => { - mock(ctx.app.config.cnpmcore, 'hooksLimit', 0); + mock(app.config.cnpmcore, 'hooksLimit', 0); }); it('should throw error', async () => { diff --git a/test/core/service/HookManageService/deleteHook.test.ts b/test/core/service/HookManageService/deleteHook.test.ts index 73e2303e..f90bba3d 100644 --- a/test/core/service/HookManageService/deleteHook.test.ts +++ b/test/core/service/HookManageService/deleteHook.test.ts @@ -1,19 +1,16 @@ import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; -import { HookManageService } from '../../../../app/core/service/HookManageService'; -import { Hook } from '../../../../app/core/entity/Hook'; -import { TestUtil } from '../../../TestUtil'; -import { HookType } from '../../../../app/common/enum/Hook'; +import { TestUtil } from 'test/TestUtil'; +import { HookManageService } from 'app/core/service/HookManageService'; +import { Hook } from 'app/core/entity/Hook'; +import { HookType } from 'app/common/enum/Hook'; describe('test/core/service/HookManageService/deleteHook.test.ts', () => { - let ctx: Context; let hookManageService: HookManageService; let hook: Hook; beforeEach(async () => { - ctx = await app.mockModuleContext(); - hookManageService = await ctx.getEggObject(HookManageService); + hookManageService = await app.getEggObject(HookManageService); hook = await hookManageService.createHook({ type: HookType.Package, ownerId: 'mock_owner_id', @@ -25,7 +22,6 @@ describe('test/core/service/HookManageService/deleteHook.test.ts', () => { afterEach(async () => { await TestUtil.truncateDatabase(); - await app.destroyModuleContext(ctx); mock.restore(); }); diff --git a/test/core/service/HookManageService/getHookByOwnerId.test.ts b/test/core/service/HookManageService/getHookByOwnerId.test.ts index b082fa67..4b379771 100644 --- a/test/core/service/HookManageService/getHookByOwnerId.test.ts +++ b/test/core/service/HookManageService/getHookByOwnerId.test.ts @@ -1,19 +1,16 @@ import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; -import { HookManageService } from '../../../../app/core/service/HookManageService'; -import { Hook } from '../../../../app/core/entity/Hook'; -import { TestUtil } from '../../../TestUtil'; -import { HookType } from '../../../../app/common/enum/Hook'; +import { TestUtil } from 'test/TestUtil'; +import { HookManageService } from 'app/core/service/HookManageService'; +import { Hook } from 'app/core/entity/Hook'; +import { HookType } from 'app/common/enum/Hook'; describe('test/core/service/HookManageService/getHookByOwnerId.test.ts', () => { - let ctx: Context; let hookManageService: HookManageService; let hook: Hook; beforeEach(async () => { - ctx = await app.mockModuleContext(); - hookManageService = await ctx.getEggObject(HookManageService); + hookManageService = await app.getEggObject(HookManageService); hook = await hookManageService.createHook({ type: HookType.Package, ownerId: 'mock_owner_id', @@ -25,7 +22,6 @@ describe('test/core/service/HookManageService/getHookByOwnerId.test.ts', () => { afterEach(async () => { await TestUtil.truncateDatabase(); - await app.destroyModuleContext(ctx); mock.restore(); }); diff --git a/test/core/service/HookManageService/updateHook.test.ts b/test/core/service/HookManageService/updateHook.test.ts index 2ea436f0..78ab7cd0 100644 --- a/test/core/service/HookManageService/updateHook.test.ts +++ b/test/core/service/HookManageService/updateHook.test.ts @@ -1,19 +1,16 @@ import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; -import { HookManageService } from '../../../../app/core/service/HookManageService'; -import { Hook } from '../../../../app/core/entity/Hook'; -import { TestUtil } from '../../../TestUtil'; -import { HookType } from '../../../../app/common/enum/Hook'; +import { TestUtil } from 'test/TestUtil'; +import { HookManageService } from 'app/core/service/HookManageService'; +import { Hook } from 'app/core/entity/Hook'; +import { HookType } from 'app/common/enum/Hook'; describe('test/core/service/HookManageService/updateHook.test.ts', () => { - let ctx: Context; let hookManageService: HookManageService; let hook: Hook; beforeEach(async () => { - ctx = await app.mockModuleContext(); - hookManageService = await ctx.getEggObject(HookManageService); + hookManageService = await app.getEggObject(HookManageService); hook = await hookManageService.createHook({ type: HookType.Package, ownerId: 'mock_owner_id', @@ -25,7 +22,6 @@ describe('test/core/service/HookManageService/updateHook.test.ts', () => { afterEach(async () => { await TestUtil.truncateDatabase(); - await app.destroyModuleContext(ctx); mock.restore(); }); diff --git a/test/core/service/HookTriggerService.test.ts b/test/core/service/HookTriggerService.test.ts index 5c153a81..6c3ce57e 100644 --- a/test/core/service/HookTriggerService.test.ts +++ b/test/core/service/HookTriggerService.test.ts @@ -1,23 +1,21 @@ -import assert = require('assert'); +import assert from 'assert'; +import { HttpClientRequestOptions } from 'egg'; import { app, mock } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; -import { TestUtil } from '../../TestUtil'; -import { HookManageService } from '../../../app/core/service/HookManageService'; -import { HookType } from '../../../app/common/enum/Hook'; -import { UserRepository } from '../../../app/repository/UserRepository'; -import { PACKAGE_VERSION_ADDED } from '../../../app/core/event'; -import { Change } from '../../../app/core/entity/Change'; -import { ChangeRepository } from '../../../app/repository/ChangeRepository'; -import { Task, TriggerHookTask } from '../../../app/core/entity/Task'; -import { HookEvent } from '../../../app/core/entity/HookEvent'; -import { CreateHookTriggerService } from '../../../app/core/service/CreateHookTriggerService'; -import { TaskRepository } from '../../../app/repository/TaskRepository'; -import { Hook } from '../../../app/core/entity/Hook'; -import { HookTriggerService } from '../../../app/core/service/HookTriggerService'; -import { RequestOptions } from 'urllib/src/Request'; +import { TestUtil } from 'test/TestUtil'; +import { HookManageService } from 'app/core/service/HookManageService'; +import { HookType } from 'app/common/enum/Hook'; +import { UserRepository } from 'app/repository/UserRepository'; +import { PACKAGE_VERSION_ADDED } from 'app/core/event'; +import { Change } from 'app/core/entity/Change'; +import { ChangeRepository } from 'app/repository/ChangeRepository'; +import { Task, TriggerHookTask } from 'app/core/entity/Task'; +import { HookEvent } from 'app/core/entity/HookEvent'; +import { CreateHookTriggerService } from 'app/core/service/CreateHookTriggerService'; +import { TaskRepository } from 'app/repository/TaskRepository'; +import { Hook } from 'app/core/entity/Hook'; +import { HookTriggerService } from 'app/core/service/HookTriggerService'; describe('test/core/service/HookTriggerService.test.ts', () => { - let ctx: Context; let hookManageService: HookManageService; let changeRepository: ChangeRepository; let createHookTriggerService: CreateHookTriggerService; @@ -28,13 +26,12 @@ describe('test/core/service/HookTriggerService.test.ts', () => { let userId: string; beforeEach(async () => { - ctx = await app.mockModuleContext(); - hookManageService = await ctx.getEggObject(HookManageService); - changeRepository = await ctx.getEggObject(ChangeRepository); - createHookTriggerService = await ctx.getEggObject(CreateHookTriggerService); - taskRepository = await ctx.getEggObject(TaskRepository); - const userRepository = await ctx.getEggObject(UserRepository); - hookTriggerService = await ctx.getEggObject(HookTriggerService); + hookManageService = await app.getEggObject(HookManageService); + changeRepository = await app.getEggObject(ChangeRepository); + createHookTriggerService = await app.getEggObject(CreateHookTriggerService); + taskRepository = await app.getEggObject(TaskRepository); + const userRepository = await app.getEggObject(UserRepository); + hookTriggerService = await app.getEggObject(HookTriggerService); await TestUtil.createPackage({ name: pkgName, }, { @@ -48,7 +45,7 @@ describe('test/core/service/HookTriggerService.test.ts', () => { let change: Change; let hook: Hook; let callEndpoint: string; - let callOptions: RequestOptions; + let callOptions: HttpClientRequestOptions; beforeEach(async () => { change = Change.create({ @@ -69,7 +66,7 @@ describe('test/core/service/HookTriggerService.test.ts', () => { const task = Task.createCreateHookTask(HookEvent.createPublishEvent(pkgName, change.changeId, '1.0.0', 'latest')); await createHookTriggerService.executeTask(task); - mock(ctx.httpclient, 'request', async (url, options) => { + mock(app.httpclient, 'request', async (url, options) => { callEndpoint = url; callOptions = options; return { diff --git a/test/core/service/PackageManagerService/publish.test.ts b/test/core/service/PackageManagerService/publish.test.ts index 99471adc..72a7b5f0 100644 --- a/test/core/service/PackageManagerService/publish.test.ts +++ b/test/core/service/PackageManagerService/publish.test.ts @@ -1,23 +1,20 @@ -import assert = require('assert'); +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; -import { PackageManagerService } from '../../../../app/core/service/PackageManagerService'; -import { UserService } from '../../../../app/core/service/UserService'; -import { PackageRepository } from '../../../../app/repository/PackageRepository'; -import { TestUtil } from '../../../TestUtil'; +import { TestUtil } from 'test/TestUtil'; +import { PackageManagerService } from 'app/core/service/PackageManagerService'; +import { UserService } from 'app/core/service/UserService'; +import { PackageRepository } from 'app/repository/PackageRepository'; describe('test/core/service/PackageManagerService/publish.test.ts', () => { - let ctx: Context; let packageManagerService: PackageManagerService; let userService: UserService; let packageRepository: PackageRepository; let publisher; beforeEach(async () => { - ctx = await app.mockModuleContext(); - userService = await ctx.getEggObject(UserService); - packageManagerService = await ctx.getEggObject(PackageManagerService); - packageRepository = await ctx.getEggObject(PackageRepository); + userService = await app.getEggObject(UserService); + packageManagerService = await app.getEggObject(PackageManagerService); + packageRepository = await app.getEggObject(PackageRepository); const { user } = await userService.create({ name: 'test-user', @@ -29,7 +26,6 @@ describe('test/core/service/PackageManagerService/publish.test.ts', () => { }); afterEach(async () => { - await app.destroyModuleContext(ctx); mock.restore(); await TestUtil.truncateDatabase(); }); diff --git a/test/core/service/PackageSyncerService/createTask.test.ts b/test/core/service/PackageSyncerService/createTask.test.ts index 4b08a7c8..4fae6b89 100644 --- a/test/core/service/PackageSyncerService/createTask.test.ts +++ b/test/core/service/PackageSyncerService/createTask.test.ts @@ -1,16 +1,14 @@ -import assert = require('assert'); -import { app, mock } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; +import assert from 'assert'; import { setTimeout } from 'timers/promises'; -import { PackageSyncerService } from '../../../../app/core/service/PackageSyncerService'; -import { TestUtil } from '../../../TestUtil'; +import { app, mock } from 'egg-mock/bootstrap'; +import { TestUtil } from 'test/TestUtil'; +import { PackageSyncerService } from 'app/core/service/PackageSyncerService'; import { Task } from 'app/core/entity/Task'; -import { TaskState } from '../../../../app/common/enum/Task'; -import { TaskRepository } from '../../../../app/repository/TaskRepository'; -import { TaskService } from '../../../../app/core/service/TaskService'; +import { TaskState } from 'app/common/enum/Task'; +import { TaskRepository } from 'app/repository/TaskRepository'; +import { TaskService } from 'app/core/service/TaskService'; describe('test/core/service/PackageSyncerService/createTask.test.ts', () => { - let ctx: Context; const pkgName = '@cnpmcore/foo'; const username = 'mock_username'; let packageSyncerService: PackageSyncerService; @@ -18,10 +16,9 @@ describe('test/core/service/PackageSyncerService/createTask.test.ts', () => { let taskService: TaskService; beforeEach(async () => { - ctx = await app.mockModuleContext(); - packageSyncerService = await ctx.getEggObject(PackageSyncerService); - taskRepository = await ctx.getEggObject(TaskRepository); - taskService = await ctx.getEggObject(TaskService); + packageSyncerService = await app.getEggObject(PackageSyncerService); + taskRepository = await app.getEggObject(TaskRepository); + taskService = await app.getEggObject(TaskService); await TestUtil.createPackage({ name: pkgName, @@ -32,10 +29,6 @@ describe('test/core/service/PackageSyncerService/createTask.test.ts', () => { }); }); - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - it('should ignore if registryId not same', async () => { await assert.rejects(async () => { await packageSyncerService.createTask(pkgName, { diff --git a/test/core/service/PackageSyncerService/executeTask.test.ts b/test/core/service/PackageSyncerService/executeTask.test.ts index 569ec34e..181c9bf9 100644 --- a/test/core/service/PackageSyncerService/executeTask.test.ts +++ b/test/core/service/PackageSyncerService/executeTask.test.ts @@ -1,13 +1,12 @@ -import assert = require('assert'); +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; +import { TestUtil } from 'test/TestUtil'; import { PackageSyncerService } from 'app/core/service/PackageSyncerService'; import { PackageManagerService } from 'app/core/service/PackageManagerService'; import { Package as PackageModel } from 'app/repository/model/Package'; import { Task as TaskModel } from 'app/repository/model/Task'; import { Task as TaskEntity } from 'app/core/entity/Task'; import { HistoryTask as HistoryTaskModel } from 'app/repository/model/HistoryTask'; -import { TestUtil } from 'test/TestUtil'; import { NPMRegistry } from 'app/common/adapter/NPMRegistry'; import { NFSAdapter } from 'app/common/adapter/NFSAdapter'; import { getScopeAndName } from 'app/common/PackageUtil'; @@ -21,7 +20,6 @@ import { UserService } from 'app/core/service/UserService'; import { ChangeRepository } from 'app/repository/ChangeRepository'; describe('test/core/service/PackageSyncerService/executeTask.test.ts', () => { - let ctx: Context; let packageSyncerService: PackageSyncerService; let packageManagerService: PackageManagerService; let packageRepository: PackageRepository; @@ -33,20 +31,15 @@ describe('test/core/service/PackageSyncerService/executeTask.test.ts', () => { let changeRepository: ChangeRepository; beforeEach(async () => { - ctx = await app.mockModuleContext(); - packageSyncerService = await ctx.getEggObject(PackageSyncerService); - packageManagerService = await ctx.getEggObject(PackageManagerService); - packageRepository = await ctx.getEggObject(PackageRepository); - npmRegistry = await ctx.getEggObject(NPMRegistry); - taskService = await ctx.getEggObject(TaskService); - registryManagerService = await ctx.getEggObject(RegistryManagerService); - scopeManagerService = await ctx.getEggObject(ScopeManagerService); - userService = await ctx.getEggObject(UserService); - changeRepository = await ctx.getEggObject(ChangeRepository); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); + packageSyncerService = await app.getEggObject(PackageSyncerService); + packageManagerService = await app.getEggObject(PackageManagerService); + packageRepository = await app.getEggObject(PackageRepository); + npmRegistry = await app.getEggObject(NPMRegistry); + taskService = await app.getEggObject(TaskService); + registryManagerService = await app.getEggObject(RegistryManagerService); + scopeManagerService = await app.getEggObject(ScopeManagerService); + userService = await app.getEggObject(UserService); + changeRepository = await app.getEggObject(ChangeRepository); }); describe('executeTask()', () => { diff --git a/test/core/service/PackageSyncerService/findExecuteTask.test.ts b/test/core/service/PackageSyncerService/findExecuteTask.test.ts index bfb6fd0f..e01c9bc3 100644 --- a/test/core/service/PackageSyncerService/findExecuteTask.test.ts +++ b/test/core/service/PackageSyncerService/findExecuteTask.test.ts @@ -1,24 +1,17 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { PackageSyncerService } from 'app/core/service/PackageSyncerService'; import { Task as TaskModel } from 'app/repository/model/Task'; import { HistoryTask as HistoryTaskModel } from 'app/repository/model/HistoryTask'; import { TaskService } from 'app/core/service/TaskService'; describe('test/core/service/PackageSyncerService/findExecuteTask.test.ts', () => { - let ctx: Context; let packageSyncerService: PackageSyncerService; let taskService: TaskService; beforeEach(async () => { - ctx = await app.mockModuleContext(); - packageSyncerService = await ctx.getEggObject(PackageSyncerService); - taskService = await ctx.getEggObject(TaskService); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); + packageSyncerService = await app.getEggObject(PackageSyncerService); + taskService = await app.getEggObject(TaskService); }); describe('findExecuteTask()', () => { diff --git a/test/core/service/PackageSyncerService/getTaskRegistry.test.ts b/test/core/service/PackageSyncerService/getTaskRegistry.test.ts index 44f6eb81..02a07a88 100644 --- a/test/core/service/PackageSyncerService/getTaskRegistry.test.ts +++ b/test/core/service/PackageSyncerService/getTaskRegistry.test.ts @@ -1,6 +1,5 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { PackageSyncerService } from 'app/core/service/PackageSyncerService'; import { RegistryManagerService } from 'app/core/service/RegistryManagerService'; import { Registry } from 'app/core/entity/Registry'; @@ -8,16 +7,14 @@ import { RegistryType } from 'app/common/enum/Registry'; import { Task } from 'app/core/entity/Task'; describe('test/core/service/PackageSyncerService/getTaskRegistry.test.ts', () => { - let ctx: Context; let packageSyncerService: PackageSyncerService; let registryManagerService: RegistryManagerService; let registry: Registry; let task: Task; beforeEach(async () => { - ctx = await app.mockModuleContext(); - packageSyncerService = await ctx.getEggObject(PackageSyncerService); - registryManagerService = await ctx.getEggObject(RegistryManagerService); + packageSyncerService = await app.getEggObject(PackageSyncerService); + registryManagerService = await app.getEggObject(RegistryManagerService); registry = await registryManagerService.createRegistry({ name: 'cnpmcore', changeStream: 'https://r.cnpmjs.org/_changes', @@ -33,11 +30,6 @@ describe('test/core/service/PackageSyncerService/getTaskRegistry.test.ts', () => skipDependencies: true, tips: `Sync cause by changes_stream(${registry.changeStream}) update seq: 1`, }); - - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); }); describe('getTaskRegistry()', () => { diff --git a/test/core/service/RegistryManagerService/index.test.ts b/test/core/service/RegistryManagerService/index.test.ts index e8f84496..619e27e9 100644 --- a/test/core/service/RegistryManagerService/index.test.ts +++ b/test/core/service/RegistryManagerService/index.test.ts @@ -1,6 +1,5 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { RegistryManagerService } from 'app/core/service/RegistryManagerService'; import { RegistryType } from 'app/common/enum/Registry'; import { ScopeManagerService } from 'app/core/service/ScopeManagerService'; @@ -10,16 +9,14 @@ import { TaskType } from 'app/common/enum/Task'; import { ChangesStreamTaskData } from 'app/core/entity/Task'; describe('test/core/service/RegistryManagerService/index.test.ts', () => { - let ctx: Context; let registryManagerService: RegistryManagerService; let scopeManagerService: ScopeManagerService; let taskRepository: TaskRepository; before(async () => { - ctx = await app.mockModuleContext(); - registryManagerService = await ctx.getEggObject(RegistryManagerService); - scopeManagerService = await ctx.getEggObject(ScopeManagerService); - taskRepository = await ctx.getEggObject(TaskRepository); + registryManagerService = await app.getEggObject(RegistryManagerService); + scopeManagerService = await app.getEggObject(ScopeManagerService); + taskRepository = await app.getEggObject(TaskRepository); }); beforeEach(async () => { @@ -33,10 +30,6 @@ describe('test/core/service/RegistryManagerService/index.test.ts', () => { }); }); - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('RegistryManagerService', () => { describe('query should work', async () => { @@ -155,7 +148,5 @@ describe('test/core/service/RegistryManagerService/index.test.ts', () => { assert((task?.data as ChangesStreamTaskData).since === ''); }); }); - - }); }); diff --git a/test/core/service/ScopeManagerService/index.test.ts b/test/core/service/ScopeManagerService/index.test.ts index cb4a6e2d..3d8f818a 100644 --- a/test/core/service/ScopeManagerService/index.test.ts +++ b/test/core/service/ScopeManagerService/index.test.ts @@ -1,15 +1,12 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { ScopeManagerService } from 'app/core/service/ScopeManagerService'; describe('test/core/service/ScopeManagerService/index.test.ts', () => { - let ctx: Context; let scopeManagerService: ScopeManagerService; before(async () => { - ctx = await app.mockModuleContext(); - scopeManagerService = await ctx.getEggObject(ScopeManagerService); + scopeManagerService = await app.getEggObject(ScopeManagerService); }); beforeEach(async () => { @@ -20,10 +17,6 @@ describe('test/core/service/ScopeManagerService/index.test.ts', () => { }); }); - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('ScopeManagerService', () => { it('query should work', async () => { const queryRes = await scopeManagerService.listScopes({}); diff --git a/test/core/service/TaskService/findExecuteTask.test.ts b/test/core/service/TaskService/findExecuteTask.test.ts index c94d16d1..f1ee583c 100644 --- a/test/core/service/TaskService/findExecuteTask.test.ts +++ b/test/core/service/TaskService/findExecuteTask.test.ts @@ -1,27 +1,19 @@ -import assert = require('assert'); +import assert from 'assert'; import { app, mm } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { TaskService } from 'app/core/service/TaskService'; import { PackageSyncerService } from 'app/core/service/PackageSyncerService'; import { TaskState, TaskType } from 'app/common/enum/Task'; -import { RedisQueueAdapter } from '../../../../app/infra/QueueAdapter'; +import { RedisQueueAdapter } from 'app/infra/QueueAdapter'; describe('test/core/service/TaskService/findExecuteTask.test.ts', () => { - let ctx: Context; let taskService: TaskService; let packageSyncerService: PackageSyncerService; let queueAdapter: RedisQueueAdapter; beforeEach(async () => { - ctx = await app.mockModuleContext(); - taskService = await ctx.getEggObject(TaskService); - packageSyncerService = await ctx.getEggObject(PackageSyncerService); - queueAdapter = await ctx.getEggObject(RedisQueueAdapter); - }); - - afterEach(async () => { - mm.restore(); - await app.destroyModuleContext(ctx); + taskService = await app.getEggObject(TaskService); + packageSyncerService = await app.getEggObject(PackageSyncerService); + queueAdapter = await app.getEggObject(RedisQueueAdapter); }); describe('findExecuteTask()', () => { diff --git a/test/core/util/EntityUtil.test.ts b/test/core/util/EntityUtil.test.ts index 7932120e..3174fa68 100644 --- a/test/core/util/EntityUtil.test.ts +++ b/test/core/util/EntityUtil.test.ts @@ -1,5 +1,5 @@ import { EntityUtil } from 'app/core/util/EntityUtil'; -import assert = require('assert'); +import assert from 'assert'; describe('test/core/util/EntityUtil.test.ts', () => { describe('convertPageOptionsToLimitOption', () => { diff --git a/test/infra/QueueAdapter.test.ts b/test/infra/QueueAdapter.test.ts index 56f715d1..7bc1f518 100644 --- a/test/infra/QueueAdapter.test.ts +++ b/test/infra/QueueAdapter.test.ts @@ -1,19 +1,12 @@ -import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import assert from 'assert'; -import { RedisQueueAdapter } from '../../app/infra/QueueAdapter'; +import { app } from 'egg-mock/bootstrap'; +import { RedisQueueAdapter } from 'app/infra/QueueAdapter'; describe('test/infra/QueueAdapter.test.ts', () => { - let ctx: Context; let queueAdapter: RedisQueueAdapter; beforeEach(async () => { - ctx = await app.mockModuleContext(); - queueAdapter = await ctx.getEggObject(RedisQueueAdapter); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); + queueAdapter = await app.getEggObject(RedisQueueAdapter); }); it('should not push duplicate task', async () => { diff --git a/test/port/controller/BinarySyncController/showBinary.test.ts b/test/port/controller/BinarySyncController/showBinary.test.ts index 48b66dad..66e9eb50 100644 --- a/test/port/controller/BinarySyncController/showBinary.test.ts +++ b/test/port/controller/BinarySyncController/showBinary.test.ts @@ -1,5 +1,4 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; import { BinarySyncerService } from 'app/core/service/BinarySyncerService'; import { NodeBinary } from 'app/common/adapter/binary/NodeBinary'; @@ -10,22 +9,16 @@ import { NFSClientAdapter } from 'app/infra/NFSClientAdapter'; import { TestUtil } from 'test/TestUtil'; describe('test/port/controller/BinarySyncController/showBinary.test.ts', () => { - let ctx: Context; let binarySyncerService: BinarySyncerService; let binaryRepository: BinaryRepository; let nfsClientAdapter: NFSClientAdapter; beforeEach(async () => { - ctx = await app.mockModuleContext(); - binarySyncerService = await ctx.getEggObject(BinarySyncerService); - binaryRepository = await ctx.getEggObject(BinaryRepository); + binarySyncerService = await app.getEggObject(BinarySyncerService); + binaryRepository = await app.getEggObject(BinaryRepository); nfsClientAdapter = await app.getEggObject(NFSClientAdapter); }); - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('[GET /binary.html] showBinaryHTML()', () => { it('should 200', async () => { const res = await app.httpRequest() diff --git a/test/port/controller/ChangesStreamController/listChanges.test.ts b/test/port/controller/ChangesStreamController/listChanges.test.ts index 32e531de..8ccd2999 100644 --- a/test/port/controller/ChangesStreamController/listChanges.test.ts +++ b/test/port/controller/ChangesStreamController/listChanges.test.ts @@ -1,18 +1,8 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { TestUtil } from '../../../TestUtil'; +import { TestUtil } from 'test/TestUtil'; describe('test/port/controller/ChangesStreamController/listChanges.test.ts', () => { - let ctx: Context; - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('[GET /_changes] listChanges()', () => { it('should 422 when since is not number', async () => { const res = await app.httpRequest() diff --git a/test/port/controller/DownloadController/showPackageDownloads.test.ts b/test/port/controller/DownloadController/showPackageDownloads.test.ts index cb52130a..93e90f0e 100644 --- a/test/port/controller/DownloadController/showPackageDownloads.test.ts +++ b/test/port/controller/DownloadController/showPackageDownloads.test.ts @@ -1,21 +1,14 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; -import dayjs from '../../../../app/common/dayjs'; +import dayjs from 'app/common/dayjs'; import { TestUtil } from 'test/TestUtil'; const SavePackageVersionDownloadCounterPath = require.resolve('../../../../app/port/schedule/SavePackageVersionDownloadCounter'); describe('test/port/controller/DownloadController/showPackageDownloads.test.ts', () => { - let ctx: Context; let publisher; beforeEach(async () => { publisher = await TestUtil.createUser(); - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); }); describe('[GET /downloads/range/:range/:fullname] showPackageDownloads()', () => { diff --git a/test/port/controller/HomeController/cors.test.ts b/test/port/controller/HomeController/cors.test.ts index 2ddf9a60..21291d35 100644 --- a/test/port/controller/HomeController/cors.test.ts +++ b/test/port/controller/HomeController/cors.test.ts @@ -1,17 +1,7 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; describe('test/port/controller/HomeController/cors.test.ts', () => { - let ctx: Context; - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('CORS', () => { it('should GET work', async () => { const res = await app.httpRequest() diff --git a/test/port/controller/HomeController/ping.test.ts b/test/port/controller/HomeController/ping.test.ts index 59be6ef8..825eeab6 100644 --- a/test/port/controller/HomeController/ping.test.ts +++ b/test/port/controller/HomeController/ping.test.ts @@ -1,17 +1,7 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; describe('test/port/controller/HomeController/ping.test.ts', () => { - let ctx: Context; - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('[GET /-/ping] ping()', () => { it('should 200', async () => { const res = await app.httpRequest() diff --git a/test/port/controller/HomeController/showTotal.test.ts b/test/port/controller/HomeController/showTotal.test.ts index 79ed91ba..9a63dd23 100644 --- a/test/port/controller/HomeController/showTotal.test.ts +++ b/test/port/controller/HomeController/showTotal.test.ts @@ -1,5 +1,4 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; import { TestUtil } from 'test/TestUtil'; import { PackageVersionDownload } from 'app/repository/model/PackageVersionDownload'; @@ -9,15 +8,6 @@ const SavePackageVersionDownloadCounterPath = require.resolve('../../../../app/p const UpdateTotalDataPath = require.resolve('../../../../app/port/schedule/UpdateTotalData'); describe('test/port/controller/HomeController/showTotal.test.ts', () => { - let ctx: Context; - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('[GET /] showTotal()', () => { it('should total information', async () => { let res = await app.httpRequest() diff --git a/test/port/controller/PackageBlockController/blockPackage.test.ts b/test/port/controller/PackageBlockController/blockPackage.test.ts index 7aa1cdd3..6ed38ee1 100644 --- a/test/port/controller/PackageBlockController/blockPackage.test.ts +++ b/test/port/controller/PackageBlockController/blockPackage.test.ts @@ -1,18 +1,11 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; import { TestUtil } from 'test/TestUtil'; describe('test/port/controller/PackageBlockController/blockPackage.test.ts', () => { let adminUser: any; - let ctx: Context; beforeEach(async () => { adminUser = await TestUtil.createAdmin(); - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); }); describe('[PUT /-/package/:fullname/blocks] blockPackage()', () => { diff --git a/test/port/controller/PackageBlockController/unblockPackage.test.ts b/test/port/controller/PackageBlockController/unblockPackage.test.ts index 7d59c3f7..453ecf2e 100644 --- a/test/port/controller/PackageBlockController/unblockPackage.test.ts +++ b/test/port/controller/PackageBlockController/unblockPackage.test.ts @@ -1,18 +1,11 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; import { TestUtil } from 'test/TestUtil'; describe('test/port/controller/PackageBlockController/unblockPackage.test.ts', () => { let adminUser: any; - let ctx: Context; beforeEach(async () => { adminUser = await TestUtil.createAdmin(); - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); }); describe('[DELETE /-/package/:fullname/blocks] unblockPackage()', () => { diff --git a/test/port/controller/PackageSyncController/createSyncTask.test.ts b/test/port/controller/PackageSyncController/createSyncTask.test.ts index e593e022..e61837f7 100644 --- a/test/port/controller/PackageSyncController/createSyncTask.test.ts +++ b/test/port/controller/PackageSyncController/createSyncTask.test.ts @@ -1,6 +1,5 @@ -import assert = require('assert'); +import assert from 'assert'; import { setTimeout } from 'timers/promises'; -import { Context } from 'egg'; import { app, mock } from 'egg-mock/bootstrap'; import { TestUtil } from 'test/TestUtil'; import { Task as TaskModel } from 'app/repository/model/Task'; @@ -8,17 +7,11 @@ import { PackageSyncerService } from 'app/core/service/PackageSyncerService'; describe('test/port/controller/PackageSyncController/createSyncTask.test.ts', () => { let publisher: any; - let ctx: Context; beforeEach(async () => { publisher = await TestUtil.createUser(); - ctx = await app.mockModuleContext(); mock(app.config.cnpmcore, 'syncMode', 'all'); }); - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('[PUT /-/package/:fullname/syncs] createSyncTask()', () => { it('should 403 when syncMode = none', async () => { mock(app.config.cnpmcore, 'syncMode', 'none'); diff --git a/test/port/controller/PackageSyncController/showSyncTask.test.ts b/test/port/controller/PackageSyncController/showSyncTask.test.ts index d369139e..0ef8b55c 100644 --- a/test/port/controller/PackageSyncController/showSyncTask.test.ts +++ b/test/port/controller/PackageSyncController/showSyncTask.test.ts @@ -1,5 +1,4 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; import { TestUtil } from 'test/TestUtil'; import { TaskRepository } from '../../../../app/repository/TaskRepository'; @@ -9,19 +8,13 @@ const SyncPackageWorkerPath = require.resolve('../../../../app/port/schedule/Syn describe('test/port/controller/PackageSyncController/showSyncTask.test.ts', () => { let publisher; - let ctx: Context; let taskRepository: TaskRepository; beforeEach(async () => { publisher = await TestUtil.createUser(); - ctx = await app.mockModuleContext(); - taskRepository = await ctx.getEggObject(TaskRepository); + taskRepository = await app.getEggObject(TaskRepository); mock(app.config.cnpmcore, 'syncMode', 'all'); }); - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('[GET /-/package/:fullname/syncs/:taskId] showSyncTask()', () => { it('should 401 if user not login when alwaysAuth = true', async () => { const pkg = await TestUtil.getFullPackage({ name: '@cnpm/koa', version: '1.0.0' }); diff --git a/test/port/controller/PackageSyncController/showSyncTaskLog.test.ts b/test/port/controller/PackageSyncController/showSyncTaskLog.test.ts index cd1722f4..b8e017d5 100644 --- a/test/port/controller/PackageSyncController/showSyncTaskLog.test.ts +++ b/test/port/controller/PackageSyncController/showSyncTaskLog.test.ts @@ -1,5 +1,4 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; import { TestUtil } from 'test/TestUtil'; import { TaskRepository } from 'app/repository/TaskRepository'; @@ -8,21 +7,15 @@ import { NFSAdapter } from 'app/common/adapter/NFSAdapter'; describe('test/port/controller/PackageSyncController/showSyncTaskLog.test.ts', () => { let publisher; - let ctx: Context; let taskRepository: TaskRepository; let nfsAdapter: NFSAdapter; beforeEach(async () => { publisher = await TestUtil.createUser(); - ctx = await app.mockModuleContext(); - taskRepository = await ctx.getEggObject(TaskRepository); - nfsAdapter = await ctx.getEggObject(NFSAdapter); + taskRepository = await app.getEggObject(TaskRepository); + nfsAdapter = await app.getEggObject(NFSAdapter); mock(app.config.cnpmcore, 'syncMode', 'all'); }); - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('[GET /-/package/:fullname/syncs/:taskId/log] showSyncTaskLog()', () => { it('should 401 if user not login when alwaysAuth = true', async () => { const pkg = await TestUtil.getFullPackage({ name: '@cnpm/koa' }); diff --git a/test/port/controller/PackageTagController/removeTag.test.ts b/test/port/controller/PackageTagController/removeTag.test.ts index 39ab3661..3febe66c 100644 --- a/test/port/controller/PackageTagController/removeTag.test.ts +++ b/test/port/controller/PackageTagController/removeTag.test.ts @@ -1,18 +1,11 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; import { TestUtil } from 'test/TestUtil'; describe('test/port/controller/PackageTagController/removeTag.test.ts', () => { let publisher; - let ctx: Context; beforeEach(async () => { publisher = await TestUtil.createUser(); - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); }); describe('[DELETE /-/package/:fullname/dist-tags/:tag] removeTag()', () => { diff --git a/test/port/controller/PackageTagController/saveTag.test.ts b/test/port/controller/PackageTagController/saveTag.test.ts index 22441054..7b6f2c52 100644 --- a/test/port/controller/PackageTagController/saveTag.test.ts +++ b/test/port/controller/PackageTagController/saveTag.test.ts @@ -1,18 +1,11 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; import { TestUtil } from 'test/TestUtil'; describe('test/port/controller/PackageTagController/saveTag.test.ts', () => { let publisher; - let ctx: Context; beforeEach(async () => { publisher = await TestUtil.createUser(); - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); }); describe('[PUT /-/package/:fullname/dist-tags/:tag] saveTag()', () => { diff --git a/test/port/controller/PackageTagController/showTags.test.ts b/test/port/controller/PackageTagController/showTags.test.ts index 633691c1..638013c9 100644 --- a/test/port/controller/PackageTagController/showTags.test.ts +++ b/test/port/controller/PackageTagController/showTags.test.ts @@ -1,18 +1,11 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; import { TestUtil } from 'test/TestUtil'; describe('test/port/controller/PackageTagController/showTags.test.ts', () => { let publisher; - let ctx: Context; beforeEach(async () => { publisher = await TestUtil.createUser(); - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); }); describe('[GET /-/package/:fullname/dist-tags] showTags()', () => { diff --git a/test/port/controller/RegistryController/index.test.ts b/test/port/controller/RegistryController/index.test.ts index be49ba89..a5270c97 100644 --- a/test/port/controller/RegistryController/index.test.ts +++ b/test/port/controller/RegistryController/index.test.ts @@ -1,20 +1,17 @@ +import assert from 'assert'; +import { app } from 'egg-mock/bootstrap'; import { TaskType } from 'app/common/enum/Task'; import { Registry } from 'app/core/entity/Registry'; import { ChangesStreamTaskData } from 'app/core/entity/Task'; import { TaskService } from 'app/core/service/TaskService'; -import assert = require('assert'); -import { Context } from 'egg'; -import { app } from 'egg-mock/bootstrap'; -import { TestUtil } from '../../../TestUtil'; +import { TestUtil } from 'test/TestUtil'; describe('test/port/controller/RegistryController/index.test.ts', () => { - let ctx: Context; let adminUser: any; let registry: Registry; let taskService: TaskService; before(async () => { - ctx = await app.mockModuleContext(); - taskService = await ctx.getEggObject(TaskService); + taskService = await app.getEggObject(TaskService); }); beforeEach(async () => { adminUser = await TestUtil.createAdmin(); @@ -47,11 +44,6 @@ describe('test/port/controller/RegistryController/index.test.ts', () => { registryId: registry.registryId, }) .expect(200); - - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); }); describe('[POST /-/registry] createRegistry()', () => { diff --git a/test/port/controller/ScopeController/index.test.ts b/test/port/controller/ScopeController/index.test.ts index cec3a8f3..25cb9ee5 100644 --- a/test/port/controller/ScopeController/index.test.ts +++ b/test/port/controller/ScopeController/index.test.ts @@ -1,19 +1,16 @@ -import assert = require('assert'); +import assert from 'assert'; import { RegistryType } from 'app/common/enum/Registry'; import { RegistryManagerService } from 'app/core/service/RegistryManagerService'; -import { Context } from 'egg'; import { app } from 'egg-mock/bootstrap'; import { TestUtil } from '../../../TestUtil'; import { Scope } from 'app/core/entity/Scope'; describe('test/port/controller/ScopeController/index.test.ts', () => { - let ctx: Context; let adminUser: any; let registryManagerService: RegistryManagerService; beforeEach(async () => { - ctx = await app.mockModuleContext(); adminUser = await TestUtil.createAdmin(); - registryManagerService = await ctx.getEggObject(RegistryManagerService); + registryManagerService = await app.getEggObject(RegistryManagerService); // create registry await registryManagerService.createRegistry({ name: 'custom', @@ -24,10 +21,6 @@ describe('test/port/controller/ScopeController/index.test.ts', () => { }); }); - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('[POST /-/scope] createScope()', () => { it('should 200', async () => { diff --git a/test/port/controller/TokenController/createToken.test.ts b/test/port/controller/TokenController/createToken.test.ts index 5d5e5a97..0637c5e4 100644 --- a/test/port/controller/TokenController/createToken.test.ts +++ b/test/port/controller/TokenController/createToken.test.ts @@ -1,18 +1,8 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { TestUtil } from '../../../TestUtil'; +import { TestUtil } from 'test/TestUtil'; describe('test/port/controller/TokenController/createToken.test.ts', () => { - let ctx: Context; - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('[POST /-/npm/v1/tokens] createToken()', () => { it('should 200', async () => { const { authorization, password, ua } = await TestUtil.createUser(); diff --git a/test/port/controller/TokenController/listTokens.test.ts b/test/port/controller/TokenController/listTokens.test.ts index 997b9855..c04404bb 100644 --- a/test/port/controller/TokenController/listTokens.test.ts +++ b/test/port/controller/TokenController/listTokens.test.ts @@ -1,18 +1,8 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { TestUtil } from '../../../TestUtil'; +import { TestUtil } from 'test/TestUtil'; describe('test/port/controller/TokenController/listTokens.test.ts', () => { - let ctx: Context; - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('[GET /-/npm/v1/tokens] listTokens()', () => { it('should 401', async () => { let res = await app.httpRequest() diff --git a/test/port/controller/TokenController/removeToken.test.ts b/test/port/controller/TokenController/removeToken.test.ts index 22795248..126815c9 100644 --- a/test/port/controller/TokenController/removeToken.test.ts +++ b/test/port/controller/TokenController/removeToken.test.ts @@ -1,18 +1,8 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { TestUtil } from '../../../TestUtil'; +import { TestUtil } from 'test/TestUtil'; describe('test/port/controller/TokenController/removeToken.test.ts', () => { - let ctx: Context; - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('[DELETE /-/npm/v1/tokens/token/:tokenKey] removeToken()', () => { it('should 200', async () => { const { authorization, password, token, ua } = await TestUtil.createUser(); diff --git a/test/port/controller/UserController/loginOrCreateUser.test.ts b/test/port/controller/UserController/loginOrCreateUser.test.ts index 917e7c9a..2c976314 100644 --- a/test/port/controller/UserController/loginOrCreateUser.test.ts +++ b/test/port/controller/UserController/loginOrCreateUser.test.ts @@ -1,17 +1,7 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; describe('test/port/controller/UserController/loginOrCreateUser.test.ts', () => { - let ctx: Context; - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('[PUT /-/user/org.couchdb.user::username] loginOrCreateUser()', () => { it('should 422', async () => { let res = await app.httpRequest() diff --git a/test/port/controller/UserController/logout.test.ts b/test/port/controller/UserController/logout.test.ts index 2fc979e0..94360ee6 100644 --- a/test/port/controller/UserController/logout.test.ts +++ b/test/port/controller/UserController/logout.test.ts @@ -1,18 +1,8 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { TestUtil } from '../../../TestUtil'; +import { TestUtil } from 'test/TestUtil'; describe('test/port/controller/UserController/logout.test.ts', () => { - let ctx: Context; - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('[DELETE /-/user/token/:token] logout()', () => { it('should {ok: false} when not login', async () => { const res = await app.httpRequest() diff --git a/test/port/controller/UserController/saveProfile.test.ts b/test/port/controller/UserController/saveProfile.test.ts index 6bb663b9..de95dec9 100644 --- a/test/port/controller/UserController/saveProfile.test.ts +++ b/test/port/controller/UserController/saveProfile.test.ts @@ -1,18 +1,8 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { TestUtil } from '../../../TestUtil'; +import { TestUtil } from 'test/TestUtil'; describe('test/port/controller/UserController/saveProfile.test.ts', () => { - let ctx: Context; - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('[POST /-/npm/v1/user] saveProfile()', () => { it('should 403', async () => { const { authorization } = await TestUtil.createUser(); diff --git a/test/port/controller/UserController/showProfile.test.ts b/test/port/controller/UserController/showProfile.test.ts index ca9a4112..5d7d8f27 100644 --- a/test/port/controller/UserController/showProfile.test.ts +++ b/test/port/controller/UserController/showProfile.test.ts @@ -1,18 +1,8 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { TestUtil } from '../../../TestUtil'; +import { TestUtil } from 'test/TestUtil'; describe('test/port/controller/UserController/showProfile.test.ts', () => { - let ctx: Context; - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('[GET /-/npm/v1/user] showProfile()', () => { it('should 401', async () => { const { authorization } = await TestUtil.createUser(); diff --git a/test/port/controller/UserController/showUser.test.ts b/test/port/controller/UserController/showUser.test.ts index 65c9c6d8..07696d86 100644 --- a/test/port/controller/UserController/showUser.test.ts +++ b/test/port/controller/UserController/showUser.test.ts @@ -1,18 +1,8 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { TestUtil } from '../../../TestUtil'; +import { TestUtil } from 'test/TestUtil'; describe('test/port/controller/UserController/showUser.test.ts', () => { - let ctx: Context; - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('[GET /-/user/org.couchdb.user::username] showUser()', () => { it('should 200 when user authorized', async () => { const { authorization, name, email } = await TestUtil.createUser(); diff --git a/test/port/controller/UserController/starredByUser.test.ts b/test/port/controller/UserController/starredByUser.test.ts index 06165b5f..52f069b1 100644 --- a/test/port/controller/UserController/starredByUser.test.ts +++ b/test/port/controller/UserController/starredByUser.test.ts @@ -1,18 +1,8 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { TestUtil } from '../../../TestUtil'; +import { TestUtil } from 'test/TestUtil'; describe('test/port/controller/UserController/starredByUser.test.ts', () => { - let ctx: Context; - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('[GET /-/_view/starredByUser] starredByUser()', () => { it('should 403', async () => { const { authorization } = await TestUtil.createUser(); diff --git a/test/port/controller/UserController/whoami.test.ts b/test/port/controller/UserController/whoami.test.ts index 3526e259..efbcca99 100644 --- a/test/port/controller/UserController/whoami.test.ts +++ b/test/port/controller/UserController/whoami.test.ts @@ -1,18 +1,8 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { TestUtil } from '../../../TestUtil'; +import { TestUtil } from 'test/TestUtil'; describe('test/port/controller/UserController/whoami.test.ts', () => { - let ctx: Context; - beforeEach(async () => { - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('[GET /-/whoami] whoami()', () => { it('should 200', async () => { const { authorization, name } = await TestUtil.createUser(); diff --git a/test/port/controller/hook/HookController.test.ts b/test/port/controller/hook/HookController.test.ts index 4d64b4ba..683fb44e 100644 --- a/test/port/controller/hook/HookController.test.ts +++ b/test/port/controller/hook/HookController.test.ts @@ -1,23 +1,20 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; -import { TestUtil } from '../../../TestUtil'; -import { HookManageService } from '../../../../app/core/service/HookManageService'; -import { Hook } from '../../../../app/core/entity/Hook'; -import { UserRepository } from '../../../../app/repository/UserRepository'; -import { HookType } from '../../../../app/common/enum/Hook'; +import { TestUtil } from 'test/TestUtil'; +import { HookManageService } from 'app/core/service/HookManageService'; +import { Hook } from 'app/core/entity/Hook'; +import { UserRepository } from 'app/repository/UserRepository'; +import { HookType } from 'app/common/enum/Hook'; describe('test/port/controller/hook/HookController.test.ts', () => { - let ctx: Context; let hookManageService: HookManageService; let user; let userId; beforeEach(async () => { user = await TestUtil.createUser(); - ctx = await app.mockModuleContext(); - hookManageService = await ctx.getEggObject(HookManageService); - const userRepository = await ctx.getEggObject(UserRepository); + hookManageService = await app.getEggObject(HookManageService); + const userRepository = await app.getEggObject(UserRepository); const userEntity = await userRepository.findUserByName(user.name); userId = userEntity?.userId; }); diff --git a/test/port/controller/package/DownloadPackageVersionTarController.test.ts b/test/port/controller/package/DownloadPackageVersionTarController.test.ts index 3f3a0c2b..ce69a69f 100644 --- a/test/port/controller/package/DownloadPackageVersionTarController.test.ts +++ b/test/port/controller/package/DownloadPackageVersionTarController.test.ts @@ -1,23 +1,16 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; import { TestUtil } from 'test/TestUtil'; import { NFSClientAdapter } from 'app/infra/NFSClientAdapter'; describe('test/port/controller/package/DownloadPackageVersionTarController.test.ts', () => { - let ctx: Context; let publisher: any; let nfsClientAdapter: NFSClientAdapter; beforeEach(async () => { publisher = await TestUtil.createUser(); - ctx = await app.mockModuleContext(); nfsClientAdapter = await app.getEggObject(NFSClientAdapter); }); - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - const scopedName = '@cnpm/testmodule-download-version-tar'; const name = 'testmodule-download-version-tar'; beforeEach(async () => { diff --git a/test/port/controller/package/RemovePackageVersionController.test.ts b/test/port/controller/package/RemovePackageVersionController.test.ts index 70daaa09..ccd71e23 100644 --- a/test/port/controller/package/RemovePackageVersionController.test.ts +++ b/test/port/controller/package/RemovePackageVersionController.test.ts @@ -1,21 +1,14 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; import { TestUtil } from 'test/TestUtil'; -import { PackageRepository } from '../../../../app/repository/PackageRepository'; +import { PackageRepository } from 'app/repository/PackageRepository'; describe('test/port/controller/package/RemovePackageVersionController.test.ts', () => { - let ctx: Context; let packageRepository: PackageRepository; let publisher; beforeEach(async () => { publisher = await TestUtil.createUser(); - ctx = await app.mockModuleContext(); - packageRepository = await ctx.getEggObject(PackageRepository); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); + packageRepository = await app.getEggObject(PackageRepository); }); describe('[DELETE /:fullname/-/:filenameWithVersion.tgz/-rev/:rev] remove()', () => { diff --git a/test/port/controller/package/SavePackageVersionController.test.ts b/test/port/controller/package/SavePackageVersionController.test.ts index 1bcbc014..7ef2c8b4 100644 --- a/test/port/controller/package/SavePackageVersionController.test.ts +++ b/test/port/controller/package/SavePackageVersionController.test.ts @@ -1,21 +1,14 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; import { TestUtil } from 'test/TestUtil'; -import { UserRepository } from '../../../../app/repository/UserRepository'; +import { UserRepository } from 'app/repository/UserRepository'; describe('test/port/controller/package/SavePackageVersionController.test.ts', () => { - let ctx: Context; let userRepository: UserRepository; let publisher; beforeEach(async () => { publisher = await TestUtil.createUser(); - ctx = await app.mockModuleContext(); - userRepository = await ctx.getEggObject(UserRepository); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); + userRepository = await app.getEggObject(UserRepository); }); describe('[PUT /:fullname] save()', () => { diff --git a/test/port/controller/package/ShowPackageController.test.ts b/test/port/controller/package/ShowPackageController.test.ts index e1a09589..9f3cfb89 100644 --- a/test/port/controller/package/ShowPackageController.test.ts +++ b/test/port/controller/package/ShowPackageController.test.ts @@ -1,5 +1,4 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; import { TestUtil } from 'test/TestUtil'; import { PackageRepository } from '../../../../app/repository/PackageRepository'; @@ -9,17 +8,11 @@ import { CacheService } from '../../../../app/core/service/CacheService'; import { DistRepository } from '../../../../app/repository/DistRepository'; describe('test/port/controller/package/ShowPackageController.test.ts', () => { - let ctx: Context; let packageRepository: PackageRepository; let publisher; beforeEach(async () => { publisher = await TestUtil.createUser(); - ctx = await app.mockModuleContext(); - packageRepository = await ctx.getEggObject(PackageRepository); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); + packageRepository = await app.getEggObject(PackageRepository); }); describe('[GET /:fullname] show()', () => { diff --git a/test/port/controller/package/ShowPackageVersionController.test.ts b/test/port/controller/package/ShowPackageVersionController.test.ts index d7e9151c..2cb93c8f 100644 --- a/test/port/controller/package/ShowPackageVersionController.test.ts +++ b/test/port/controller/package/ShowPackageVersionController.test.ts @@ -1,20 +1,13 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; import { TestUtil } from 'test/TestUtil'; -import { BugVersion } from '../../../../app/core/entity/BugVersion'; -import { PackageManagerService } from '../../../../app/core/service/PackageManagerService'; +import { BugVersion } from 'app/core/entity/BugVersion'; +import { PackageManagerService } from 'app/core/service/PackageManagerService'; describe('test/port/controller/package/ShowPackageVersionController.test.ts', () => { - let ctx: Context; let publisher; beforeEach(async () => { publisher = await TestUtil.createUser(); - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); }); describe('[GET /:fullname/:versionOrTag] show()', () => { diff --git a/test/port/controller/package/UpdatePackageController.test.ts b/test/port/controller/package/UpdatePackageController.test.ts index e5126166..f4c8866c 100644 --- a/test/port/controller/package/UpdatePackageController.test.ts +++ b/test/port/controller/package/UpdatePackageController.test.ts @@ -1,18 +1,11 @@ -import assert = require('assert'); -import { Context } from 'egg'; +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; import { TestUtil } from 'test/TestUtil'; describe('test/port/controller/package/UpdatePackageController.test.ts', () => { - let ctx: Context; let publisher; beforeEach(async () => { publisher = await TestUtil.createUser(); - ctx = await app.mockModuleContext(); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); }); describe('[PUT /:fullname/-rev/:rev] update()', () => { diff --git a/test/port/middleware/AlwaysAuth.test.ts b/test/port/middleware/AlwaysAuth.test.ts index 2156da7f..9c896b7f 100644 --- a/test/port/middleware/AlwaysAuth.test.ts +++ b/test/port/middleware/AlwaysAuth.test.ts @@ -1,4 +1,4 @@ -import assert = require('assert'); +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; import { TestUtil } from '../../TestUtil'; diff --git a/test/port/middleware/Tracing.test.ts b/test/port/middleware/Tracing.test.ts index fb153ee1..0d009454 100644 --- a/test/port/middleware/Tracing.test.ts +++ b/test/port/middleware/Tracing.test.ts @@ -1,4 +1,4 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; describe('test/port/middleware/Tracing.test.ts', () => { diff --git a/test/repository/ChangeRepository.test.ts b/test/repository/ChangeRepository.test.ts index 3cc39c71..b312206b 100644 --- a/test/repository/ChangeRepository.test.ts +++ b/test/repository/ChangeRepository.test.ts @@ -1,26 +1,20 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { ChangeRepository } from 'app/repository/ChangeRepository'; import { Change as ChangeModel } from 'app/repository/model/Change'; describe('test/repository/ChangeRepository.test.ts', () => { - let ctx: Context; - let changeRepository: ChangeRepository; beforeEach(async () => { - ctx = await app.mockModuleContext(); - changeRepository = await ctx.getEggObject(ChangeRepository); + changeRepository = await app.getEggObject(ChangeRepository); await ChangeModel.truncate(); }); afterEach(async () => { await ChangeModel.truncate(); - await app.destroyModuleContext(ctx); }); - describe('query', () => { beforeEach(async () => { for (let i = 1; i < 10; i++) { diff --git a/test/repository/RegistryRepository.test.ts b/test/repository/RegistryRepository.test.ts index 6ed9b780..e20a01ca 100644 --- a/test/repository/RegistryRepository.test.ts +++ b/test/repository/RegistryRepository.test.ts @@ -1,19 +1,15 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { RegistryRepository } from 'app/repository/RegistryRepository'; import { Registry } from 'app/core/entity/Registry'; import { RegistryType } from 'app/common/enum/Registry'; describe('test/repository/RegistryRepository.test.ts', () => { - let ctx: Context; - let registryRepository: RegistryRepository; let registryModel: Registry; beforeEach(async () => { - ctx = await app.mockModuleContext(); - registryRepository = await ctx.getEggObject(RegistryRepository); + registryRepository = await app.getEggObject(RegistryRepository); registryModel = await registryRepository.saveRegistry(Registry.create({ name: 'cnpmcore', userPrefix: 'cnpm:', @@ -21,14 +17,8 @@ describe('test/repository/RegistryRepository.test.ts', () => { host: 'https://registry.npmjs.org', type: 'cnpmcore' as RegistryType, })) as Registry; - }); - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - - describe('RegistryRepository', () => { it('create work', async () => { const newRegistry = await registryRepository.saveRegistry(Registry.create({ diff --git a/test/repository/ScopeRepository.test.ts b/test/repository/ScopeRepository.test.ts index 2c361ab8..fe31495e 100644 --- a/test/repository/ScopeRepository.test.ts +++ b/test/repository/ScopeRepository.test.ts @@ -1,28 +1,20 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { ScopeRepository } from 'app/repository/ScopeRepository'; import { Scope } from 'app/core/entity/Scope'; describe('test/repository/ScopeRepository.test.ts', () => { - let ctx: Context; - let scopeRepository: ScopeRepository; let cnpmjsScope: Scope; beforeEach(async () => { - ctx = await app.mockModuleContext(); - scopeRepository = await ctx.getEggObject(ScopeRepository); + scopeRepository = await app.getEggObject(ScopeRepository); cnpmjsScope = await scopeRepository.saveScope(Scope.create({ name: '@cnpmjs', registryId: '1', })) as Scope; }); - afterEach(async () => { - await app.destroyModuleContext(ctx); - }); - describe('RegistryRepository', () => { it('create work', async () => { const cnpmScope = await scopeRepository.saveScope(Scope.create({ diff --git a/test/repository/TaskRepository.test.ts b/test/repository/TaskRepository.test.ts index a383b490..54167ff6 100644 --- a/test/repository/TaskRepository.test.ts +++ b/test/repository/TaskRepository.test.ts @@ -1,6 +1,5 @@ -import assert = require('assert'); +import assert from 'assert'; import { app } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { setTimeout } from 'timers/promises'; import { TaskRepository } from 'app/repository/TaskRepository'; import { Task as TaskModel } from 'app/repository/model/Task'; @@ -10,22 +9,17 @@ import os from 'os'; import { EasyData, EntityUtil } from '../../app/core/util/EntityUtil'; describe('test/repository/TaskRepository.test.ts', () => { - let ctx: Context; - let taskRepository: TaskRepository; beforeEach(async () => { - ctx = await app.mockModuleContext(); - taskRepository = await ctx.getEggObject(TaskRepository); + taskRepository = await app.getEggObject(TaskRepository); await TaskModel.truncate(); }); afterEach(async () => { await TaskModel.truncate(); - await app.destroyModuleContext(ctx); }); - describe('unique biz id', () => { it('should save succeed if biz id is equal', async () => { diff --git a/test/schedule/ChangesStreamWorker.test.ts b/test/schedule/ChangesStreamWorker.test.ts index e522384a..8a754145 100644 --- a/test/schedule/ChangesStreamWorker.test.ts +++ b/test/schedule/ChangesStreamWorker.test.ts @@ -1,6 +1,5 @@ -import assert = require('assert'); +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { ChangesStreamService } from 'app/core/service/ChangesStreamService'; import { TaskService } from 'app/core/service/TaskService'; import { Task } from 'app/repository/model/Task'; @@ -9,17 +8,11 @@ import { TestUtil } from 'test/TestUtil'; const ChangesStreamWorkerPath = require.resolve('../../app/port/schedule/ChangesStreamWorker'); describe('test/schedule/ChangesStreamWorker.test.ts', () => { - let ctx: Context; let changesStreamService: ChangesStreamService; let taskService: TaskService; beforeEach(async () => { - ctx = await app.mockModuleContext(); - changesStreamService = await ctx.getEggObject(ChangesStreamService); - taskService = await ctx.getEggObject(TaskService); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); + changesStreamService = await app.getEggObject(ChangesStreamService); + taskService = await app.getEggObject(TaskService); }); it('should work', async () => { diff --git a/test/schedule/CheckRecentlyUpdatedPackages.test.ts b/test/schedule/CheckRecentlyUpdatedPackages.test.ts index 59a6e10f..57f105b8 100644 --- a/test/schedule/CheckRecentlyUpdatedPackages.test.ts +++ b/test/schedule/CheckRecentlyUpdatedPackages.test.ts @@ -1,21 +1,14 @@ -import assert = require('assert'); +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; -import { Context } from 'egg'; import { PackageSyncerService } from 'app/core/service/PackageSyncerService'; import { TestUtil } from 'test/TestUtil'; const CheckRecentlyUpdatedPackagesPath = require.resolve('../../app/port/schedule/CheckRecentlyUpdatedPackages'); describe('test/schedule/CheckRecentlyUpdatedPackages.test.ts', () => { - let ctx: Context; let packageSyncerService: PackageSyncerService; beforeEach(async () => { - ctx = await app.mockModuleContext(); - packageSyncerService = await ctx.getEggObject(PackageSyncerService); - }); - - afterEach(async () => { - await app.destroyModuleContext(ctx); + packageSyncerService = await app.getEggObject(PackageSyncerService); }); it('should work', async () => { diff --git a/test/schedule/SyncPackageWorker.test.ts b/test/schedule/SyncPackageWorker.test.ts index 2686e55f..1690ead2 100644 --- a/test/schedule/SyncPackageWorker.test.ts +++ b/test/schedule/SyncPackageWorker.test.ts @@ -1,4 +1,4 @@ -import assert = require('assert'); +import assert from 'assert'; import { app, mock } from 'egg-mock/bootstrap'; import { PackageSyncerService } from 'app/core/service/PackageSyncerService'; import { TestUtil } from 'test/TestUtil'; diff --git a/tsconfig.json b/tsconfig.json index db3d70c7..bf340a93 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,12 @@ { "extends": "@eggjs/tsconfig", "compilerOptions": { + "target": "ES2020", + "module": "Node16", + "moduleResolution": "Node", "declaration": false, "resolveJsonModule": true, - "baseUrl": ".", + "baseUrl": "./", "useUnknownInCatchVariables": false }, "exclude": [ diff --git a/tsconfig.prod.json b/tsconfig.prod.json index 86b1b3d3..0d27de5c 100644 --- a/tsconfig.prod.json +++ b/tsconfig.prod.json @@ -1,11 +1,8 @@ { - "extends": "@eggjs/tsconfig", + "extends": "./tsconfig.json", "compilerOptions": { "outDir": "dist", "declaration": true, - "resolveJsonModule": true, - "baseUrl": ".", - "useUnknownInCatchVariables": false }, "exclude": [ "node_modules",