Skip to content

Commit df4208c

Browse files
authored
fix: type defines (#185)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Chores** - Updated dependency versioning for increased compatibility and smoother upgrade paths. - **Refactor** - Enhanced internal logging mechanisms for improved flexibility and consistency. - **Tests** - Transitioned asynchronous request handling to modern async patterns for more reliable network operations. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 57e0715 commit df4208c

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"@types/methods": "^1.1.4",
6060
"@types/mocha": "10",
6161
"@types/node": "22",
62-
"egg": "beta",
62+
"egg": "^4.0.8",
6363
"egg-errors": "^2.2.1",
6464
"egg-tracer": "^2.0.0",
6565
"eslint": "8",

src/app/extend/application.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import mergeDescriptors from 'merge-descriptors';
66
import { isAsyncFunction, isObject } from 'is-type-of';
77
import { mock, restore } from 'mm';
88
import type { HttpClient } from 'urllib';
9-
import { Transport, EggLogger, LoggerLevel, LoggerMeta } from 'egg-logger';
9+
import { Transport, Logger, LoggerLevel, LoggerMeta } from 'egg-logger';
1010
import { EggCore, EggCoreOptions, Context } from '@eggjs/core';
1111
import { getMockAgent, restoreMockAgent } from '../../lib/mock_agent.js';
1212
import {
@@ -47,10 +47,6 @@ export default abstract class ApplicationUnittest extends EggCore {
4747
[key: string]: any;
4848
declare options: MockOptions & EggCoreOptions;
4949
_mockHttpClient?: MockHttpClientMethod;
50-
declare logger: EggLogger;
51-
declare coreLogger: EggLogger;
52-
abstract getLogger(name: string): EggLogger;
53-
declare httpClient: HttpClient;
5450
declare httpclient: HttpClient;
5551

5652
/**
@@ -404,7 +400,7 @@ export default abstract class ApplicationUnittest extends EggCore {
404400
* @param {String|Logger} [logger] - logger instance, default is `app.logger`
405401
* @function App#mockLog
406402
*/
407-
mockLog(logger?: string | EggLogger) {
403+
mockLog(logger?: string | Logger) {
408404
logger = logger ?? this.logger;
409405
if (typeof logger === 'string') {
410406
logger = this.getLogger(logger);
@@ -424,7 +420,7 @@ export default abstract class ApplicationUnittest extends EggCore {
424420
});
425421
}
426422

427-
__checkExpectLog(expectOrNot: boolean, str: string | RegExp, logger?: string | EggLogger) {
423+
__checkExpectLog(expectOrNot: boolean, str: string | RegExp, logger?: string | Logger) {
428424
logger = logger || this.logger;
429425
if (typeof logger === 'string') {
430426
logger = this.getLogger(logger);
@@ -460,7 +456,7 @@ export default abstract class ApplicationUnittest extends EggCore {
460456
* @param {String|Logger} [logger] - logger instance, default is `ctx.logger`
461457
* @function App#expectLog
462458
*/
463-
expectLog(str: string | RegExp, logger?: string | EggLogger) {
459+
expectLog(str: string | RegExp, logger?: string | Logger) {
464460
this.__checkExpectLog(true, str, logger);
465461
}
466462

@@ -470,7 +466,7 @@ export default abstract class ApplicationUnittest extends EggCore {
470466
* @param {String|Logger} [logger] - logger instance, default is `ctx.logger`
471467
* @function App#notExpectLog
472468
*/
473-
notExpectLog(str: string | RegExp, logger?: string | EggLogger) {
469+
notExpectLog(str: string | RegExp, logger?: string | Logger) {
474470
this.__checkExpectLog(false, str, logger);
475471
}
476472

src/typings/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// make sure to import egg typings and let typescript know about it
2+
// @see https://github.com/whxaxes/blog/issues/11
3+
// and https://www.typescriptlang.org/docs/handbook/declaration-merging.html
4+
import 'egg';

test/app_proxy.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('test/app_proxy.test.ts', () => {
3030

3131
it('should not set property', async () => {
3232
assert.throws(() => {
33-
app.curl = function* mockCurl() {
33+
(app as any).curl = async function mockCurl() {
3434
return 'mock';
3535
};
3636
}, /can't set curl before ready/);
@@ -100,11 +100,11 @@ describe('test/app_proxy.test.ts', () => {
100100
after(() => app.close());
101101

102102
it('should override property with setter', async () => {
103-
app.curl = async function mockCurl() {
103+
(app as any).curl = async function mockCurl() {
104104
return 'mock';
105105
};
106-
const data = await app.curl();
107-
assert(data === 'mock');
106+
const data = await app.curl('http://127.0.0.1:7001');
107+
assert.equal(data, 'mock');
108108
});
109109

110110
it('should ignore when set property on MockApplication', async () => {

0 commit comments

Comments
 (0)