-
-
Notifications
You must be signed in to change notification settings - Fork 99
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: uvu is not detecting a thrown string #130
Comments
I'm not sure that it's a thrown string that is being missed, but if you clone the prettier-plugin-astro repo, and run |
minimal reproduction of the bug: |
ah, this is a duplicate of #60 |
It wouldnt be the same cause as 60. Your CSB doesn't work btw, 502 bad gateway |
yeah, i don't think that was the right way to write my reproduction - you need to open a new terminal and run 'yarn test' to see the output. codesandbox is expecting yarn start to exist and create an http server, but i don't want one 😅 |
Here's a better link for the reproduction: https://playground.denobr.com/801f4d5301 |
Think you forgot to save 😆 – that's just a "hello world" for a Deno playground. No need to fiddle with this. Saving your CSB file contents here & will repro locally soon: import { test } from "uvu";
test("this test should fail", () => {
console.log("before throw of string");
throw "not detected by uvu";
console.log("after throw of string");
throw Error("hmmmm");
});
test.run(); |
basically the console.logs are meant to demonstrate where the async function stops executing |
Yup, understood. |
The error is caused by |
function format(name, err, suite = '') {
let { details, operator='' } = err;
let idx = err.stack && err.stack.indexOf('\n');
if (err.name.startsWith('AssertionError') && !operator.includes('not')) details = compare(err.actual, err.expected); // TODO?
let str = ' ' + FAILURE + (suite ? kleur.red(SUITE(` ${suite} `)) : '') + ' ' + QUOTE + kleur.red().bold(name) + QUOTE;
str += '\n ' + err.message + (operator ? kleur.italic().dim(` (${operator})`) : '') + '\n';
if (details) str += GUTTER + details.split('\n').join(GUTTER);
if (!!~idx) str += stack(err.stack, idx);
return str + '\n';
} when |
Yes I know. I'm keeping this open as an exploration to see if it even makes sense to throw non-Errors. The entirety of uvu operates with Error primitives. That's how assertion control is orchestrated. Throwing things that are not Errors is not the same thing as throwing an Error. In other words, Tbh my inclination is to close this as unsupported, but going to play with it first. |
I would say that if you end up not supporting detecting non-Error() throws, that should be added to the documentation with a recommendation for how to correctly catch and rethrow them for uvu. Because I agree that encouraging Error() use is a good idea, but I haven't encountered many examples of using |
In #129 there's a function call that is only detected by uvu if i catch and rethrow it, it just fails to complete the test suite otherwise.
#129 (comment)
The text was updated successfully, but these errors were encountered: