Skip to content

Commit 411eac7

Browse files
committed
1 parent 474fdce commit 411eac7

11 files changed

Lines changed: 342 additions & 368 deletions

src/app/extend/context.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ declare module '@eggjs/core' {
1717
get httpclient(): HttpClient;
1818
get httpClient(): HttpClient;
1919
getLogger(name: string): EggLogger;
20+
get logger(): EggLogger;
21+
get coreLogger(): EggLogger;
2022
}
2123
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const { sleep } = require('../../../../utils');
1+
const { scheduler } = require('node:timers/promises');
22

33
module.exports = app => {
44
app.get('/', async function() {
55
this.logger.debug('hi %s %s', this.method, this.url);
66
// wait for writing to file
7-
await sleep(1000);
7+
await scheduler.wait(1000);
88
this.body = 'ok';
99
});
1010
};
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
'use strict';
1+
import { strict as assert } from 'node:assert';
2+
import { createApp, startLocalServer, MockApplication } from '../../utils.js';
23

3-
const assert = require('assert');
4-
const utils = require('../../utils');
5-
6-
describe('test/lib/core/context_httpclient.test.js', () => {
7-
let url;
8-
let app;
4+
describe('test/lib/core/context_httpclient.test.ts', () => {
5+
let url: string;
6+
let app: MockApplication;
97

108
before(() => {
11-
app = utils.app('apps/context_httpclient');
9+
app = createApp('apps/context_httpclient');
1210
return app.ready();
1311
});
1412
before(async () => {
15-
url = await utils.startLocalServer();
13+
url = await startLocalServer();
1614
});
1715

1816
it('should send request with ctx.httpclient', async () => {
1917
const ctx = app.mockContext();
2018
const httpclient = ctx.httpclient;
2119
assert(ctx.httpclient === httpclient);
22-
assert(httpclient.ctx === ctx);
20+
assert((httpclient as any).ctx === ctx);
2321
assert(typeof httpclient.request === 'function');
2422
assert(typeof httpclient.curl === 'function');
2523
const result = await ctx.httpclient.request(url);

test/lib/core/context_httpclient_timeout.test.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

test/lib/core/context_performance_starttime.test.js

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { strict as assert } from 'node:assert';
2+
import { createApp, MockApplication } from '../../utils.js';
3+
4+
describe('test/lib/core/context_performance_starttime.test.ts', () => {
5+
let app: MockApplication;
6+
7+
before(() => {
8+
app = createApp('apps/app-enablePerformanceTimer-true');
9+
return app.ready();
10+
});
11+
12+
it('should set ctx.performanceStarttime', () => {
13+
const ctx = app.mockContext();
14+
assert(ctx.performanceStarttime);
15+
assert.equal(typeof ctx.performanceStarttime, 'number');
16+
assert(typeof ctx.performanceStarttime === 'number' && ctx.performanceStarttime > 0);
17+
});
18+
19+
it('should use ctx.performanceStarttime on controller', async () => {
20+
const res = await app.httpRequest()
21+
.get('/');
22+
assert.equal(res.status, 200);
23+
assert.match(res.text, /hello performanceStarttime: \d+\.\d+/);
24+
});
25+
});
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
'use strict';
1+
import { mm } from '@eggjs/mock';
2+
import { createApp, MockApplication } from '../../utils.js';
23

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

6-
describe('test/lib/core/custom_loader.test.js', () => {
7-
afterEach(mock.restore);
8-
9-
let app;
7+
let app: MockApplication;
108
before(() => {
11-
app = utils.app('apps/custom-loader');
9+
app = createApp('apps/custom-loader');
1210
return app.ready();
1311
});
1412
after(() => app.close());
@@ -29,5 +27,4 @@ describe('test/lib/core/custom_loader.test.js', () => {
2927
.expect('beforeLoad')
3028
.expect(200);
3129
});
32-
3330
});

test/lib/core/dnscache_httpclient.test.js

Lines changed: 0 additions & 227 deletions
This file was deleted.

0 commit comments

Comments
 (0)