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
chore: Refactor unit tests #2294
Conversation
Alright, I got functionality from 1st comment working. It still needs cleanup but most of logic is already there. EDIT: With removal of |
0daa669
to
f5c07f3
Compare
raise AssertionError("Bad js/unit_test.ts output") | ||
if expected != actual: | ||
print "expected", expected, "actual", actual | ||
raise AssertionError("expected tests did not equal actual") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic should be ported over to the runner too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is: up till now if one of tests failed remaining tests for other permissions were not run. I think we can safely spawn subprocesses for each permissions combination and return failure if any of them failed. That way all tests will always run, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds fine. But for each set of permissions there is a summary line printed. For example:
Running tests for: --allow-write --allow-run
running 1 tests
test runWithCwdIsAsync ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
The js/unit_tests_runner.ts needs to parse the first line (to determine how many tests there are) and then also parse the last line to check that passed matches. If we don't have this feature, it's possible for Deno to silently crash with exit code 0 and the tests all pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I'll add it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, so I've ported it to TS, but the thing is... There is no line-per-line output of unit tests ATM because there's no available lines
helper. I didn't want to copy over chunks
implemented by @kevinkassimo from xeval.ts
and there's no way to use it, because that file uses extensionless imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CC @ry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just copy it over add a todo ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I tried... It's not really possible since chunk
from xeval.ts
uses import from js/buffer.ts
so again there's conflict because of extensionless imports. I'm gonna leave it as is for now...
I've also added short summary at the end of run, because it's easy to miss if something went wrong at the beginning:
What do you think? |
I'm slightly concerned around running many processes in parallel on windows. @piscisaureus can you please check this branch on windows works for you:
|
Otherwise looks great! |
Processes are run serially. Also command you showed is unnecessary, you can just run There's also one more thing to solve, please see this comment
Thanks! |
I get this (freshly rebuilt):
|
@piscisaureus I've just pushed a fix |
|
@piscisaureus would you be willing to help out with debugging? Unfortunately I don't have access to Windows machine |
js/unit_test_runner.ts
Outdated
stdout: "piped" | ||
}); | ||
|
||
await p.status(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes the windows env hangs.
Commenting it make everything works as we wait for p.output()
after. Maybe this is a bug in the Deno.run
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zekth kudos for help 🙏 I'll update PR in the evening
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zekth Can you create an issue/test case for the Deno.run error? (assuming it's a bug!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hayd spent 1 hour trying to reproduce this, no luck for the moment. Raising an issue to track it.
Additionnal note: TLDR: there is no console test shown in my logs. But we have the same output : As i mentionned i've supposed a problem in the |
Okay so removing |
As this PR may land before resolving this behaviour it is revelant for me to raise an issue for this to track before having some other problems like this on windows |
|
||
let result = 0; | ||
|
||
if (!actual && !expected) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little difficult to read. I presume this is covering the case where actual and expected are both undefined? It could use a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Thanks for seeing this through.
This PR tries to resolve issue #2103.
In the first pass I've changed the behavior of Python script to run unit tests with every possible combination of permissions. This ensures that no test is skipped but requires to spawn separate Deno process for each combination even if there are no tests to run. This approach is really suboptimal.
My next step will be to first run a process to discover all tests and establish which perm combinations are used in test cases and then spawn new processes only for those combinations.
By the way, I think that this combination technique might be useful for users as well. Maybe we should consider implementing it in standard library? Eg. in deno-postgres I need to run tests once with
--allow-env
flag and second time without it, I'd be neat if this was built in without need to port this behavior.CC @ry