-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(egg): skip loadRouter in metadataOnly mode #5847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| module.exports = class MetadataOnlyBoot { | ||
| constructor(app) { | ||
| this.app = app; | ||
| app.bootLog = []; | ||
| } | ||
|
|
||
| configWillLoad() { | ||
| this.app.bootLog.push('configWillLoad'); | ||
| } | ||
|
|
||
| configDidLoad() { | ||
| this.app.bootLog.push('configDidLoad'); | ||
| } | ||
|
|
||
| async didLoad() { | ||
| this.app.bootLog.push('didLoad'); | ||
| } | ||
|
|
||
| async willReady() { | ||
| this.app.bootLog.push('willReady'); | ||
| } | ||
|
|
||
| async didReady() { | ||
| this.app.bootLog.push('didReady'); | ||
| } | ||
|
|
||
| async serverDidReady() { | ||
| this.app.bootLog.push('serverDidReady'); | ||
| } | ||
|
|
||
| async beforeClose() { | ||
| this.app.bootLog.push('beforeClose'); | ||
| } | ||
|
|
||
| async loadMetadata() { | ||
| this.app.bootLog.push('loadMetadata'); | ||
| } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| module.exports = async function () { | ||
| this.body = 'hello'; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| module.exports = (app) => { | ||
| app.get('/', app.controller.home); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "name": "metadata-only-app" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,66 +1,58 @@ | ||
| import { describe } from 'vitest'; | ||
| import { strict as assert } from 'node:assert'; | ||
|
|
||
| // import utils from '../utils'; | ||
| // import assert from 'assert'; | ||
| // import path from 'path'; | ||
| import { describe, it, afterAll, beforeAll } from 'vitest'; | ||
|
|
||
| // let app; | ||
| import { singleProcessApp, type SingleModeApplication } from './utils.ts'; | ||
|
|
||
| describe.skip('test/lib/start.test.js', () => { | ||
| // afterEach(() => app.close()); | ||
| // describe('start', () => { | ||
| // it('should dump config and plugins', async () => { | ||
| // app = await utils.singleProcessApp('apps/demo'); | ||
| // const baseDir = utils.getFilepath('apps/demo'); | ||
| // let json = require(path.join(baseDir, 'run/agent_config.json')); | ||
| // assert(/\d+\.\d+\.\d+/.test(json.plugins.onerror.version)); | ||
| // assert(json.config.name === 'demo'); | ||
| // assert(json.config.tips === 'hello egg'); | ||
| // json = require(path.join(baseDir, 'run/application_config.json')); | ||
| // checkApp(json); | ||
| // const dumpped = app.dumpConfigToObject(); | ||
| // checkApp(dumpped.config); | ||
| // function checkApp(json) { | ||
| // assert(/\d+\.\d+\.\d+/.test(json.plugins.onerror.version)); | ||
| // assert(json.config.name === 'demo'); | ||
| // // should dump dynamic config | ||
| // assert(json.config.tips === 'hello egg started'); | ||
| // } | ||
| // }); | ||
| // it('should request work', async () => { | ||
| // app = await utils.singleProcessApp('apps/demo'); | ||
| // await app.httpRequest().get('/protocol') | ||
| // .expect(200) | ||
| // .expect('http'); | ||
| // await app.httpRequest().get('/class-controller') | ||
| // .expect(200) | ||
| // .expect('this is bar!'); | ||
| // }); | ||
| // it('should env work', async () => { | ||
| // app = await utils.singleProcessApp('apps/demo', { env: 'prod' }); | ||
| // assert(app.config.env === 'prod'); | ||
| // }); | ||
| // }); | ||
| // describe('custom framework work', () => { | ||
| // it('should work with options.framework', async () => { | ||
| // app = await utils.singleProcessApp('apps/demo', { framework: path.join(__dirname, '../fixtures/custom-egg') }); | ||
| // assert(app.customEgg); | ||
| // await app.httpRequest().get('/protocol') | ||
| // .expect(200) | ||
| // .expect('http'); | ||
| // await app.httpRequest().get('/class-controller') | ||
| // .expect(200) | ||
| // .expect('this is bar!'); | ||
| // }); | ||
| // it('should work with package.egg.framework', async () => { | ||
| // app = await utils.singleProcessApp('apps/custom-framework-demo'); | ||
| // assert(app.customEgg); | ||
| // await app.httpRequest().get('/protocol') | ||
| // .expect(200) | ||
| // .expect('http'); | ||
| // await app.httpRequest().get('/class-controller') | ||
| // .expect(200) | ||
| // .expect('this is bar!'); | ||
| // }); | ||
| // }); | ||
| describe('test/start.test.ts', () => { | ||
| describe('metadataOnly mode', () => { | ||
| let app: SingleModeApplication; | ||
|
|
||
| beforeAll(async () => { | ||
| app = await singleProcessApp('apps/metadata-only-app', { metadataOnly: true }); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await app.close(); | ||
| }); | ||
|
|
||
| it('should only call loadMetadata, not normal lifecycle hooks', () => { | ||
| assert.deepStrictEqual(app.bootLog, ['loadMetadata']); | ||
| }); | ||
|
|
||
| it('should skip loadRouter — no routes registered', () => { | ||
| assert.strictEqual(app.router.stack.length, 0); | ||
| }); | ||
|
|
||
| it('should not create agent', () => { | ||
| assert.strictEqual(app.agent, undefined); | ||
| }); | ||
|
Comment on lines
+27
to
+29
|
||
| }); | ||
|
|
||
| describe('normal mode (baseline)', () => { | ||
| let app: SingleModeApplication; | ||
|
|
||
| beforeAll(async () => { | ||
| app = await singleProcessApp('apps/metadata-only-app'); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await app.close(); | ||
| }); | ||
|
|
||
| it('should call normal lifecycle hooks, not loadMetadata', () => { | ||
| assert(app.bootLog.includes('configDidLoad')); | ||
| assert(app.bootLog.includes('didLoad')); | ||
| assert(app.bootLog.includes('willReady')); | ||
| assert(!app.bootLog.includes('loadMetadata')); | ||
| }); | ||
|
|
||
| it('should register routes', () => { | ||
| assert(app.router.stack.length > 0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }); | ||
|
|
||
| it('should create agent', () => { | ||
| assert(app.agent); | ||
| }); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard teardown against setup failure in
afterAll.If
beforeAllfails,appcan be unset andapp.close()throws, which can mask the original failure (Line 16 and Line 40).🛠️ Suggested fix
Also applies to: 39-41
🤖 Prompt for AI Agents