This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: parse and mount route when routes was called.
to avoid plugin not mount finish, but the route was mounted.
- Loading branch information
1 parent
82f60e9
commit 3639983
Showing
3 changed files
with
84 additions
and
2 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
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,71 @@ | ||
import { init, Plugin } from '../helpers'; | ||
|
||
describe('Plugin multi', () => { | ||
it('multi plugin, should success', async () => { | ||
class PluginX extends Plugin { | ||
constructor() { | ||
super(); | ||
|
||
this.field = 'parameters'; | ||
} | ||
handler() { | ||
const { args } = this; | ||
|
||
return (ctx, next) => { | ||
ctx.value = args; | ||
|
||
return next(); | ||
}; | ||
} | ||
} | ||
|
||
class PluginY extends Plugin { | ||
constructor() { | ||
super(); | ||
|
||
this.field = 'parameters'; | ||
} | ||
handler() { | ||
const { args } = this; | ||
|
||
return (ctx, next) => { | ||
ctx.value += args; | ||
|
||
return next(); | ||
}; | ||
} | ||
} | ||
|
||
class PluginZ extends Plugin { | ||
constructor() { | ||
super(); | ||
|
||
this.field = 'parameters'; | ||
} | ||
handler() { | ||
const { args } = this; | ||
|
||
return (ctx, next) => { | ||
ctx.value += args; | ||
|
||
ctx.response.body = ctx.value; | ||
}; | ||
} | ||
} | ||
|
||
const { request } = await init({ | ||
apiDoc: './test/plugin/api', | ||
plugins: [PluginX, PluginY, PluginZ], | ||
options: { | ||
PluginX: 'x', | ||
PluginY: 'y', | ||
PluginZ: 'z', | ||
}, | ||
}); | ||
|
||
await request | ||
.get('/api/pets') | ||
.expect(200) | ||
.expect('xyz'); | ||
}); | ||
}); |