From 3f357edca7fd6b3fe1a6c920910f1b745f5c6822 Mon Sep 17 00:00:00 2001 From: MK Date: Sun, 31 Aug 2025 10:36:35 +0800 Subject: [PATCH 1/2] test: enable oxlint type-aware feature --- .gitignore | 1 + .oxlintrc.json | 95 ++------------- package.json | 12 +- src/egg.ts | 8 +- src/index.ts | 11 ++ src/lifecycle.ts | 15 ++- src/loader/context_loader.ts | 6 +- src/loader/egg_loader.ts | 26 ++-- src/loader/file_loader.ts | 6 +- src/singleton.ts | 18 +-- src/utils/timing.ts | 2 +- test/asyncLocalStorage.test.ts | 12 +- test/egg-ts.test.ts | 64 +++++----- test/index.test.ts | 12 +- test/loader/egg_loader.test.ts | 8 +- test/loader/file_loader.test.ts | 82 ++++++------- test/loader/get_appname.test.ts | 2 +- test/loader/load_file.test.ts | 2 +- test/loader/mixin/load_agent_extend.test.ts | 20 +-- .../mixin/load_application_extend.test.ts | 20 +-- test/loader/mixin/load_config.test.ts | 46 +++---- test/loader/mixin/load_controller.test.ts | 114 +++++++++--------- test/loader/mixin/load_custom_agent.test.ts | 12 +- test/loader/mixin/load_custom_app.test.ts | 12 +- test/loader/mixin/load_custom_loader.test.ts | 22 ++-- test/loader/mixin/load_extend.test.ts | 40 +++--- test/loader/mixin/load_extend_class.test.ts | 2 +- test/loader/mixin/load_middleware.test.ts | 22 ++-- test/loader/mixin/load_plugin.test.ts | 78 ++++++------ test/loader/mixin/load_service.test.ts | 20 +-- test/singleton.test.ts | 80 ++++++------ test/utils/index.test.ts | 22 ++-- test/utils/router.test.ts | 46 +++---- test/utils/timing.test.ts | 16 +-- 34 files changed, 447 insertions(+), 507 deletions(-) diff --git a/.gitignore b/.gitignore index 73a57841..61f7969e 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ lib/ .tshy* dist .package-lock.json +pnpm-lock.yaml \ No newline at end of file diff --git a/.oxlintrc.json b/.oxlintrc.json index 89516a53..b6fc10e6 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -4,39 +4,15 @@ "node": true, "mocha": true }, - "categories": { - "correctness": "error", - "perf": "error", - "nursery": "error", - "restriction": "error", - "style": "error", - "pedantic": "error", - "suspicious": "error" - }, - "plugins": [ - "import", - "typescript", - "unicorn", - "jsdoc", - "node", - "promise", - "oxc" - ], + "extends": ["./node_modules/@eggjs/oxlint-config/.oxlintrc.json"], "rules": { // eslint - "constructor-super": "error", - "getter-return": "error", - "no-undef": "error", - "no-unreachable": "error", - "no-var": "error", - "no-eq-null": "error", "no-await-in-loop": "allow", "eqeqeq": ["error", "smart"], "init-declarations": "allow", "curly": "allow", "no-ternary": "allow", - "max-params": ["error", 5], - "no-await-expression-member": "error", + "max-params": ["error", 8], "no-continue": "allow", "guard-for-in": "allow", "func-style": "allow", @@ -44,77 +20,45 @@ "yoda": "allow", "sort-keys": "allow", "no-magic-numbers": "allow", - "no-duplicate-imports": "error", - "no-multi-assign": "error", - "func-names": "error", - "default-param-last": "error", - "prefer-object-spread": "error", "no-undefined": "allow", "no-plusplus": "allow", "no-console": "allow", "no-extraneous-class": "allow", - "no-empty-function": "error", "max-depth": ["error", 6], "max-lines-per-function": "allow", - "no-lonely-if": "error", "max-lines": "allow", "require-await": "allow", - "max-nested-callbacks": ["error", 5], + "max-nested-callbacks": ["error", 6], "max-classes-per-file": "allow", "radix": "allow", - "no-negated-condition": "error", - "no-else-return": "error", - "no-throw-literal": "error", + "prefer-template": "allow", + "new-cap": "allow", // import "import/exports-last": "allow", "import/max-dependencies": "allow", - "import/no-cycle": "error", "import/no-anonymous-default-export": "allow", - "import/no-namespace": "error", - "import/named": "error", - "import/export": "error", "import/no-default-export": "allow", - "import/unambiguous": "error", // promise - "promise/no-return-wrap": "error", - "promise/param-names": "error", "promise/prefer-await-to-callbacks": "allow", - "promise/prefer-await-to-then": "error", - "promise/prefer-catch": "error", - "promise/no-return-in-finally": "error", - "promise/avoid-new": "error", + "promise/avoid-new": "allow", + "promise/always-return": "allow", // unicorn - "unicorn/error-message": "error", "unicorn/no-null": "allow", "unicorn/filename-case": "allow", - "unicorn/prefer-structured-clone": "error", - "unicorn/prefer-logical-operator-over-ternary": "error", - "unicorn/prefer-number-properties": "error", - "unicorn/prefer-array-some": "error", - "unicorn/prefer-string-slice": "error", + "unicorn/switch-case-braces": ["error", "avoid"], // "unicorn/no-null": "error", - "unicorn/throw-new-error": "error", "unicorn/catch-error-name": "allow", "unicorn/prefer-spread": "allow", - "unicorn/numeric-separators-style": "error", - "unicorn/prefer-string-raw": "error", - "unicorn/text-encoding-identifier-case": "error", - "unicorn/no-array-for-each": "error", - "unicorn/explicit-length-check": "error", - "unicorn/no-lonely-if": "error", "unicorn/no-useless-undefined": "allow", - "unicorn/prefer-date-now": "error", "unicorn/no-static-only-class": "allow", - "unicorn/no-typeof-undefined": "error", - "unicorn/prefer-negative-index": "error", "unicorn/no-anonymous-default-export": "allow", "unicorn/prefer-event-target": "allow", + "unicorn/no-array-for-each": "allow", // oxc - "oxc/no-map-spread": "error", "oxc/no-rest-spread-properties": "allow", "oxc/no-optional-chaining": "allow", "oxc/no-async-await": "allow", @@ -122,33 +66,14 @@ // typescript "typescript/explicit-function-return-type": "allow", - "typescript/consistent-type-imports": "error", - "typescript/consistent-type-definitions": "error", "typescript/consistent-indexed-object-style": "allow", - "typescript/no-inferrable-types": "error", - "typescript/array-type": "error", - "typescript/no-non-null-assertion": "error", "typescript/no-explicit-any": "allow", - "typescript/no-import-type-side-effects": "error", - "typescript/no-dynamic-delete": "error", - "typescript/prefer-ts-expect-error": "error", - "typescript/ban-ts-comment": "error", - "typescript/prefer-enum-initializers": "error", + "typescript/no-unnecessary-boolean-literal-compare": "allow", // jsdoc "jsdoc/require-returns": "allow", "jsdoc/require-param": "allow" }, - "overrides": [ - { - "rules": { - "unicorn/no-array-for-each": "allow", - "promise/avoid-new": "allow", - "max-nested-callbacks": "allow" - }, - "files": ["test/**/*.ts"] - } - ], "ignorePatterns": [ "index.d.ts", "test/fixtures/**", diff --git a/package.json b/package.json index 9bc629dc..11c8e1ff 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "description": "A core plugin framework based on @eggjs/koa", "scripts": { "clean": "rimraf dist", - "lint": "oxlint", + "lint": "oxlint --type-aware", "pretest": "npm run clean && npm run lint -- --fix && npm run prepublishOnly", "test": "egg-bin test", "posttest": "npm run clean", @@ -61,6 +61,7 @@ "devDependencies": { "@arethetypeswrong/cli": "^0.17.4", "@eggjs/bin": "7", + "@eggjs/oxlint-config": "^1.0.0", "@eggjs/supertest": "^8.1.1", "@eggjs/tsconfig": "1", "@types/js-yaml": "4", @@ -68,14 +69,15 @@ "@types/node": "22", "await-event": "2", "coffee": "5", - "husky": "9", - "lint-staged": "15", - "oxlint": "^0.16.2", - "prettier": "3", "gals": "1", + "husky": "9", "js-yaml": "3", + "lint-staged": "15", "mm": "^4.0.2", + "oxlint": "^1.14.0", + "oxlint-tsgolint": "^0.1.5", "pedding": "2", + "prettier": "3", "rimraf": "6", "ts-node": "10", "tshy": "3", diff --git a/src/egg.ts b/src/egg.ts index 81902ea5..db7df1da 100644 --- a/src/egg.ts +++ b/src/egg.ts @@ -137,13 +137,13 @@ export class EggCore extends KoaApplication { constructor(options: EggCoreInitOptions = {}) { options.baseDir = options.baseDir ?? process.cwd(); options.type = options.type ?? 'application'; - assert( + assert.ok( typeof options.baseDir === 'string', 'options.baseDir required, and must be a string' ); // assert(fs.existsSync(options.baseDir), `Directory ${options.baseDir} not exists`); // assert(fs.statSync(options.baseDir).isDirectory(), `Directory ${options.baseDir} is not a directory`); - assert( + assert.ok( options.type === 'application' || options.type === 'agent', 'options.type should be application or agent' ); @@ -219,7 +219,7 @@ export class EggCore extends KoaApplication { * @since 1.0.0 */ const Loader = this[EGG_LOADER]; - assert(Loader, "Symbol.for('egg#loader') is required"); + assert.ok(Loader, "Symbol.for('egg#loader') is required"); this.loader = new Loader({ baseDir: options.baseDir, app: this, @@ -264,7 +264,7 @@ export class EggCore extends KoaApplication { * @since 1.0.0 */ use(fn: MiddlewareFunc) { - assert(typeof fn === 'function', 'app.use() requires a function'); + assert.ok(typeof fn === 'function', 'app.use() requires a function'); debug('[use] add middleware: %o', fn._name || fn.name || '-'); this.middleware.push(fn as unknown as KoaMiddlewareFunc); return this; diff --git a/src/index.ts b/src/index.ts index 4c060742..e7937520 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,3 +12,14 @@ export * from './loader/context_loader.js'; export * from './utils/sequencify.js'; export * from './utils/timing.js'; export type * from './types.js'; + +export default function hello() { + const a = { + b: 1, + c: 2, + }; + + const b = a.b; + + return b; +} diff --git a/src/lifecycle.ts b/src/lifecycle.ts index aeabcd88..5ce36e07 100644 --- a/src/lifecycle.ts +++ b/src/lifecycle.ts @@ -7,8 +7,7 @@ import { Ready as ReadyObject, type ReadyFunctionArg } from 'get-ready'; import { Ready } from 'ready-callback'; import { EggConsoleLogger } from 'egg-logger'; -import utils from './utils/index.js'; -import type { Fun } from './utils/index.js'; +import utils, { type Fun } from './utils/index.js'; import type { EggCore } from './egg.js'; const debug = debuglog('@eggjs/core/lifecycle'); @@ -93,7 +92,7 @@ export class Lifecycle extends EventEmitter { const eggReadyTimeoutEnv = Number.parseInt( process.env.EGG_READY_TIMEOUT_ENV || '10000' ); - assert( + assert.ok( Number.isInteger(eggReadyTimeoutEnv), `process.env.EGG_READY_TIMEOUT_ENV ${process.env.EGG_READY_TIMEOUT_ENV} should be able to parseInt.` ); @@ -159,7 +158,7 @@ export class Lifecycle extends EventEmitter { } addBootHook(bootHootOrBootClass: BootImplClass | ILifecycleBoot) { - assert( + assert.ok( this.#init === false, 'do not add hook when lifecycle has been initialized' ); @@ -170,7 +169,7 @@ export class Lifecycle extends EventEmitter { hook: (app: T) => void, fullPath?: string ) { - assert( + assert.ok( this.#init === false, 'do not add hook when lifecycle has been initialized' ); @@ -195,7 +194,7 @@ export class Lifecycle extends EventEmitter { */ init() { debug('%s init lifecycle', this.app.type); - assert(this.#init === false, 'lifecycle have been init'); + assert.ok(this.#init === false, 'lifecycle have been init'); this.#init = true; this.#boots = this.#bootHooks.map(BootHootOrBootClass => { let instance = BootHootOrBootClass as ILifecycleBoot; @@ -221,8 +220,8 @@ export class Lifecycle extends EventEmitter { } registerBeforeClose(fn: FunWithFullPath, fullPath?: string) { - assert(typeof fn === 'function', 'argument should be function'); - assert(this.#isClosed === false, 'app has been closed'); + assert.ok(typeof fn === 'function', 'argument should be function'); + assert.ok(this.#isClosed === false, 'app has been closed'); if (fullPath) { fn.fullPath = fullPath; } diff --git a/src/loader/context_loader.ts b/src/loader/context_loader.ts index c5a3577c..5e6eb12f 100644 --- a/src/loader/context_loader.ts +++ b/src/loader/context_loader.ts @@ -15,7 +15,7 @@ export class ClassLoader { _ctx: Context; constructor(options: ClassLoaderOptions) { - assert(options.ctx, 'options.ctx is required'); + assert.ok(options.ctx, 'options.ctx is required'); const properties = options.properties; this._ctx = options.ctx; @@ -62,8 +62,8 @@ export class ContextLoader extends FileLoader { * @param {String} options.fieldClass - determine the field name of inject object. */ constructor(options: ContextLoaderOptions) { - assert(options.property, 'options.property is required'); - assert(options.inject, 'options.inject is required'); + assert.ok(options.property, 'options.property is required'); + assert.ok(options.inject, 'options.inject is required'); const target = {}; if (options.fieldClass) { options.inject[options.fieldClass] = target; diff --git a/src/loader/egg_loader.ts b/src/loader/egg_loader.ts index b2991a13..c0284757 100644 --- a/src/loader/egg_loader.ts +++ b/src/loader/egg_loader.ts @@ -93,12 +93,12 @@ export class EggLoader { */ constructor(options: EggLoaderOptions) { this.options = options; - assert( + assert.ok( fs.existsSync(this.options.baseDir), `${this.options.baseDir} not exists` ); - assert(this.options.app, 'options.app is required'); - assert(this.options.logger, 'options.logger is required'); + assert.ok(this.options.app, 'options.app is required'); + assert.ok(this.options.logger, 'options.logger is required'); this.timing = this.app.timing || new Timing(); @@ -360,11 +360,11 @@ export class EggLoader { // } continue; } - assert( + assert.ok( typeof eggPath === 'string', "Symbol.for('egg#eggPath') should be string" ); - assert(fs.existsSync(eggPath), `${eggPath} not exists`); + assert.ok(fs.existsSync(eggPath), `${eggPath} not exists`); const realpath = fs.realpathSync(eggPath); if (!eggPaths.includes(realpath)) { eggPaths.unshift(realpath); @@ -795,7 +795,7 @@ export class EggLoader { } if (plugin.package) { - assert( + assert.ok( isValidatePackageName(plugin.package), `plugin ${plugin.name} invalid, use 'path' instead of package: "${plugin.package}"` ); @@ -1021,13 +1021,13 @@ export class EggLoader { ); if (!config) return; if (isPlugin || isApp) { - assert( + assert.ok( !config.coreMiddleware, 'Can not define coreMiddleware in app or plugin' ); } if (!isApp) { - assert(!config.middleware, 'Can not define middleware in ' + filepath); + assert.ok(!config.middleware, 'Can not define middleware in ' + filepath); } // store config meta, check where is the property of config come from. this.#setConfigMeta(config, filepath); @@ -1436,7 +1436,7 @@ export class EggLoader { middlewaresMap.set(name, true); const options = this.config[name] || {}; let mw: MiddlewareFunc | null = createMiddleware(options, app); - assert( + assert.ok( typeof mw === 'function', `Middleware ${name} must be a function, but actual is ${inspect(mw)}` ); @@ -1568,14 +1568,14 @@ export class EggLoader { /** start CustomLoader loader */ async loadCustomLoader() { - assert(this.config, 'should loadConfig first'); + assert.ok(this.config, 'should loadConfig first'); const customLoader = this.config.customLoader || {}; for (const property of Object.keys(customLoader)) { const loaderConfig = { ...customLoader[property], }; - assert( + assert.ok( loaderConfig.directory, `directory is required for config.customLoader.${property}` ); @@ -1597,7 +1597,7 @@ export class EggLoader { switch (inject) { case 'ctx': { - assert( + assert.ok( !(property in this.app.context), `customLoader should not override ctx.${property}` ); @@ -1611,7 +1611,7 @@ export class EggLoader { break; } case 'app': { - assert( + assert.ok( !(property in this.app), `customLoader should not override app.${property}` ); diff --git a/src/loader/file_loader.ts b/src/loader/file_loader.ts index 8139a905..c97680b9 100644 --- a/src/loader/file_loader.ts +++ b/src/loader/file_loader.ts @@ -95,8 +95,8 @@ export class FileLoader { * @param {String|Function} options.caseStyle - set property's case when converting a filepath to property list. */ constructor(options: FileLoaderOptions) { - assert(options.directory, 'options.directory is required'); - assert(options.target, 'options.target is required'); + assert.ok(options.directory, 'options.directory is required'); + assert.ok(options.target, 'options.target is required'); this.options = { caseStyle: CaseStyle.camel, call: true, @@ -267,7 +267,7 @@ function getProperties( // if caseStyle is function, return the result of function if (typeof caseStyle === 'function') { const result = caseStyle(filepath); - assert( + assert.ok( Array.isArray(result), `caseStyle expect an array, but got ${JSON.stringify(result)}` ); diff --git a/src/singleton.ts b/src/singleton.ts index 3e81eb7a..f0330287 100644 --- a/src/singleton.ts +++ b/src/singleton.ts @@ -22,19 +22,19 @@ export class Singleton { readonly options: Record; constructor(options: SingletonOptions) { - assert( + assert.ok( options.name, '[@eggjs/core/singleton] Singleton#constructor options.name is required' ); - assert( + assert.ok( options.app, '[@eggjs/core/singleton] Singleton#constructor options.app is required' ); - assert( + assert.ok( options.create, '[@eggjs/core/singleton] Singleton#constructor options.create is required' ); - assert( + assert.ok( !(options.name in options.app), `[@eggjs/core/singleton] ${options.name} is already exists in app` ); @@ -50,7 +50,7 @@ export class Singleton { initSync() { const options = this.options; - assert( + assert.ok( !(options.client && options.clients), `[@eggjs/core/singleton] ${this.name} can not set options.client and options.clients both` ); @@ -79,7 +79,7 @@ export class Singleton { async initAsync() { const options = this.options; - assert( + assert.ok( !(options.client && options.clients), `[@eggjs/core/singleton] ${this.name} can not set options.client and options.clients both` ); @@ -132,7 +132,7 @@ export class Singleton { createInstance(config: Record, clientName: string) { // async creator only support createInstanceAsync - assert( + assert.ok( !isAsyncFunction(this.create), `[@eggjs/core/singleton] ${this.name} only support asynchronous creation, please use createInstanceAsync` ); @@ -158,11 +158,11 @@ export class Singleton { } #extendDynamicMethods(client: any) { - assert( + assert.ok( !client.createInstance, '[@eggjs/core/singleton] singleton instance should not have createInstance method' ); - assert( + assert.ok( !client.createInstanceAsync, '[@eggjs/core/singleton] singleton instance should not have createInstanceAsync method' ); diff --git a/src/utils/timing.ts b/src/utils/timing.ts index 0f1f43dc..23f0149a 100644 --- a/src/utils/timing.ts +++ b/src/utils/timing.ts @@ -69,7 +69,7 @@ export class Timing { end(name?: string) { if (!name || !this.#enable) return; const item = this.#map.get(name); - assert(item, `should run timing.start('${name}') first`); + assert.ok(item, `should run timing.start('${name}') first`); item.end = Date.now(); item.duration = item.end - item.start; debug('end %j', item); diff --git a/test/asyncLocalStorage.test.ts b/test/asyncLocalStorage.test.ts index 3d02df5e..8118bb4b 100644 --- a/test/asyncLocalStorage.test.ts +++ b/test/asyncLocalStorage.test.ts @@ -24,20 +24,20 @@ describe('test/asyncLocalStorage.test.ts', () => { assert.equal(res.status, 200); // console.log(res.body); assert.equal(res.body.sessionId, 'mock-session-id-123'); - assert(res.body.traceId); + assert.ok(res.body.traceId); assert.equal(app.currentContext, undefined); }); it('should access als on global', async () => { - assert(Reflect.get(global, Symbol.for('gals#asyncLocalStorage'))); - assert(Reflect.get(global, kGALS)); - assert( - Reflect.get(global, Symbol.for('gals#asyncLocalStorage')) instanceof + assert.ok(Reflect.get(globalThis, Symbol.for('gals#asyncLocalStorage'))); + assert.ok(Reflect.get(globalThis, kGALS)); + assert.ok( + Reflect.get(globalThis, Symbol.for('gals#asyncLocalStorage')) instanceof AsyncLocalStorage ); assert.equal( app.ctxStorage, - Reflect.get(global, Symbol.for('gals#asyncLocalStorage')) + Reflect.get(globalThis, Symbol.for('gals#asyncLocalStorage')) ); assert.equal(app.ctxStorage, getAsyncLocalStorage()); }); diff --git a/test/egg-ts.test.ts b/test/egg-ts.test.ts index 5cbbd9fe..14d3d349 100644 --- a/test/egg-ts.test.ts +++ b/test/egg-ts.test.ts @@ -50,17 +50,17 @@ describe('test/egg-ts.test.ts', () => { await request(app.callback()) .get('/') .expect(res => { - assert(res.text.includes('from extend context')); - assert(res.text.includes('from extend application')); - assert(res.text.includes('from extend request')); - assert(res.text.includes('from extend agent')); - assert(res.text.includes('from extend helper')); - assert(res.text.includes('from extend response')); - assert(res.text.includes('from custom app')); - assert(res.text.includes('from plugins')); - assert(res.text.includes('from config.default')); - assert(res.text.includes('from middleware')); - assert(res.text.includes('from service')); + assert.ok(res.text.includes('from extend context')); + assert.ok(res.text.includes('from extend application')); + assert.ok(res.text.includes('from extend request')); + assert.ok(res.text.includes('from extend agent')); + assert.ok(res.text.includes('from extend helper')); + assert.ok(res.text.includes('from extend response')); + assert.ok(res.text.includes('from custom app')); + assert.ok(res.text.includes('from plugins')); + assert.ok(res.text.includes('from config.default')); + assert.ok(res.text.includes('from middleware')); + assert.ok(res.text.includes('from service')); }) .expect(200); }); @@ -91,17 +91,17 @@ describe('test/egg-ts.test.ts', () => { .get('/') .expect(res => { // console.log(res.text); - assert(res.text.includes('from extend context')); - assert(res.text.includes('from extend application')); - assert(res.text.includes('from extend request')); - assert(res.text.includes('from extend agent')); - assert(res.text.includes('from extend helper')); - assert(res.text.includes('from extend response')); - assert(res.text.includes('from custom agent')); - assert(res.text.includes('from plugins')); - assert(res.text.includes('from config.default')); - assert(res.text.includes('from middleware')); - assert(res.text.includes('from service')); + assert.ok(res.text.includes('from extend context')); + assert.ok(res.text.includes('from extend application')); + assert.ok(res.text.includes('from extend request')); + assert.ok(res.text.includes('from extend agent')); + assert.ok(res.text.includes('from extend helper')); + assert.ok(res.text.includes('from extend response')); + assert.ok(res.text.includes('from custom agent')); + assert.ok(res.text.includes('from plugins')); + assert.ok(res.text.includes('from config.default')); + assert.ok(res.text.includes('from middleware')); + assert.ok(res.text.includes('from service')); }) .expect(200); }); @@ -113,8 +113,8 @@ describe('test/egg-ts.test.ts', () => { app = createApp('egg-ts-js'); await app.loader.loadController(); - assert(!app.controller.god); - assert(app.controller.test); + assert.ok(!app.controller.god); + assert.ok(app.controller.test); }); it('should support load ts,js files', async () => { @@ -122,8 +122,8 @@ describe('test/egg-ts.test.ts', () => { app = createApp('egg-ts-js'); await app.loader.loadService(); - assert(app.serviceClasses.lord); - assert(app.serviceClasses.test); + assert.ok(app.serviceClasses.lord); + assert.ok(app.serviceClasses.test); }); it('should auto require tsconfig-paths', async () => { @@ -131,8 +131,8 @@ describe('test/egg-ts.test.ts', () => { app = createApp('egg-ts-js-tsconfig-paths'); await app.loader.loadService(); - assert(app.serviceClasses.lord); - assert(app.serviceClasses.test); + assert.ok(app.serviceClasses.lord); + assert.ok(app.serviceClasses.test); }); it.skip('should not load ts files while EGG_TYPESCRIPT was not exist', async () => { @@ -141,8 +141,8 @@ describe('test/egg-ts.test.ts', () => { await app.loader.loadApplicationExtend(); await app.loader.loadService(); assert.equal((app as any).appExtend, undefined); - assert(app.serviceClasses.lord); - assert(!app.serviceClasses.test); + assert.ok(app.serviceClasses.lord); + assert.ok(!app.serviceClasses.test); }); it.skip('should not load ts files while EGG_TYPESCRIPT was true but no extensions', async () => { @@ -150,8 +150,8 @@ describe('test/egg-ts.test.ts', () => { mm(utils, 'extensions', ['.js', '.json']); app = createApp('egg-ts-js'); await app.loader.loadService(); - assert(app.serviceClasses.lord); - assert(!app.serviceClasses.test); + assert.ok(app.serviceClasses.lord); + assert.ok(!app.serviceClasses.test); }); it.skip('should compile app-ts without error', async () => { diff --git a/test/index.test.ts b/test/index.test.ts index bc66d08b..6af36e83 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -5,10 +5,10 @@ import type { EggAppConfig } from '../src/index.js'; describe('test/index.test.ts', () => { it('should expose properties', () => { - assert(EggCore.EggCore); - assert(EggCore.EggLoader); - assert(EggCore.BaseContextClass); - assert(EggCore.utils); + assert.ok(EggCore.EggCore); + assert.ok(EggCore.EggLoader); + assert.ok(EggCore.BaseContextClass); + assert.ok(EggCore.utils); console.log(Object.keys(EggCore)); assert.deepEqual(Object.keys(EggCore), [ 'BaseContextClass', @@ -42,7 +42,7 @@ describe('test/index.test.ts', () => { coreMiddleware: [], middleware: [], } as EggAppConfig; - assert(config.middleware); - assert(config.coreMiddleware); + assert.ok(config.middleware); + assert.ok(config.coreMiddleware); }); }); diff --git a/test/loader/egg_loader.test.ts b/test/loader/egg_loader.test.ts index f88a8fa6..937cd63f 100644 --- a/test/loader/egg_loader.test.ts +++ b/test/loader/egg_loader.test.ts @@ -17,8 +17,8 @@ describe('test/loader/egg_loader.test.ts', () => { after(() => app.close()); it('should container FileLoader and ContextLoader', () => { - assert(app.loader.FileLoader); - assert(app.loader.ContextLoader); + assert.ok(app.loader.FileLoader); + assert.ok(app.loader.ContextLoader); }); describe('loader.getHomedir()', () => { @@ -95,7 +95,7 @@ describe('test/loader/egg_loader.test.ts', () => { logger: console, } as any); await loader.loadToApp(directory, prop); - assert(Reflect.get(app, prop).user); + assert.ok(Reflect.get(app, prop).user); }); it('should be loaded by loadToContext', async () => { @@ -109,6 +109,6 @@ describe('test/loader/egg_loader.test.ts', () => { logger: console, } as any); await loader.loadToContext(directory, prop); - assert(Reflect.get(app.context, prop).user); + assert.ok(Reflect.get(app.context, prop).user); }); }); diff --git a/test/loader/file_loader.test.ts b/test/loader/file_loader.test.ts index 1b575345..81daa63f 100644 --- a/test/loader/file_loader.test.ts +++ b/test/loader/file_loader.test.ts @@ -17,16 +17,16 @@ describe('test/loader/file_loader.test.ts', () => { target: services, }).load(); - assert(services.dir.abc); - assert(services.dir.service); - assert(services.foo); - assert(services.fooBarHello); - assert(services.fooService); - assert(services.hyphenDir.a); - assert(services.underscoreDir.a); - assert(services.userProfile); - assert('load' in services.dir.service); - assert('app' in services.dir.service); + assert.ok(services.dir.abc); + assert.ok(services.dir.service); + assert.ok(services.foo); + assert.ok(services.fooBarHello); + assert.ok(services.fooService); + assert.ok(services.hyphenDir.a); + assert.ok(services.underscoreDir.a); + assert.ok(services.userProfile); + assert.ok('load' in services.dir.service); + assert.ok('app' in services.dir.service); assert.equal(services.dir.service.load, true); await Promise.all([ @@ -130,10 +130,10 @@ describe('test/loader/file_loader.test.ts', () => { call: false, // filters: [ 'm1', 'm2', 'dm1', 'dm2' ], }).load(); - assert(app.middlewares.m1); - assert(app.middlewares.m2); - assert(app.middlewares.dm1); - assert(app.middlewares.dm2); + assert.ok(app.middlewares.m1); + assert.ok(app.middlewares.m2); + assert.ok(app.middlewares.dm1); + assert.ok(app.middlewares.dm2); }); it('should support ignore string', async () => { @@ -163,9 +163,9 @@ describe('test/loader/file_loader.test.ts', () => { target: app.services, lowercaseFirst: true, }).load(); - assert(app.services.someClass); - assert(app.services.someDir); - assert(app.services.someDir.someSubClass); + assert.ok(app.services.someClass); + assert.ok(app.services.someDir); + assert.ok(app.services.someDir.someSubClass); }); it('should support options.initializer with es6 class', async () => { @@ -178,7 +178,7 @@ describe('test/loader/file_loader.test.ts', () => { return new exports(app, opt.path); }, }).load(); - assert(app.dao.TestClass); + assert.ok(app.dao.TestClass); assert.deepEqual(app.dao.TestClass.user, { name: 'kai.fangk' }); assert.equal(app.dao.TestClass.app, app); assert.equal( @@ -199,7 +199,7 @@ describe('test/loader/file_loader.test.ts', () => { return yaml.load(exports.toString()); }, }).load(); - assert(app.yml.config); + assert.ok(app.yml.config); assert.deepEqual(app.yml.config.map, { a: 1, b: 2 }); }); @@ -220,7 +220,7 @@ describe('test/loader/file_loader.test.ts', () => { }).load(); assert.equal(app.model.mod.a, 1); assert.equal(app.model.mod2.foo, 'bar'); - assert(app.model.mod2.HelloFoo); + assert.ok(app.model.mod2.HelloFoo); assert.equal(app.model.mod3.ok, true); assert.equal(app.model.mod3.foo, 'bar'); }); @@ -280,10 +280,10 @@ describe('test/loader/file_loader.test.ts', () => { caseStyle: CaseStyle.upper, }).load(); - assert(target.FooBar1); - assert(target.FooBar2); - assert(target.FooBar3); - assert(target.FooBar4); + assert.ok(target.FooBar1); + assert.ok(target.FooBar2); + assert.ok(target.FooBar3); + assert.ok(target.FooBar4); }); it('should load when caseStyle = camel', async () => { @@ -294,10 +294,10 @@ describe('test/loader/file_loader.test.ts', () => { caseStyle: CaseStyle.camel, }).load(); - assert(target.fooBar1); - assert(target.fooBar2); - assert(target.FooBar3); - assert(target.fooBar4); + assert.ok(target.fooBar1); + assert.ok(target.fooBar2); + assert.ok(target.FooBar3); + assert.ok(target.fooBar4); }); it('should load when caseStyle = lower', async () => { @@ -308,10 +308,10 @@ describe('test/loader/file_loader.test.ts', () => { caseStyle: CaseStyle.lower, }).load(); - assert(target.fooBar1); - assert(target.fooBar2); - assert(target.fooBar3); - assert(target.fooBar4); + assert.ok(target.fooBar1); + assert.ok(target.fooBar2); + assert.ok(target.fooBar3); + assert.ok(target.fooBar4); }); it('should load when caseStyle is function', async () => { @@ -327,10 +327,10 @@ describe('test/loader/file_loader.test.ts', () => { }, }).load(); - assert(target.foobar1); - assert(target.fooBar2); - assert(target.FooBar3); - assert(target['foo-bar4']); + assert.ok(target.foobar1); + assert.ok(target.fooBar2); + assert.ok(target.FooBar3); + assert.ok(target['foo-bar4']); }); it('should throw when caseStyle do not return array', async () => { @@ -355,10 +355,10 @@ describe('test/loader/file_loader.test.ts', () => { lowercaseFirst: true, }).load(); - assert(target.fooBar1); - assert(target.fooBar2); - assert(target.fooBar3); - assert(target.fooBar4); + assert.ok(target.fooBar1); + assert.ok(target.fooBar2); + assert.ok(target.fooBar3); + assert.ok(target.fooBar4); }); }); @@ -374,7 +374,7 @@ describe('test/loader/file_loader.test.ts', () => { assert.equal(inject.b, true); const instance = new target.a(inject); - assert(instance); + assert.ok(instance); assert.equal(inject.a, true); }); diff --git a/test/loader/get_appname.test.ts b/test/loader/get_appname.test.ts index 1cae2158..2ca82480 100644 --- a/test/loader/get_appname.test.ts +++ b/test/loader/get_appname.test.ts @@ -16,7 +16,7 @@ describe('test/loader/get_appname.test.ts', () => { try { createApp('app-noname'); } catch (err: any) { - assert(err.message.includes(`name is required from ${pkg}`)); + assert.ok(err.message.includes(`name is required from ${pkg}`)); done(); } }); diff --git a/test/loader/load_file.test.ts b/test/loader/load_file.test.ts index d35db6ed..aea1f0bf 100644 --- a/test/loader/load_file.test.ts +++ b/test/loader/load_file.test.ts @@ -63,7 +63,7 @@ describe('test/loader/load_file.test.ts', () => { const result = await app.loader.loadFile( getFilepath('load_file/es-module-default.js') ); - assert(result.fn); + assert.ok(result.fn); }); it('should load compiled es module file which default = null', async () => { diff --git a/test/loader/mixin/load_agent_extend.test.ts b/test/loader/mixin/load_agent_extend.test.ts index f73762db..8b0214b9 100644 --- a/test/loader/mixin/load_agent_extend.test.ts +++ b/test/loader/mixin/load_agent_extend.test.ts @@ -12,21 +12,21 @@ describe('test/loader/mixin/load_agent_extend.test.ts', () => { after(() => agent.close()); it('should load extend from chair, plugin and agent', () => { - assert(agent.poweredBy); - assert(agent.a); - assert(agent.b); - assert(agent.foo); - assert(agent.bar); + assert.ok(agent.poweredBy); + assert.ok(agent.a); + assert.ok(agent.b); + assert.ok(agent.foo); + assert.ok(agent.bar); }); it('should override chair by plugin', () => { - assert(agent.a === 'plugin a'); - assert(agent.b === 'plugin b'); - assert(agent.poweredBy === 'plugin a'); + assert.ok(agent.a === 'plugin a'); + assert.ok(agent.b === 'plugin b'); + assert.ok(agent.poweredBy === 'plugin a'); }); it('should override plugin by agent', () => { - assert(agent.foo === 'agent bar'); - assert(agent.bar === 'foo'); + assert.ok(agent.foo === 'agent bar'); + assert.ok(agent.bar === 'foo'); }); }); diff --git a/test/loader/mixin/load_application_extend.test.ts b/test/loader/mixin/load_application_extend.test.ts index b2abc886..81ed5aea 100644 --- a/test/loader/mixin/load_application_extend.test.ts +++ b/test/loader/mixin/load_application_extend.test.ts @@ -12,21 +12,21 @@ describe('test/loader/mixin/load_application_extend.test.ts', () => { after(() => app.close()); it('should load extend from chair, plugin and application', () => { - assert(app.poweredBy); - assert(app.a); - assert(app.b); - assert(app.foo); - assert(app.bar); + assert.ok(app.poweredBy); + assert.ok(app.a); + assert.ok(app.b); + assert.ok(app.foo); + assert.ok(app.bar); }); it('should override chair by plugin', () => { - assert(app.a === 'plugin a'); - assert(app.b === 'plugin b'); - assert(app.poweredBy === 'plugin a'); + assert.ok(app.a === 'plugin a'); + assert.ok(app.b === 'plugin b'); + assert.ok(app.poweredBy === 'plugin a'); }); it('should override plugin by app', () => { - assert(app.foo === 'app bar'); - assert(app.bar === 'foo'); + assert.ok(app.foo === 'app bar'); + assert.ok(app.bar === 'foo'); }); }); diff --git a/test/loader/mixin/load_config.test.ts b/test/loader/mixin/load_config.test.ts index cd01e95e..2d928122 100644 --- a/test/loader/mixin/load_config.test.ts +++ b/test/loader/mixin/load_config.test.ts @@ -16,8 +16,8 @@ describe('test/loader/mixin/load_config.test.ts', () => { const loader = app.loader; await loader.loadPlugin(); await loader.loadConfig(); - assert(loader.config.name === 'config-test'); - assert(loader.config.test === 1); + assert.ok(loader.config.name === 'config-test'); + assert.ok(loader.config.test === 1); // 支持嵌套覆盖 assert.deepEqual(loader.config.urllib, { keepAlive: false, @@ -33,7 +33,7 @@ describe('test/loader/mixin/load_config.test.ts', () => { const loader = app.loader; await loader.loadPlugin(); await loader.loadConfig(); - assert(loader.config.name === 'override default'); + assert.ok(loader.config.name === 'override default'); }); it('should load application config overriding plugin', async () => { @@ -41,7 +41,7 @@ describe('test/loader/mixin/load_config.test.ts', () => { const loader = app.loader; await loader.loadPlugin(); await loader.loadConfig(); - assert(loader.config.plugin === 'override plugin'); + assert.ok(loader.config.plugin === 'override plugin'); }); // egg config.default @@ -53,7 +53,7 @@ describe('test/loader/mixin/load_config.test.ts', () => { const loader = app.loader; await loader.loadPlugin(); await loader.loadConfig(); - assert(loader.config.egg === 'egg-unittest'); + assert.ok(loader.config.egg === 'egg-unittest'); }); it('should override config by env.EGG_APP_CONFIG', async () => { @@ -71,11 +71,11 @@ describe('test/loader/mixin/load_config.test.ts', () => { const loader = app.loader; await loader.loadPlugin(); await loader.loadConfig(); - assert(loader.config.egg === 'env_egg'); - assert(loader.config.foo.bar === 'env_bar'); - assert(loader.config.foo.bar2 === 'b'); - assert(loader.configMeta.egg === ''); - assert(loader.configMeta.foo.bar === ''); + assert.ok(loader.config.egg === 'env_egg'); + assert.ok(loader.config.foo.bar === 'env_bar'); + assert.ok(loader.config.foo.bar2 === 'b'); + assert.ok(loader.configMeta.egg === ''); + assert.ok(loader.configMeta.foo.bar === ''); }); it('should override config with invalid env.EGG_APP_CONFIG', async () => { @@ -84,9 +84,9 @@ describe('test/loader/mixin/load_config.test.ts', () => { const loader = app.loader; await loader.loadPlugin(); await loader.loadConfig(); - assert(loader.config.egg === 'egg-unittest'); - assert(loader.config.foo.bar === 'a'); - assert(loader.config.foo.bar2 === 'b'); + assert.ok(loader.config.egg === 'egg-unittest'); + assert.ok(loader.config.foo.bar === 'a'); + assert.ok(loader.config.foo.bar2 === 'b'); }); it('should not load config of plugin that is disabled', async () => { @@ -94,7 +94,7 @@ describe('test/loader/mixin/load_config.test.ts', () => { const loader = app.loader; await loader.loadPlugin(); await loader.loadConfig(); - assert(!loader.config.pluginA); + assert.ok(!loader.config.pluginA); }); it('should throw when plugin define middleware', async () => { @@ -113,7 +113,7 @@ describe('test/loader/mixin/load_config.test.ts', () => { await loader.loadConfig(); throw new Error('should not run'); } catch (err: any) { - assert( + assert.ok( err.message.includes( `Can not define middleware in ${path.join(pluginDir, 'config/config.default.js')}` ) @@ -134,10 +134,10 @@ describe('test/loader/mixin/load_config.test.ts', () => { const loader = app.loader; await loader.loadPlugin(); await loader.loadConfig(); - assert(loader.config.plugin.val === 2); - assert(loader.config.plugin.val === 2); - assert(loader.config.plugin.sub !== loader.config.app.sub); - assert(loader.config.appInApp === false); + assert.ok(loader.config.plugin.val === 2); + assert.ok(loader.config.plugin.val === 2); + assert.ok(loader.config.plugin.sub !== loader.config.app.sub); + assert.ok(loader.config.appInApp === false); }); it('should load config without coreMiddleware', async () => { @@ -216,7 +216,7 @@ describe('test/loader/mixin/load_config.test.ts', () => { const loader = app.loader; await loader.loadPlugin(); await app.loader.loadConfig(); - assert(loader.config.from === 'default'); + assert.ok(loader.config.from === 'default'); }); it('should return without scope when env = prod', async () => { @@ -225,7 +225,7 @@ describe('test/loader/mixin/load_config.test.ts', () => { const loader = app.loader; await loader.loadPlugin(); await app.loader.loadConfig(); - assert(loader.config.from === 'prod'); + assert.ok(loader.config.from === 'prod'); }); it('should return with scope when env = default', async () => { @@ -235,7 +235,7 @@ describe('test/loader/mixin/load_config.test.ts', () => { const loader = app.loader; await loader.loadPlugin(); await app.loader.loadConfig(); - assert(loader.config.from === 'en'); + assert.ok(loader.config.from === 'en'); }); it('should return with scope when env = prod', async () => { @@ -245,7 +245,7 @@ describe('test/loader/mixin/load_config.test.ts', () => { const loader = app.loader; await loader.loadPlugin(); await app.loader.loadConfig(); - assert(loader.config.from === 'en_prod'); + assert.ok(loader.config.from === 'en_prod'); }); }); }); diff --git a/test/loader/mixin/load_controller.test.ts b/test/loader/mixin/load_controller.test.ts index 222aee6f..6341976a 100644 --- a/test/loader/mixin/load_controller.test.ts +++ b/test/loader/mixin/load_controller.test.ts @@ -17,7 +17,7 @@ describe('test/loader/mixin/load_controller.test.ts', () => { describe('when controller is async function', () => { it('should use it as middleware', () => { - assert(app.controller.asyncFunction); + assert.ok(app.controller.asyncFunction); return request(app.callback()) .get('/async-function') @@ -28,7 +28,7 @@ describe('test/loader/mixin/load_controller.test.ts', () => { describe('when controller is generator function', () => { it('should use it as middleware', () => { - assert(app.controller.generatorFunction); + assert.ok(app.controller.generatorFunction); assert.equal( app.controller.generatorFunction.name, 'objectControllerMiddleware' @@ -49,7 +49,7 @@ describe('test/loader/mixin/load_controller.test.ts', () => { }); it('should first argument is ctx', () => { - assert(app.controller.generatorFunction); + assert.ok(app.controller.generatorFunction); return request(app.callback()) .get('/generator-function-ctx') @@ -60,12 +60,12 @@ describe('test/loader/mixin/load_controller.test.ts', () => { describe('when controller is object', () => { it('should define method which is function', () => { - assert(app.controller.object.callFunction); - assert( + assert.ok(app.controller.object.callFunction); + assert.ok( app.controller.object.callFunction.name === 'objectControllerMiddleware' ); const classFilePath = path.join(app.baseDir, 'app/controller/object.js'); - assert( + assert.ok( app.controller.object.callFunction[app.loader.FileLoader.FULLPATH] === classFilePath + '#callFunction()' ); @@ -77,13 +77,13 @@ describe('test/loader/mixin/load_controller.test.ts', () => { }); it('should define method which is generator function', () => { - assert(app.controller.object.callGeneratorFunction); - assert( + assert.ok(app.controller.object.callGeneratorFunction); + assert.ok( app.controller.object.callGeneratorFunction.name === 'objectControllerMiddleware' ); const classFilePath = path.join(app.baseDir, 'app/controller/object.js'); - assert( + assert.ok( app.controller.object.callGeneratorFunction[ app.loader.FileLoader.FULLPATH ] === @@ -97,13 +97,13 @@ describe('test/loader/mixin/load_controller.test.ts', () => { }); it('should define method on subObject', () => { - assert(app.controller.object.subObject.callGeneratorFunction); - assert( + assert.ok(app.controller.object.subObject.callGeneratorFunction); + assert.ok( app.controller.object.subObject.callGeneratorFunction.name === 'objectControllerMiddleware' ); const classFilePath = path.join(app.baseDir, 'app/controller/object.js'); - assert( + assert.ok( app.controller.object.subObject.callGeneratorFunction[ app.loader.FileLoader.FULLPATH ] === @@ -117,15 +117,15 @@ describe('test/loader/mixin/load_controller.test.ts', () => { }); it('should define method on subObject.subSubObject', () => { - assert( + assert.ok( app.controller.object.subObject.subSubObject.callGeneratorFunction ); - assert( + assert.ok( app.controller.object.subObject.subSubObject.callGeneratorFunction .name === 'objectControllerMiddleware' ); const classFilePath = path.join(app.baseDir, 'app/controller/object.js'); - assert( + assert.ok( app.controller.object.subObject.subSubObject.callGeneratorFunction[ app.loader.FileLoader.FULLPATH ] === @@ -139,13 +139,13 @@ describe('test/loader/mixin/load_controller.test.ts', () => { }); it('should define method which is generator function with argument', () => { - assert(app.controller.object.callGeneratorFunctionWithArg); - assert( + assert.ok(app.controller.object.callGeneratorFunctionWithArg); + assert.ok( app.controller.object.callGeneratorFunctionWithArg.name === 'objectControllerMiddleware' ); const classFilePath = path.join(app.baseDir, 'app/controller/object.js'); - assert( + assert.ok( app.controller.object.callGeneratorFunctionWithArg[ app.loader.FileLoader.FULLPATH ] === @@ -159,13 +159,13 @@ describe('test/loader/mixin/load_controller.test.ts', () => { }); it('should define method which is async function', () => { - assert(app.controller.object.callAsyncFunction); - assert( + assert.ok(app.controller.object.callAsyncFunction); + assert.ok( app.controller.object.callAsyncFunction.name === 'objectControllerMiddleware' ); const classFilePath = path.join(app.baseDir, 'app/controller/object.js'); - assert( + assert.ok( app.controller.object.callAsyncFunction[ app.loader.FileLoader.FULLPATH ] === @@ -179,13 +179,13 @@ describe('test/loader/mixin/load_controller.test.ts', () => { }); it('should define method which is async function with argument', () => { - assert(app.controller.object.callAsyncFunctionWithArg); - assert( + assert.ok(app.controller.object.callAsyncFunctionWithArg); + assert.ok( app.controller.object.callAsyncFunctionWithArg.name === 'objectControllerMiddleware' ); const classFilePath = path.join(app.baseDir, 'app/controller/object.js'); - assert( + assert.ok( app.controller.object.callAsyncFunctionWithArg[ app.loader.FileLoader.FULLPATH ] === @@ -199,7 +199,7 @@ describe('test/loader/mixin/load_controller.test.ts', () => { }); it('should not load properties that are not function', () => { - assert(!app.controller.object.nofunction); + assert.ok(!app.controller.object.nofunction); }); it('should match app.resources', async () => { @@ -219,12 +219,12 @@ describe('test/loader/mixin/load_controller.test.ts', () => { describe('when controller is class', () => { it('should define method which is function', () => { - assert(app.controller.class.callFunction); - assert( + assert.ok(app.controller.class.callFunction); + assert.ok( app.controller.class.callFunction.name === 'classControllerMiddleware' ); const classFilePath = path.join(app.baseDir, 'app/controller/class.js'); - assert( + assert.ok( app.controller.class.callFunction[app.loader.FileLoader.FULLPATH] === `${classFilePath}#HomeController.callFunction()` ); @@ -236,13 +236,13 @@ describe('test/loader/mixin/load_controller.test.ts', () => { }); it('should define method which is generator function', () => { - assert(app.controller.class.callGeneratorFunction); - assert( + assert.ok(app.controller.class.callGeneratorFunction); + assert.ok( app.controller.class.callGeneratorFunction.name === 'classControllerMiddleware' ); const classFilePath = path.join(app.baseDir, 'app/controller/class.js'); - assert( + assert.ok( app.controller.class.callGeneratorFunction[ app.loader.FileLoader.FULLPATH ] === `${classFilePath}#HomeController.callGeneratorFunction()` @@ -255,13 +255,13 @@ describe('test/loader/mixin/load_controller.test.ts', () => { }); it('should define method which is generator function with ctx', () => { - assert(app.controller.class.callGeneratorFunctionWithArg); - assert( + assert.ok(app.controller.class.callGeneratorFunctionWithArg); + assert.ok( app.controller.class.callGeneratorFunctionWithArg.name === 'classControllerMiddleware' ); const classFilePath = path.join(app.baseDir, 'app/controller/class.js'); - assert( + assert.ok( app.controller.class.callGeneratorFunctionWithArg[ app.loader.FileLoader.FULLPATH ] === `${classFilePath}#HomeController.callGeneratorFunctionWithArg()` @@ -274,13 +274,13 @@ describe('test/loader/mixin/load_controller.test.ts', () => { }); it('should define method which is async function', () => { - assert(app.controller.class.callAsyncFunction); - assert( + assert.ok(app.controller.class.callAsyncFunction); + assert.ok( app.controller.class.callAsyncFunction.name === 'classControllerMiddleware' ); const classFilePath = path.join(app.baseDir, 'app/controller/class.js'); - assert( + assert.ok( app.controller.class.callAsyncFunction[ app.loader.FileLoader.FULLPATH ] === `${classFilePath}#HomeController.callAsyncFunction()` @@ -293,13 +293,13 @@ describe('test/loader/mixin/load_controller.test.ts', () => { }); it('should define method which is async function with ctx', () => { - assert(app.controller.class.callAsyncFunctionWithArg); - assert( + assert.ok(app.controller.class.callAsyncFunctionWithArg); + assert.ok( app.controller.class.callAsyncFunctionWithArg.name === 'classControllerMiddleware' ); const classFilePath = path.join(app.baseDir, 'app/controller/class.js'); - assert( + assert.ok( app.controller.class.callAsyncFunctionWithArg[ app.loader.FileLoader.FULLPATH ] === `${classFilePath}#HomeController.callAsyncFunctionWithArg()` @@ -312,7 +312,7 @@ describe('test/loader/mixin/load_controller.test.ts', () => { }); it('should load class that is inherited from its super class', () => { - assert( + assert.ok( app.controller.classInherited.callInheritedFunction.name === 'classControllerMiddleware' ); @@ -320,7 +320,7 @@ describe('test/loader/mixin/load_controller.test.ts', () => { app.baseDir, 'app/controller/class_inherited.js' ); - assert( + assert.ok( app.controller.classInherited.callInheritedFunction[ app.loader.FileLoader.FULLPATH ] === `${classFilePath}#HomeController.callInheritedFunction()` @@ -333,8 +333,8 @@ describe('test/loader/mixin/load_controller.test.ts', () => { }); it('should load inherited class without overriding its own function', () => { - assert(app.controller.classInherited.callOverriddenFunction); - assert( + assert.ok(app.controller.classInherited.callOverriddenFunction); + assert.ok( app.controller.classInherited.callOverriddenFunction.name === 'classControllerMiddleware' ); @@ -342,7 +342,7 @@ describe('test/loader/mixin/load_controller.test.ts', () => { app.baseDir, 'app/controller/class_inherited.js' ); - assert( + assert.ok( app.controller.classInherited.callOverriddenFunction[ app.loader.FileLoader.FULLPATH ] === `${classFilePath}#HomeController.callOverriddenFunction()` @@ -355,18 +355,18 @@ describe('test/loader/mixin/load_controller.test.ts', () => { }); it('should not load properties that are not function', () => { - assert(!app.controller.class.nofunction); + assert.ok(!app.controller.class.nofunction); }); it('should not override constructor', () => { - assert( + assert.ok( /\[native code]/.test(app.controller.class.constructor.toString()) ); }); it('should load class that is wrapped by function', () => { - assert(app.controller.classWrapFunction.get); - assert( + assert.ok(app.controller.classWrapFunction.get); + assert.ok( app.controller.classWrapFunction.get.name === 'classControllerMiddleware' ); @@ -374,7 +374,7 @@ describe('test/loader/mixin/load_controller.test.ts', () => { app.baseDir, 'app/controller/class_wrap_function.js' ); - assert( + assert.ok( app.controller.classWrapFunction.get[app.loader.FileLoader.FULLPATH] === `${classFilePath}#HomeController.get()` ); @@ -436,10 +436,10 @@ describe('test/loader/mixin/load_controller.test.ts', () => { describe('function attribute', () => { it('should keep function attribute ok', () => { - assert(isFunction(app.controller.functionAttr.getAccountInfo)); - assert(isAsyncFunction(app.controller.functionAttr.getAccountInfo)); - assert(app.controller.functionAttr.getAccountInfo.operationType); - assert( + assert.ok(isFunction(app.controller.functionAttr.getAccountInfo)); + assert.ok(isAsyncFunction(app.controller.functionAttr.getAccountInfo)); + assert.ok(app.controller.functionAttr.getAccountInfo.operationType); + assert.ok( app.controller.functionAttr.foo && isAsyncFunction(app.controller.functionAttr.foo.bar) ); @@ -454,7 +454,7 @@ describe('test/loader/mixin/load_controller.test.ts', () => { describe('not controller', () => { it('should load a number', () => { - assert(app.controller.number === 123); + assert.ok(app.controller.number === 123); }); }); @@ -472,7 +472,7 @@ describe('test/loader/mixin/load_controller.test.ts', () => { after(() => app.close()); it('should load', () => { - assert(app.controller.user); + assert.ok(app.controller.user); }); }); @@ -501,7 +501,7 @@ describe('test/loader/mixin/load_controller.test.ts', () => { }); it('should support parameter', async () => { - assert(app.config.controller); + assert.ok(app.config.controller); assert.equal(app.config.controller.supportParams, true); const ctx = { app }; const args = [1, 2, 3]; diff --git a/test/loader/mixin/load_custom_agent.test.ts b/test/loader/mixin/load_custom_agent.test.ts index 32f1dd91..87c89aac 100644 --- a/test/loader/mixin/load_custom_agent.test.ts +++ b/test/loader/mixin/load_custom_agent.test.ts @@ -12,17 +12,17 @@ describe('test/loader/mixin/load_custom_agent.test.ts', () => { after(() => agent.close()); it('should load agent.js', () => { - assert(agent.b === 'plugin b'); - assert(agent.c === 'plugin c'); - assert(agent.agent === 'agent'); + assert.ok(agent.b === 'plugin b'); + assert.ok(agent.c === 'plugin c'); + assert.ok(agent.agent === 'agent'); }); it("should agent.js of plugin before application's", () => { - assert(agent.dateB <= agent.date); - assert(agent.dateC <= agent.date); + assert.ok(agent.dateB <= agent.date); + assert.ok(agent.dateC <= agent.date); }); it('should not load plugin that is disabled', () => { - assert(!agent.a); + assert.ok(!agent.a); }); }); diff --git a/test/loader/mixin/load_custom_app.test.ts b/test/loader/mixin/load_custom_app.test.ts index cc96cdb1..8e9b922d 100644 --- a/test/loader/mixin/load_custom_app.test.ts +++ b/test/loader/mixin/load_custom_app.test.ts @@ -14,18 +14,18 @@ describe('test/loader/mixin/load_custom_app.test.ts', () => { after(() => app.close()); it('should load app.js', () => { - assert((app as any).b === 'plugin b'); - assert((app as any).c === 'plugin c'); - assert((app as any).app === 'app'); + assert.ok((app as any).b === 'plugin b'); + assert.ok((app as any).c === 'plugin c'); + assert.ok((app as any).app === 'app'); }); it("should app.js of plugin before application's", () => { - assert((app as any).dateB <= (app as any).date); - assert((app as any).dateC <= (app as any).date); + assert.ok((app as any).dateB <= (app as any).date); + assert.ok((app as any).dateC <= (app as any).date); }); it('should not load plugin that is disabled', () => { - assert(!(app as any).a); + assert.ok(!(app as any).a); }); }); }); diff --git a/test/loader/mixin/load_custom_loader.test.ts b/test/loader/mixin/load_custom_loader.test.ts index 1c7d778f..d08d0b08 100644 --- a/test/loader/mixin/load_custom_loader.test.ts +++ b/test/loader/mixin/load_custom_loader.test.ts @@ -20,13 +20,13 @@ describe('test/loader/mixin/load_custom_loader.test.ts', () => { it('should load to app', async () => { console.log((app as any).adapter); const res = await (app as any).adapter.docker.inspectDocker(); - assert(res); - assert(res.inject === 'app'); + assert.ok(res); + assert.ok(res.inject === 'app'); }); it('should support exports load to app', () => { - assert((app as any).util.test.sayHi('egg') === 'hi, egg'); - assert((app as any).util.sub.fn.echo() === 'echo custom_loader'); + assert.ok((app as any).util.test.sayHi('egg') === 'hi, egg'); + assert.ok((app as any).util.sub.fn.echo() === 'echo custom_loader'); }); it('should load to ctx', async () => { @@ -44,9 +44,9 @@ describe('test/loader/mixin/load_custom_loader.test.ts', () => { it('should support loadunit', () => { let name = (app as any).plugin.a.getName(); - assert(name === 'plugina'); + assert.ok(name === 'plugina'); name = (app as any).plugin.b.getName(); - assert(name === 'pluginb'); + assert.ok(name === 'pluginb'); }); it('should loadConfig first', async () => { @@ -55,7 +55,7 @@ describe('test/loader/mixin/load_custom_loader.test.ts', () => { await app.loader.loadCustomLoader(); throw new Error('should not run'); } catch (err: any) { - assert(err.message === 'should loadConfig first'); + assert.ok(err.message === 'should loadConfig first'); } finally { app.close(); } @@ -72,7 +72,7 @@ describe('test/loader/mixin/load_custom_loader.test.ts', () => { await app.loader.loadCustomLoader(); throw new Error('should not run'); } catch (err: any) { - assert( + assert.ok( err.message === 'directory is required for config.customLoader.custom' ); } finally { @@ -94,7 +94,7 @@ describe('test/loader/mixin/load_custom_loader.test.ts', () => { await app.loader.loadCustomLoader(); throw new Error('should not run'); } catch (err: any) { - assert(err.message === 'inject only support app or ctx'); + assert.ok(err.message === 'inject only support app or ctx'); } finally { app.close(); } @@ -116,7 +116,7 @@ describe('test/loader/mixin/load_custom_loader.test.ts', () => { await app.loader.loadCustomLoader(); throw new Error('should not run'); } catch (err: any) { - assert(err.message === 'customLoader should not override app.config'); + assert.ok(err.message === 'customLoader should not override app.config'); } finally { app.close(); } @@ -133,7 +133,7 @@ describe('test/loader/mixin/load_custom_loader.test.ts', () => { await app.loader.loadCustomLoader(); throw new Error('should not run'); } catch (err: any) { - assert(err.message === 'customLoader should not override ctx.cookies'); + assert.ok(err.message === 'customLoader should not override ctx.cookies'); } finally { app.close(); } diff --git a/test/loader/mixin/load_extend.test.ts b/test/loader/mixin/load_extend.test.ts index 26571095..019855fb 100644 --- a/test/loader/mixin/load_extend.test.ts +++ b/test/loader/mixin/load_extend.test.ts @@ -23,18 +23,18 @@ describe('test/loader/mixin/load_extend.test.ts', () => { afterEach(mm.restore); it('should load app.context app.request app.response', () => { - assert(app.context.appContext, 'app.context.appContext'); - assert(app.context.pluginbContext, 'app.context.pluginbContext'); - assert(!app.context.pluginaContext, '!app.context.pluginaContext'); - assert(app.request.appRequest, 'app.request.appRequest'); - assert(app.request.pluginbRequest, 'app.request.pluginbRequest'); - assert(!app.request.pluginaRequest, '!app.request.pluginaRequest'); - assert(app.response.appResponse, 'app.response.appResponse'); - assert(app.response.pluginbResponse, 'app.response.pluginbResponse'); - assert(!app.response.pluginaResponse, '!app.response.pluginaResponse'); - assert((app as any).appApplication, 'appApplication'); - assert((app as any).pluginbApplication, 'pluginbApplication'); - assert(!(app as any).pluginaApplication, 'pluginaApplication'); + assert.ok(app.context.appContext, 'app.context.appContext'); + assert.ok(app.context.pluginbContext, 'app.context.pluginbContext'); + assert.ok(!app.context.pluginaContext, '!app.context.pluginaContext'); + assert.ok(app.request.appRequest, 'app.request.appRequest'); + assert.ok(app.request.pluginbRequest, 'app.request.pluginbRequest'); + assert.ok(!app.request.pluginaRequest, '!app.request.pluginaRequest'); + assert.ok(app.response.appResponse, 'app.response.appResponse'); + assert.ok(app.response.pluginbResponse, 'app.response.pluginbResponse'); + assert.ok(!app.response.pluginaResponse, '!app.response.pluginaResponse'); + assert.ok((app as any).appApplication, 'appApplication'); + assert.ok((app as any).pluginbApplication, 'pluginbApplication'); + assert.ok(!(app as any).pluginaApplication, 'pluginaApplication'); return request(app.callback()) .get('/') @@ -105,17 +105,17 @@ describe('test/loader/mixin/load_extend.test.ts', () => { const app = createApp('extend-env'); await app.loader.loadPlugin(); await app.loader.loadApplicationExtend(); - assert((app as any).custom === true); + assert.ok((app as any).custom === true); // application.custom.js override application.js - assert((app as any).a === 'a1'); + assert.ok((app as any).a === 'a1'); // application.custom.js in plugin also can override application.js in app - assert((app as any).b === 'b1'); + assert.ok((app as any).b === 'b1'); }); it('should not load extend that returned function', async () => { const proto: any = {}; await app.loader.loadExtend('call', proto); - assert(proto.call === undefined); + assert.ok(proto.call === undefined); }); describe('load unittest extend', () => { @@ -126,8 +126,8 @@ describe('test/loader/mixin/load_extend.test.ts', () => { app = createApp('load-plugin-unittest'); await app.loader.loadPlugin(); await app.loader.loadApplicationExtend(); - assert((app as any).unittest === true); - assert((app as any).local !== true); + assert.ok((app as any).unittest === true); + assert.ok((app as any).local !== true); }); it('should load unittext.js when mm.env(default)', async () => { @@ -136,8 +136,8 @@ describe('test/loader/mixin/load_extend.test.ts', () => { app = createApp('load-plugin-unittest'); await app.loader.loadPlugin(); await app.loader.loadApplicationExtend(); - assert((app as any).unittest === true); - assert((app as any).local === true); + assert.ok((app as any).unittest === true); + assert.ok((app as any).local === true); }); }); }); diff --git a/test/loader/mixin/load_extend_class.test.ts b/test/loader/mixin/load_extend_class.test.ts index 57c4f161..78c6c8ec 100644 --- a/test/loader/mixin/load_extend_class.test.ts +++ b/test/loader/mixin/load_extend_class.test.ts @@ -23,7 +23,7 @@ describe('test/loader/mixin/load_extend_class.test.ts', () => { afterEach(mm.restore); it('should load app.context app.request app.response', () => { - assert((app as any).appApplication); + assert.ok((app as any).appApplication); return request(app.callback()) .get('/') diff --git a/test/loader/mixin/load_middleware.test.ts b/test/loader/mixin/load_middleware.test.ts index 384265ac..88d97bc9 100644 --- a/test/loader/mixin/load_middleware.test.ts +++ b/test/loader/mixin/load_middleware.test.ts @@ -19,19 +19,19 @@ describe('test/loader/mixin/load_middleware.test.ts', () => { after(() => app.close()); it('should load application, plugin, and default middlewares', () => { - assert('static' in app.middlewares); - assert('status' in app.middlewares); - assert('custom' in app.middlewares); - assert('b' in app.middlewares); - assert(!('a' in app.middlewares)); + assert.ok('static' in app.middlewares); + assert.ok('status' in app.middlewares); + assert.ok('custom' in app.middlewares); + assert.ok('b' in app.middlewares); + assert.ok(!('a' in app.middlewares)); }); it('should also support app.middleware', () => { - assert('static' in app.middleware); - assert('status' in app.middleware); - assert('custom' in app.middleware); - assert('b' in app.middleware); - assert(!('a' in app.middleware)); + assert.ok('static' in app.middleware); + assert.ok('status' in app.middleware); + assert.ok('custom' in app.middleware); + assert.ok('b' in app.middleware); + assert.ok(!('a' in app.middleware)); assert.equal(app.middleware.static, app.middlewares.static); const names = []; @@ -222,7 +222,7 @@ describe('test/loader/mixin/load_middleware.test.ts', () => { after(() => app.close()); it('should load', () => { - assert(app.middlewares.user); + assert.ok(app.middlewares.user); }); }); }); diff --git a/test/loader/mixin/load_plugin.test.ts b/test/loader/mixin/load_plugin.test.ts index 5cbdb7c5..114f15e8 100644 --- a/test/loader/mixin/load_plugin.test.ts +++ b/test/loader/mixin/load_plugin.test.ts @@ -22,21 +22,21 @@ describe('test/loader/mixin/load_plugin.test.ts', () => { app = createApp('plugin'); const loader = app.loader; await loader.loadPlugin(); - assert('allPlugins' in loader); - assert('appPlugins' in loader); - assert('customPlugins' in loader); - assert('eggPlugins' in loader); + assert.ok('allPlugins' in loader); + assert.ok('appPlugins' in loader); + assert.ok('customPlugins' in loader); + assert.ok('eggPlugins' in loader); }); it('should load plugin by pkg.eggPlugin.exports', async () => { app = createApp('plugin-pkg-exports'); const loader = app.loader; await loader.loadPlugin(); - assert('allPlugins' in loader); - assert('appPlugins' in loader); - assert('customPlugins' in loader); - assert('eggPlugins' in loader); - assert(loader.plugins.a.enable); + assert.ok('allPlugins' in loader); + assert.ok('appPlugins' in loader); + assert.ok('customPlugins' in loader); + assert.ok('eggPlugins' in loader); + assert.ok(loader.plugins.a.enable); }); it('should loadConfig all plugins', async () => { @@ -72,7 +72,7 @@ describe('test/loader/mixin/load_plugin.test.ts', () => { path: path.join(baseDir, 'plugins/e'), from: path.join(baseDir, 'config/plugin.js'), }); - assert(Array.isArray(loader.orderPlugins)); + assert.ok(Array.isArray(loader.orderPlugins)); }); it('should loadPlugin with order', async () => { @@ -133,10 +133,10 @@ describe('test/loader/mixin/load_plugin.test.ts', () => { await loader.loadPlugin(); await loader.loadConfig(); // console.log(loader.plugins, loader.config); - assert(loader.plugins.a); - assert(loader.plugins.b); - assert(loader.config.a === 'a'); - assert(loader.config.b === 'b'); + assert.ok(loader.plugins.a); + assert.ok(loader.plugins.b); + assert.ok(loader.config.a === 'a'); + assert.ok(loader.config.b === 'b'); }); it('should support pnpm node_modules style with scope', async () => { @@ -157,10 +157,10 @@ describe('test/loader/mixin/load_plugin.test.ts', () => { await loader.loadPlugin(); await loader.loadConfig(); // console.log(loader.plugins, loader.config); - assert(loader.plugins.a); - assert(loader.plugins.b); - assert(loader.config.a === 'a'); - assert(loader.config.b === 'b'); + assert.ok(loader.plugins.a); + assert.ok(loader.plugins.b); + assert.ok(loader.config.a === 'a'); + assert.ok(loader.config.b === 'b'); }); it('should support alias', async () => { @@ -180,7 +180,7 @@ describe('test/loader/mixin/load_plugin.test.ts', () => { path: path.join(baseDir, 'node_modules/d'), from: path.join(baseDir, 'config/plugin.js'), }); - assert(!loader.plugins.d); + assert.ok(!loader.plugins.d); }); it('should support config in package.json', async () => { @@ -231,14 +231,14 @@ describe('test/loader/mixin/load_plugin.test.ts', () => { }); const loader = app.loader; await loader.loadPlugin(); - assert(!message); + assert.ok(!message); }); it('should load plugin when eggPlugin.exports.typescript = "./src" exists', async () => { app = createApp('plugin-ts-src'); const loader = app.loader; await loader.loadPlugin(); - assert(loader.allPlugins.agg.path); + assert.ok(loader.allPlugins.agg.path); assert.match(loader.allPlugins.agg.path, /src$/); }); @@ -277,7 +277,7 @@ describe('test/loader/mixin/load_plugin.test.ts', () => { path: path.join(baseDir, 'node_modules/d'), from: '', }); - assert(!loader.plugins.d); + assert.ok(!loader.plugins.d); }); it('should custom plugins with EGG_PLUGINS', async () => { @@ -289,15 +289,17 @@ describe('test/loader/mixin/load_plugin.test.ts', () => { path: path.join(baseDir, 'node_modules/h'), }, }; - mm(process.env, 'EGG_PLUGINS', `${JSON.stringify(plugins)}`); + mm(process.env, 'EGG_PLUGINS', JSON.stringify(plugins)); app = createApp('plugin'); const loader = app.loader; await loader.loadPlugin(); await loader.loadConfig(); - assert(loader.allPlugins.b.enable === false); - assert(loader.allPlugins.h.enable === true); - assert(loader.allPlugins.h.path === path.join(baseDir, 'node_modules/h')); + assert.ok(loader.allPlugins.b.enable === false); + assert.ok(loader.allPlugins.h.enable === true); + assert.ok( + loader.allPlugins.h.path === path.join(baseDir, 'node_modules/h') + ); }); it('should ignore when EGG_PLUGINS parse error', async () => { @@ -306,7 +308,7 @@ describe('test/loader/mixin/load_plugin.test.ts', () => { const loader = app.loader; await loader.loadPlugin(); await loader.loadConfig(); - assert(!loader.allPlugins.h); + assert.ok(!loader.allPlugins.h); }); it('should validate plugin.package', async () => { @@ -432,9 +434,9 @@ describe('test/loader/mixin/load_plugin.test.ts', () => { const loader = app.loader; await loader.loadPlugin(); await loader.loadConfig(); - assert(!loader.plugins.testMe); + assert.ok(!loader.plugins.testMe); const plugins = loader.orderPlugins.map(plugin => plugin.name); - assert(!plugins.includes('testMe')); + assert.ok(!plugins.includes('testMe')); }); it('should complement infomation by config/plugin.js from plugin', async () => { @@ -448,8 +450,8 @@ describe('test/loader/mixin/load_plugin.test.ts', () => { // unittest 环境不开启 const keys1 = loader1.orderPlugins.map(plugin => plugin.name).join(','); - assert(keys1.includes('b,c,d1,f,e')); - assert(!loader1.plugins.a1); + assert.ok(keys1.includes('b,c,d1,f,e')); + assert.ok(!loader1.plugins.a1); mm(process.env, 'NODE_ENV', 'development'); const app2 = createApp('plugin'); @@ -457,7 +459,7 @@ describe('test/loader/mixin/load_plugin.test.ts', () => { await loader2.loadPlugin(); await loader2.loadConfig(); const keys2 = loader2.orderPlugins.map(plugin => plugin.name).join(','); - assert(keys2.includes('d1,a1,b,c,f,e')); + assert.ok(keys2.includes('d1,a1,b,c,f,e')); assert.deepEqual(loader2.plugins.a1, { enable: true, name: 'a1', @@ -492,12 +494,12 @@ describe('test/loader/mixin/load_plugin.test.ts', () => { const loader = app.loader; await loader.loadPlugin(); await loader.loadConfig(); - assert(!loader.plugins.session.package); + assert.ok(!loader.plugins.session.package); assert.equal( loader.plugins.session.path, getFilepath('plugin-path-package/session') ); - assert(loader.plugins.hsfclient.package); + assert.ok(loader.plugins.hsfclient.package); assert.equal( loader.plugins.hsfclient.path, getFilepath('plugin-path-package/node_modules/hsfclient') @@ -557,7 +559,7 @@ describe('test/loader/mixin/load_plugin.test.ts', () => { const loader = app.loader; await loader.loadPlugin(); assert.equal(loader.allPlugins.a.enable, true); - assert(!loader.allPlugins.b); + assert.ok(!loader.allPlugins.b); assert.equal(loader.allPlugins.c.enable, true); }); @@ -566,7 +568,7 @@ describe('test/loader/mixin/load_plugin.test.ts', () => { app = createApp('load-plugin-default'); const loader = app.loader; await loader.loadPlugin(); - assert(!loader.allPlugins.a); + assert.ok(!loader.allPlugins.a); assert.equal(loader.allPlugins.b.enable, true); assert.equal(loader.allPlugins.c.enable, true); }); @@ -685,8 +687,8 @@ describe('test/loader/mixin/load_plugin.test.ts', () => { await loader.loadPlugin(); assert.equal(loader.allPlugins.a.enable, false); assert.equal(loader.allPlugins.b.enable, true); - assert(!loader.allPlugins.c); - assert(!loader.allPlugins.d); + assert.ok(!loader.allPlugins.c); + assert.ok(!loader.allPlugins.d); }); it('should load plugin from scope and prod env', async () => { diff --git a/test/loader/mixin/load_service.test.ts b/test/loader/mixin/load_service.test.ts index 61efc6f0..6479fca8 100644 --- a/test/loader/mixin/load_service.test.ts +++ b/test/loader/mixin/load_service.test.ts @@ -23,11 +23,11 @@ describe('test/loader/mixin/load_service.test.ts', () => { await app.loader.loadMiddleware(); await app.ready(); console.log(app.serviceClasses); - assert(app.serviceClasses.foo); - assert(app.serviceClasses.foo2); - assert(!app.serviceClasses.bar1); - assert(app.serviceClasses.bar2); - assert(app.serviceClasses.foo4); + assert.ok(app.serviceClasses.foo); + assert.ok(app.serviceClasses.foo2); + assert.ok(!app.serviceClasses.bar1); + assert.ok(app.serviceClasses.bar2); + assert.ok(app.serviceClasses.foo4); await request(app.callback()) .get('/') @@ -57,10 +57,10 @@ describe('test/loader/mixin/load_service.test.ts', () => { await app.loader.loadConfig(); await app.loader.loadApplicationExtend(); await app.loader.loadService(); - assert('foo' in app.serviceClasses); - assert('bar' in app.serviceClasses.foo); - assert('bar1' in app.serviceClasses.foo); - assert('aa' in app.serviceClasses.foo); + assert.ok('foo' in app.serviceClasses); + assert.ok('bar' in app.serviceClasses.foo); + assert.ok('bar1' in app.serviceClasses.foo); + assert.ok('aa' in app.serviceClasses.foo); }); it('should each request has unique ctx', async () => { @@ -160,7 +160,7 @@ describe('test/loader/mixin/load_service.test.ts', () => { it('should load', () => { console.log(app.serviceClasses); - assert(app.serviceClasses.user); + assert.ok(app.serviceClasses.user); }); }); }); diff --git a/test/singleton.test.ts b/test/singleton.test.ts index 5edea785..31a8c374 100644 --- a/test/singleton.test.ts +++ b/test/singleton.test.ts @@ -42,7 +42,7 @@ describe('test/singleton.test.ts', () => { create, }); singleton.init(); - assert(app.dataService instanceof DataService); + assert.ok(app.dataService instanceof DataService); assert.equal(app.dataService.config.foo, 'bar'); assert.equal(typeof app.dataService.createInstance, 'function'); } @@ -63,7 +63,7 @@ describe('test/singleton.test.ts', () => { create, }); singleton.init(); - assert(app.dataService instanceof Singleton); + assert.ok(app.dataService instanceof Singleton); assert.equal(app.dataService.get('first').config.foo, 'bar1'); assert.equal(app.dataService.get('second').config.foo, 'bar2'); assert.equal(typeof app.dataService.createInstance, 'function'); @@ -86,7 +86,7 @@ describe('test/singleton.test.ts', () => { create, }); singleton.init(); - assert(app.dataService instanceof DataService); + assert.ok(app.dataService instanceof DataService); assert.equal(app.dataService.config.foo, 'bar'); assert.equal(app.dataService.config.foo1, 'bar1'); assert.equal(typeof app.dataService.createInstance, 'function'); @@ -112,24 +112,24 @@ describe('test/singleton.test.ts', () => { create, }); singleton.init(); - assert(app.dataService instanceof Singleton); - assert(app.dataService.get('first').config.foo === 'bar1'); - assert( + assert.ok(app.dataService instanceof Singleton); + assert.ok(app.dataService.get('first').config.foo === 'bar1'); + assert.ok( app.dataService.getSingletonInstance('first').config.foo === 'bar1' ); - assert( + assert.ok( app.dataService.get('first'), app.dataService.getSingletonInstance('first') ); - assert(app.dataService.get('second').config.foo === 'bar'); - assert( + assert.ok(app.dataService.get('second').config.foo === 'bar'); + assert.ok( app.dataService.getSingletonInstance('second').config.foo === 'bar' ); - assert( + assert.ok( app.dataService.get('second'), app.dataService.getSingletonInstance('second') ); - assert(typeof app.dataService.createInstance === 'function'); + assert.ok(typeof app.dataService.createInstance === 'function'); }); it('should createInstance without client/clients support default', async () => { @@ -148,12 +148,12 @@ describe('test/singleton.test.ts', () => { create, }); singleton.init(); - assert(app.dataService === singleton); - assert(app.dataService instanceof Singleton); + assert.ok(app.dataService === singleton); + assert.ok(app.dataService instanceof Singleton); app.dataService = app.dataService.createInstance({ foo1: 'bar1' }); - assert(app.dataService instanceof DataService); - assert(app.dataService.config.foo1 === 'bar1'); - assert(app.dataService.config.foo === 'bar'); + assert.ok(app.dataService instanceof DataService); + assert.ok(app.dataService.config.foo1 === 'bar1'); + assert.ok(app.dataService.config.foo === 'bar'); }); it('should work with unextensible', async () => { @@ -181,9 +181,9 @@ describe('test/singleton.test.ts', () => { const dataService = await app.dataService.createInstanceAsync({ foo1: 'bar1', }); - assert(dataService instanceof DataService); - assert(dataService.config.foo1 === 'bar1'); - assert(dataService.config.foo === 'bar'); + assert.ok(dataService instanceof DataService); + assert.ok(dataService.config.foo1 === 'bar1'); + assert.ok(dataService.config.foo === 'bar'); }); it('should work with frozen', async () => { @@ -212,9 +212,9 @@ describe('test/singleton.test.ts', () => { const dataService = await app.dataService.createInstanceAsync({ foo1: 'bar1', }); - assert(dataService instanceof DataService); - assert(dataService.config.foo1 === 'bar1'); - assert(dataService.config.foo === 'bar'); + assert.ok(dataService instanceof DataService); + assert.ok(dataService.config.foo1 === 'bar1'); + assert.ok(dataService.config.foo === 'bar'); }); it('should work with no prototype and frozen', async () => { @@ -250,9 +250,9 @@ describe('test/singleton.test.ts', () => { }); singleton.init(); - assert(!app.dataService.createInstance); - assert(!app.dataService.createInstanceAsync); - assert(warn); + assert.ok(!app.dataService.createInstance); + assert.ok(!app.dataService.createInstanceAsync); + assert.ok(warn); }); it('should return client name when create', async () => { @@ -280,7 +280,7 @@ describe('test/singleton.test.ts', () => { }); singleton.init(); - assert(success); + assert.ok(success); }); }); @@ -297,9 +297,9 @@ describe('test/singleton.test.ts', () => { create: asyncCreate, }); await singleton.init(); - assert(app.dataService instanceof DataService); - assert(app.dataService.config.foo === 'bar'); - assert(typeof app.dataService.createInstance === 'function'); + assert.ok(app.dataService instanceof DataService); + assert.ok(app.dataService.config.foo === 'bar'); + assert.ok(typeof app.dataService.createInstance === 'function'); } }); @@ -318,10 +318,10 @@ describe('test/singleton.test.ts', () => { create: asyncCreate, }); await singleton.init(); - assert(app.dataService instanceof Singleton); - assert(app.dataService.get('first').config.foo === 'bar1'); - assert(app.dataService.get('second').config.foo === 'bar2'); - assert(typeof app.dataService.createInstance === 'function'); + assert.ok(app.dataService instanceof Singleton); + assert.ok(app.dataService.get('first').config.foo === 'bar1'); + assert.ok(app.dataService.get('second').config.foo === 'bar2'); + assert.ok(typeof app.dataService.createInstance === 'function'); }); it('should createInstanceAsync without client/clients support default', async () => { @@ -340,14 +340,14 @@ describe('test/singleton.test.ts', () => { create: asyncCreate, }); await singleton.init(); - assert(app.dataService === singleton); - assert(app.dataService instanceof Singleton); + assert.ok(app.dataService === singleton); + assert.ok(app.dataService instanceof Singleton); app.dataService = await app.dataService.createInstanceAsync({ foo1: 'bar1', }); - assert(app.dataService instanceof DataService); - assert(app.dataService.config.foo1 === 'bar1'); - assert(app.dataService.config.foo === 'bar'); + assert.ok(app.dataService instanceof DataService); + assert.ok(app.dataService.config.foo1 === 'bar1'); + assert.ok(app.dataService.config.foo === 'bar'); }); it('should createInstanceAsync throw error', async () => { @@ -367,7 +367,7 @@ describe('test/singleton.test.ts', () => { }); await singleton.init(); assert.equal(app.dataService, singleton); - assert(app.dataService instanceof Singleton); + assert.ok(app.dataService instanceof Singleton); await assert.rejects(async () => { await app.dataService.createInstance({ foo1: 'bar1' }); }, /\[@eggjs\/core\/singleton\] dataService only support asynchronous creation, please use createInstanceAsync$/); @@ -400,7 +400,7 @@ describe('test/singleton.test.ts', () => { await singleton.init(); - assert(success); + assert.ok(success); }); }); }); diff --git a/test/utils/index.test.ts b/test/utils/index.test.ts index 5f286883..d3269549 100644 --- a/test/utils/index.test.ts +++ b/test/utils/index.test.ts @@ -14,10 +14,10 @@ describe('test/utils/index.test.ts', () => { it('should load object', async () => { const filepath1 = utils.resolvePath(path.join(baseDir, 'object.js')); - assert(filepath1); + assert.ok(filepath1); const filepath2 = utils.resolvePath(path.join(baseDir, 'object')); - assert(filepath2, filepath1); - assert(filepath2.endsWith('.js'), filepath2); + assert.ok(filepath2, filepath1); + assert.ok(filepath2.endsWith('.js'), filepath2); }); }); @@ -46,14 +46,14 @@ describe('test/utils/index.test.ts', () => { it('should load es module', async () => { const result = await utils.loadFile(path.join(baseDir, 'es-module.js')); - assert(result.fn); + assert.ok(result.fn); }); it('should load es module with default', async () => { const result = await utils.loadFile( path.join(baseDir, 'es-module-default.js') ); - assert(result.fn); + assert.ok(result.fn); }); it('should load es module with default = null', async () => { @@ -67,14 +67,14 @@ describe('test/utils/index.test.ts', () => { const result = await utils.loadFile( path.join(baseDir, 'es-module-default-async.js') ); - assert(typeof result().then === 'function'); + assert.ok(typeof result().then === 'function'); }); it('should load es module with default = function returning a promise', async () => { const result = await utils.loadFile( path.join(baseDir, 'es-module-default-promise.js') ); - assert(typeof result().then === 'function'); + assert.ok(typeof result().then === 'function'); }); it('should load no js file', async () => { @@ -122,14 +122,14 @@ describe('test/utils/index.test.ts', () => { it('should load es module', async () => { const result = await utils.loadFile(path.join(baseDir, 'es-module.js')); - assert(result.fn); + assert.ok(result.fn); }); it('should load es module with default', async () => { const result = await utils.loadFile( path.join(baseDir, 'es-module-default.js') ); - assert(result.fn); + assert.ok(result.fn); }); it('should load es module with default = null', async () => { @@ -143,14 +143,14 @@ describe('test/utils/index.test.ts', () => { const result = await utils.loadFile( path.join(baseDir, 'es-module-default-async.js') ); - assert(typeof result().then === 'function'); + assert.ok(typeof result().then === 'function'); }); it('should load es module with default = function returning a promise', async () => { const result = await utils.loadFile( path.join(baseDir, 'es-module-default-promise.js') ); - assert(typeof result().then === 'function'); + assert.ok(typeof result().then === 'function'); }); it('should load no js file', async () => { diff --git a/test/utils/router.test.ts b/test/utils/router.test.ts index 74ac9eb8..1c730dcf 100644 --- a/test/utils/router.test.ts +++ b/test/utils/router.test.ts @@ -160,56 +160,56 @@ describe('test/utils/router.test.ts', () => { describe('router.url', () => { it('should work', () => { - assert(app.url('posts') === '/posts'); - - assert(app.router.url('posts') === '/posts'); - assert(app.router.url('members') === '/members'); - assert(app.router.url('post', { id: 1 }) === '/posts/1'); - assert(app.router.url('member', { id: 1 }) === '/members/1'); - assert(app.router.url('new_post') === '/posts/new'); - assert(app.router.url('new_member') === '/members/new'); - assert(app.router.url('edit_post', { id: 1 }) === '/posts/1/edit'); - assert(app.router.url('params', { a: 1, b: 2 }) === '/params/1/2'); + assert.ok(app.url('posts') === '/posts'); + + assert.ok(app.router.url('posts') === '/posts'); + assert.ok(app.router.url('members') === '/members'); + assert.ok(app.router.url('post', { id: 1 }) === '/posts/1'); + assert.ok(app.router.url('member', { id: 1 }) === '/members/1'); + assert.ok(app.router.url('new_post') === '/posts/new'); + assert.ok(app.router.url('new_member') === '/members/new'); + assert.ok(app.router.url('edit_post', { id: 1 }) === '/posts/1/edit'); + assert.ok(app.router.url('params', { a: 1, b: 2 }) === '/params/1/2'); // no match params - assert(app.router.url('edit_post', {}) === '/posts/:id/edit'); - assert(app.router.url('noname') === ''); - assert( + assert.ok(app.router.url('edit_post', {}) === '/posts/:id/edit'); + assert.ok(app.router.url('noname') === ''); + assert.ok( app.router.url('comment_index', { id: 1, a: 1 }) === '/comments/1?filter=&a=1' ); }); it('should work with unknow params', () => { - assert( + assert.ok( app.router.url('posts', { name: 'foo', page: 2 }) === '/posts?name=foo&page=2' ); - assert( + assert.ok( app.router.url('posts', { name: 'foo&?', page: 2 }) === '/posts?name=foo%26%3F&page=2' ); - assert( + assert.ok( app.router.url('edit_post', { id: 10, page: 2 }) === '/posts/10/edit?page=2' ); - assert( + assert.ok( app.router.url('edit_post', { i: 2, id: 10 }) === '/posts/10/edit?i=2' ); - assert( + assert.ok( app.router.url('edit_post', { id: 10, page: 2, tags: ['chair', 'develop'], }) === '/posts/10/edit?page=2&tags=chair&tags=develop' ); - assert( + assert.ok( app.router.url('edit_post', { id: [10], page: [2], tags: ['chair', 'develop'], }) === '/posts/10/edit?page=2&tags=chair&tags=develop' ); - assert( + assert.ok( app.router.url('edit_post', { id: [10, 11], page: [2], @@ -227,13 +227,13 @@ describe('test/utils/router.test.ts', () => { describe('router.pathFor', () => { it('should work', () => { - assert(app.router.pathFor('posts') === '/posts'); + assert.ok(app.router.pathFor('posts') === '/posts'); }); }); describe('router.method', () => { it('router method include HEAD', () => { - assert(app.router.methods.includes('HEAD')); + assert.ok(app.router.methods.includes('HEAD')); }); }); @@ -310,7 +310,7 @@ describe('test/utils/router.test.ts', () => { app.router.get('/test', app.controller.not_exist); throw new Error('should not run here'); } catch (err: any) { - assert(err.message.includes('controller not exists')); + assert.ok(err.message.includes('controller not exists')); } }); diff --git a/test/utils/timing.test.ts b/test/utils/timing.test.ts index ba6c8dbb..ffde7af5 100644 --- a/test/utils/timing.test.ts +++ b/test/utils/timing.test.ts @@ -14,13 +14,13 @@ describe('test/utils/timing.test.ts', () => { assert.equal(json.length, 3); assert.equal(json[1].name, 'a'); - assert(json[1].start); - assert(json[1].end); + assert.ok(json[1].start); + assert.ok(json[1].end); assert.equal(json[1].end - json[1].start, json[1].duration); assert.equal(json[1].pid, process.pid); assert.equal(json[2].name, 'b'); - assert(json[2].start); - assert(json[2].end); + assert.ok(json[2].start); + assert.ok(json[2].end); assert.equal(json[2].end - json[2].start, json[2].duration); assert.equal(json[2].pid, process.pid); @@ -34,7 +34,7 @@ describe('test/utils/timing.test.ts', () => { const json = timing.toJSON(); assert.equal(json[1].name, 'a'); - assert(json[1].start); + assert.ok(json[1].start); assert.equal(json[1].end, undefined); assert.equal(json[1].duration, undefined); }); @@ -115,8 +115,8 @@ describe('test/utils/timing.test.ts', () => { const processStart = timing .toJSON() .find(item => item.name === 'Process Start'); - assert(processStart); - assert(processStart.start); - assert(processStart.end); + assert.ok(processStart); + assert.ok(processStart.start); + assert.ok(processStart.end); }); }); From 2c632d62f04d11f1d9bcd227f8a9f57c9ca7010e Mon Sep 17 00:00:00 2001 From: MK Date: Sun, 31 Aug 2025 10:44:03 +0800 Subject: [PATCH 2/2] FIXUP --- .oxlintrc.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.oxlintrc.json b/.oxlintrc.json index b6fc10e6..2aa37719 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -69,6 +69,22 @@ "typescript/consistent-indexed-object-style": "allow", "typescript/no-explicit-any": "allow", "typescript/no-unnecessary-boolean-literal-compare": "allow", + "typescript/no-unsafe-member-access": "allow", + "typescript/no-unsafe-type-assertion": "allow", + "typescript/no-unsafe-call": "allow", + "typescript/no-unsafe-argument": "allow", + "typescript/no-misused-promises": "allow", + "typescript/promise-function-async": "allow", + "typescript/no-floating-promises": "allow", + "typescript/no-unsafe-assignment": "allow", + "typescript/require-await": "allow", + "typescript/no-unsafe-return": "allow", + "typescript/no-confusing-void-expression": "allow", + "typescript/prefer-promise-reject-errors": "allow", + "typescript/use-unknown-in-catch-callback-variable": "allow", + "typescript/non-nullable-type-assertion-style": "allow", + "typescript/unbound-method": "allow", + "typescript/restrict-template-expressions": "allow", // jsdoc "jsdoc/require-returns": "allow",