Closed KidkArolis closed 1 year ago
Failing test case for feathers/test/hooks/after.test.ts
:
it.only('.after all and method specific hooks run in the correct order (#3002)', async () => {
const app = feathers().use('/dummy', {
async get(id: any) {
return { id, items: [] as any }
}
})
const service = app.service('dummy')
service.hooks({
after: {
all(context) {
context.result.items.push('first')
return context
},
get: [
function (context) {
context.result.items.push('second')
return context
},
function (context) {
context.result.items.push('third')
return context
}
]
}
})
const data = await service.get(10)
assert.deepStrictEqual(data.items, ['first', 'second', 'third'])
})
Steps to reproduce
If a service has the following hooks:
In V4 it outputs:
In V5 it outputs:
My best current understanding is that it's because of how the before/after/error hooks get collected in a single "collected" chain using the new around hook mechanic here: https://github.com/feathersjs/feathers/blob/5854dea7f610262121a49623ec5bbd474dcd3ef3/packages/feathers/src/hooks.ts#L60-L65
What happens is that the when we spread all and then method specific hooks:
The order for the after hooks becomes:
afterAll() { await next() context => console.log('After all') }
afterFind() { await next() context => console.log('After find') }
and when that unwinds we first yield after find and then after all in that (backwards incompatible) order.
Expected behavior
V5 keeps backwards compatibility in the hooks and logs:
System configuration
Module versions: @feathersjs/feathers@5.0.0-pre.35