-
-
Notifications
You must be signed in to change notification settings - Fork 347
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
Switch to tape or mocha/karma? #115
Comments
I've never used test framework other than jest. I think our tests are running well now, and it may not be better to change the framework, so I think this may be able to pause? I had a hard time understanding our test code, and I think most of our problems have been solved. Is tape more popular than jest? If so, is it possible for us to use it in fre2? |
Well, Jest is by far the most popular of those two - but I've seen many people asking/commenting on the same issues we've run into, and the situation doesn't seem to be improving. I suspect that Jest is mostly popular because it's the de-facto standard test-framework for anyone who uses React - they have facilities specifically designed for that, so... many React users -> many Jest users. My main concern about Jest is, I don't feel like I can trust it - I don't even know if it's running all the tests or hitting all the assertions... things often look fine, and then I discover down the line that I forgot an I don't know if all our tests are actually passing for the right reasons - as you saw, it's completely possible to write a test with a loop full of assertions that Jest just ignores because you called From what I can tell, Our test code wouldn't really change much at all - tests are still just functions being passed to a Anyhow, let's leave this here for now and think about it... |
I'm sorry for using In fact, I have little experience in testing. Thank you very much for your guidance and help. I think we can open this issue and come back after settling for a while…… |
hey, I think we can continue this issue now, thank you for your proposal. |
Okay, so I think the first step is just to get the change from #117 ported over to If that doesn't help, we'll know the problem isn't Jest (which could mean it's JS-DOM or something else we haven't thought of) and that'll help us decide whether to proceed with |
Ok 😉 |
Man, it's worse than I thought... I was using I dug into I also poked around in Jest's fake implementation of timers to answer another question: what happens to timers that run too late? It turns out, these get destroyed and won't finish executing if the JS-DOM instance is cleaned up. This explains why a line like this one actually executes, even though it's being run after the JS-DOM instances has been cleaned up: the fake timers (if they're even fake?) are an entirely different implementation than the one in Jest. These differences could give us even more problems rather than solving them. At this point, I'm sort of fed up with We could still use I think maybe This is turning out to be quite the adventure, ha ha. 😂 |
If only performance is not supported, then polyfills can be found, and I don't think js-dom is a good choice. |
I've gotten one test ported to So I've attempted to create a repeatable headless Chromium setup with I've also tried with the I don't think |
I don't think our test needs to be so troublesome. It doesn't need headless browser(such as puppeteer), but only Dom and BOM. import undom from 'undom'
import performance from 'performance-polyfill' We only need a small Dom and BOM to simulate the variables used by fre, such as The difference between now and |
I wouldn't trust It's the same problem as with Frameworks really need to be tested against a real browser. At the very least, I think we need an option to run the tests on a local browser during development - even if we have to run them with polyfills on the CI server, at least someone can do a real browser-based test on their local system before pushing a change. |
It is hard to test the scheduler, not only fre, but also react, But I think this is not about headless browser. we just have not found a way to test it in node. |
Maybe devtools or this |
Well, finally some good news! I scrapped More good news: this is the reconciliation test that we couldn't get to work with So it looks like there's a way forward with I'll try to port the rest of the test-suite one of the coming days. 🙂 I will say again though: a passing test with mocks for For now, I'm happy get rid of |
@mindplay-dk Wow great, look forward to it!
I see, so we can only test DOM in node, and then test scheduler through chrome panel in the future. |
Well, it'll run the full suite of tests - just that those tests will be effectively testing the integration with a bunch of mocks and stubs, whereas what we're really interested in is integration with a browser. But we'll figure out later how to run the tests without the mocks and stubs. 🙂 |
Well, I'm stuck again. 😣 The problem is once again To explain the problem, I've isolated a very simple test on a branch. I've put a bunch of log statements in
As you can see, the test somehow exits before The update-test itself says Maybe this I've spent more than half a day trying to solve it - I have no ideas. 😐 |
How should I debug your code? Without debugging, it seems that it is because of await testUpdates([
{
<Compoent value={[]}/>, //give it a props to rerender
test: ([button]) => {
is.equal(+button.textContent, 0)
is.equal(updates, 1)
// trigger several functional state updates:
// button.click()
// button.click()
// button.click()
}
} I want to debug the code. Is there any way to pull your branche? |
In this particular case, the component doesn't need to be updated by But first problem is to get the test to actually run at all - before the script exits.
You want to add a remote, then check out (not pull) my branch. |
You were right - I finally got that test to pass, I just had to use the Will post an update soon. |
@mindplay-dk In fact, another optimization is hit here. When the state does not change, the component will not be updated.
It should be like this: setContent(<Component />)
setContent(<Component />) |
For the record, a lot of the test issues you've been closing, those tests don't actually work - many of the assertions aren't being run at all... I had started porting the tests to another framework called And there are still problems with that branch - for one, it suffers from the same problem as current tests: some tests will pass when run individually, but they will fail when you run them together, due to race conditions. Sorry, but I can't keep up - too many things are changing daily, and I can't port and fix the entire test-suite fast enough to finish before my work is already outdated and can't be merged. I'm going to take a break as I'm wasting too much time on work I can't finish... |
@mindplay-dk Thank you very much, don't rush, take your time. I recently checked that ,I'm sick and I need to be hospitalized. treatment is needed and I need to paused few months. Let's wait together. |
Sorry to hear that! I hope you get well soon. 🌻 |
Just to mention that this is written in Typescript and tape doesn't like Typescript at all. The devs don't want to support it or have anything to do with it from what i've seen in the issues. That might be an issue at some point too. Jest is bigger but well adapted for UI library like React, Fre, etc Just giving my 2 cents here :) |
https://www.npmjs.com/package/@web/test-runner Do you know test-runner? This is a popular testing tool recently, it supports headless browsers. The reason fre doesn't want to use jest is because jest cannot accurately simulate browser behavior, which makes our testing more difficult, especially time slicing and tearing. We need to use a headless browser to ensure accurate behavior. I hope I can switch to test-runner and try it together? |
A lot of people use Cypress to test browser behavior, is it what you look for? Took a quick look at test-runner, seems different than Cypress. Also look pretty nice, using I don't know test-runner, i'm no expert in testing framework, especially browser ones like cypress or test-runner. I alway find them super heavy and too time consuming for not much return (talking from a agency/product company point of view, for library like |
Yes they are very heavy. The test task is given to CI, and the best result is that developers need not to install huge dependencies. In order to test the features of concurrent mode, we have to do this, because fre rendering is asynchronous, it needs more test case accuracy than synchronous. Let me try it next, I hope such a heavy thing can bring benefits. |
When i talk about heavy, i'm talking about the time it takes to get them to work and maintained for the dev. Size is not really an issue when it comes to dev tools since it's mostly run on CI like you said. But in my previous company, they had cypress and maintaining that took more time than making features lol (not even talking about the time it took to run the tests on CI, half the time was cypress tests even in async) But for |
What do you think about switching from
jest
totape
?I've got a preliminary setup here:
master...mindplay-dk:use-tape
This is unfinished -
tape
is much simpler thanjest
, but it doesn't come with "batteries included", so it takes more work to set this up.For now, I have Babel with JSX and
async
support working - this seems already much safer, because I can clean up JS-DOM after each test, which means that timeouts get flushed, which meanstape
can catch assertions that run after the promise resolves. (the commented-out lines demonstrate this.)I still need to set up code coverage and XML reporting for CI integration - before I can port the actual tests, so a lot of work left.
Do you think I should continue with this?
The text was updated successfully, but these errors were encountered: