Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion commands/Make/Middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class MakeMiddleware extends BaseGenerator {
* We can look into configuring it later.
*/
protected getDestinationPath(): string {
return 'app/Middleware'
return this.getPathForNamespace('middleware') || 'app/Middleware'
}

public async run() {
Expand Down
28 changes: 28 additions & 0 deletions test/make-middleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,32 @@ test.group('Make Middleware', (group) => {
toNewlineArray(MiddlewareTemplate.replace('{{ filename }}', 'SpoofAccept'))
)
})

test('make a middleware inside a custom directory', async ({ assert }) => {
await fs.add(
'.adonisrc.json',
JSON.stringify({
namespaces: {
middleware: 'App/Module/Testing/Middleware',
},
autoloads: {
App: './app',
},
})
)

const rcContents = readJSONSync(join(fs.basePath, '.adonisrc.json'))
const app = new Application(fs.basePath, 'test', rcContents)

const middleware = new MakeMiddleware(app, new Kernel(app).mockConsoleOutput())
middleware.name = 'spoof_accept'
await middleware.run()

const SpoofMiddleware = await fs.get('app/Module/Testing/Middleware/SpoofAccept.ts')
const MiddlewareTemplate = await templates.get('middleware.txt')
assert.deepEqual(
toNewlineArray(SpoofMiddleware),
toNewlineArray(MiddlewareTemplate.replace('{{ filename }}', 'SpoofAccept'))
)
})
})