-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
[Bug]: vitest
complains about unhandled error when using @LogAll
decorator
#1741
Comments
This is very interesting. Thank you for the reproduction. All that the It does happen in other test runners, so something is getting modified in an unexpected way. I'll try to look into it |
I think this is because the const TestDec = () => {
return (target, propertyKey, descriptor) => {
const impl = descriptor.value;
descriptor.value = function (...args) {
const res = impl.apply(this, ...args);
res.finally(() => {
console.log('added finally');
});
return res;
};
return descriptor;
};
};
class Foo {
@TestDec()
foo() {
return Promise.reject('Boo!');
}
}
it('testing plain decorator', async () => {
const foo = new Foo();
await expect(foo.foo()).rejects.toThrow();
}); Not sure what to do about it just yet, but I'll keep searching through some more obscure stuff |
I noticed that making either of the following changes will suppress the warning from vitest. Could the issue be related to this: https://typescript-eslint.io/rules/no-floating-promises/ const TestDec = () => {
return (target, propertyKey, descriptor) => {
const impl = descriptor.value;
- descriptor.value = function (...args) {
+ descriptor.value = async function (...args) {
const res = impl.apply(this, ...args);
- res.finally(() => {
+ await res.finally(() => {
console.log('added finally');
});
return res;
};
return descriptor;
};
}; or const TestDec = () => {
return (target, propertyKey, descriptor) => {
const impl = descriptor.value;
descriptor.value = function (...args) {
const res = impl.apply(this, ...args);
- res.finally(() => {
+ return res.finally(() => {
console.log('added finally');
});
- return res;
};
return descriptor;
};
}; |
The latter would be preferable, as I don't want to modify synchronous functions to become async. I'll double check this tomorrow and get some test cases written |
Is there an existing issue for this?
Current behavior
The tests pass, but when an (a) an error is thrown inside an async function and (b) we're using ogma's
LogAll()
decorator, then vitest will complain.Error:
Minimum reproduction code
https://github.com/thenbe/repro-ogma-vitest
Steps to reproduce
Expected behavior
Vitest should not complain, just like the first test.
Package(s) version
@ogma/cli
:@ogma/common
:@ogma/logger
:@ogma/nestjs-module
: "^5.1.1"@ogma/platform-express
:@ogma/platform-fastify
:@ogma/platform-graphql-fastify
:@ogma/platform-graphql
:@ogma/platform-grpc
:@ogma/platform-kafka
:@ogma/platform-mqtt
:@ogma/platform-nats
:@ogma/platform-rabbitmq
:@ogma/platform-redis
:@ogma/platform-socket.io
:@ogma/platform-tcp
:@ogma/platform-ws
:@ogma/styler
:Node.js version
18.16.1
In which operating systems have you tested?
Other
I haven't used ogma before, so if I can't tell if this is a genuine bug or if I'm doing something I shouldn't.
The text was updated successfully, but these errors were encountered: