-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
176 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { MiddlewareFunc } from '../../src/index.js'; | ||
|
||
export const hello: MiddlewareFunc = async (ctx, next) => { | ||
console.log('Hello middleware'); | ||
console.log(ctx.app.BaseContextClass); | ||
console.log(ctx.app.Service); | ||
console.log(ctx.service); | ||
console.log(ctx.app.timing); | ||
console.log(ctx.app.lifecycle); | ||
console.log(ctx.request.ctx.app.timing); | ||
console.log(ctx.request.app.timing); | ||
console.log(ctx.request.response.app.timing); | ||
console.log(ctx.response.request.app.timing); | ||
await next(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export default async function() { | ||
const status = Number(this.query.status || 200); | ||
this.status = status; | ||
this.etag = '2.2.2.2'; | ||
this.body = { | ||
returnAppContext: this.appContext, | ||
returnAppRequest: this.request.appRequest, | ||
returnAppResponse: this.response.appResponse, | ||
returnAppApplication: this.app.appApplication, | ||
status: this.status, | ||
etag: this.etag, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { EggCore } from '../../../../../src/index.js' | ||
|
||
export default class Application extends EggCore { | ||
get appApplication() { | ||
return 'app application'; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Context } from '../../../../../src/index.js' | ||
|
||
export default class MyContext extends Context { | ||
get appContext() { | ||
return this.app ? 'app context' : 'no app context'; | ||
} | ||
|
||
ajax() { | ||
return 'app ajax patch'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Request } from '../../../../../src/index.js' | ||
|
||
export default class AppRequest extends Request { | ||
get appRequest() { | ||
return this.response.app.timing ? 'app request' : 'no app request'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Response } from '../../../../../src/index.js' | ||
|
||
export default class AppResponse extends Response { | ||
get appResponse() { | ||
return this.app.timing ? 'app response' : 'no app response'; | ||
} | ||
|
||
set status(code) { | ||
this._explicitStatus = true; | ||
this.res.statusCode = code; | ||
this.res.statusMessage = 'http status code ' + code; | ||
} | ||
|
||
get etag() { | ||
return 'etag ok'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default (app) => { | ||
app.get('/', app.controller.home); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "extend-with-class", | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { strict as assert } from 'node:assert'; | ||
import request from 'supertest'; | ||
import mm from 'mm'; | ||
import { Application, createApp } from '../../helper.js'; | ||
|
||
describe('test/loader/mixin/load_extend_class.test.ts', () => { | ||
let app: Application; | ||
before(async () => { | ||
app = createApp('extend-with-class'); | ||
await app.loader.loadPlugin(); | ||
await app.loader.loadConfig(); | ||
await app.loader.loadRequestExtend(); | ||
await app.loader.loadResponseExtend(); | ||
await app.loader.loadApplicationExtend(); | ||
await app.loader.loadContextExtend(); | ||
await app.loader.loadController(); | ||
await app.loader.loadRouter(); | ||
await app.loader.loadMiddleware(); | ||
}); | ||
after(() => app.close()); | ||
afterEach(mm.restore); | ||
|
||
it('should load app.context app.request app.response', () => { | ||
assert((app as any).appApplication); | ||
|
||
return request(app.callback()) | ||
.get('/') | ||
.expect({ | ||
returnAppContext: 'app context', | ||
returnAppRequest: 'app request', | ||
returnAppResponse: 'app response', | ||
returnAppApplication: 'app application', | ||
status: 200, | ||
etag: 'etag ok', | ||
}) | ||
.expect(200); | ||
}); | ||
}); |