Skip to content

Commit

Permalink
fix onelogger
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Jan 1, 2025
1 parent 474fdce commit 411eac7
Show file tree
Hide file tree
Showing 11 changed files with 342 additions and 368 deletions.
2 changes: 2 additions & 0 deletions src/app/extend/context.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ declare module '@eggjs/core' {
get httpclient(): HttpClient;
get httpClient(): HttpClient;
getLogger(name: string): EggLogger;
get logger(): EggLogger;
get coreLogger(): EggLogger;
}
}
4 changes: 2 additions & 2 deletions test/fixtures/apps/logger-level-debug/app/router.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { sleep } = require('../../../../utils');
const { scheduler } = require('node:timers/promises');

module.exports = app => {
app.get('/', async function() {
this.logger.debug('hi %s %s', this.method, this.url);
// wait for writing to file
await sleep(1000);
await scheduler.wait(1000);
this.body = 'ok';
});
};
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
'use strict';
import { strict as assert } from 'node:assert';
import { createApp, startLocalServer, MockApplication } from '../../utils.js';

const assert = require('assert');
const utils = require('../../utils');

describe('test/lib/core/context_httpclient.test.js', () => {
let url;
let app;
describe('test/lib/core/context_httpclient.test.ts', () => {
let url: string;
let app: MockApplication;

before(() => {
app = utils.app('apps/context_httpclient');
app = createApp('apps/context_httpclient');
return app.ready();
});
before(async () => {
url = await utils.startLocalServer();
url = await startLocalServer();
});

it('should send request with ctx.httpclient', async () => {
const ctx = app.mockContext();
const httpclient = ctx.httpclient;
assert(ctx.httpclient === httpclient);
assert(httpclient.ctx === ctx);
assert((httpclient as any).ctx === ctx);
assert(typeof httpclient.request === 'function');
assert(typeof httpclient.curl === 'function');
const result = await ctx.httpclient.request(url);
Expand Down
23 changes: 0 additions & 23 deletions test/lib/core/context_httpclient_timeout.test.js

This file was deleted.

27 changes: 0 additions & 27 deletions test/lib/core/context_performance_starttime.test.js

This file was deleted.

25 changes: 25 additions & 0 deletions test/lib/core/context_performance_starttime.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { strict as assert } from 'node:assert';
import { createApp, MockApplication } from '../../utils.js';

describe('test/lib/core/context_performance_starttime.test.ts', () => {
let app: MockApplication;

before(() => {
app = createApp('apps/app-enablePerformanceTimer-true');
return app.ready();
});

it('should set ctx.performanceStarttime', () => {
const ctx = app.mockContext();
assert(ctx.performanceStarttime);
assert.equal(typeof ctx.performanceStarttime, 'number');
assert(typeof ctx.performanceStarttime === 'number' && ctx.performanceStarttime > 0);
});

it('should use ctx.performanceStarttime on controller', async () => {
const res = await app.httpRequest()
.get('/');
assert.equal(res.status, 200);
assert.match(res.text, /hello performanceStarttime: \d+\.\d+/);
});
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
'use strict';
import { mm } from '@eggjs/mock';
import { createApp, MockApplication } from '../../utils.js';

const mock = require('egg-mock');
const utils = require('../../utils');
describe('test/lib/core/custom_loader.test.ts', () => {
afterEach(mm.restore);

describe('test/lib/core/custom_loader.test.js', () => {
afterEach(mock.restore);

let app;
let app: MockApplication;
before(() => {
app = utils.app('apps/custom-loader');
app = createApp('apps/custom-loader');
return app.ready();
});
after(() => app.close());
Expand All @@ -29,5 +27,4 @@ describe('test/lib/core/custom_loader.test.js', () => {
.expect('beforeLoad')
.expect(200);
});

});
227 changes: 0 additions & 227 deletions test/lib/core/dnscache_httpclient.test.js

This file was deleted.

Loading

0 comments on commit 411eac7

Please sign in to comment.