-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Browser support #24
Comments
Maybe open an issue on Browserify about shimming |
Found a bit more discussion upstream: browserify/insert-module-globals#40 |
I'll give it a week, but I doubt anything will happen there... I guess I can add https://github.com/sindresorhus/set-immediate-shim if that is the only thing blocking it from being used in the browser. |
Isn't it just a fancy way of doing |
@Qix- It's faster than http://www.nczonline.net/blog/2013/07/09/the-case-for-setimmediate/ |
@vdemedes thanks for the fix! The But now I’ve got another bastard there:
– coming from https://github.com/kevva/squeak/blob/v1.2.0/index.js#L144. |
@tomekwi You're welcome! I see what the problem is, will try to not forget and fix it! |
Great! I can’t wait to check out this awesome trio: hihat, ava and quixote! quixote doesn’t go well with tape, because it’s an assertion library. So I end up with lots of glue code in tests and lose the pretty format of error messages. |
Another cool tool, |
In the browser |
Shimming |
same issue with https://github.com/kevva/squeak/blob/v1.2.0/index.js#L144 :( |
Browserify should already shim |
Browserify shims I think that causes https://github.com/kevva/squeak/blob/v1.2.0/index.js#L26 to be undefined and line 144 to fail. |
I guess we can make |
I tweaked the constructor and injected the console in This seems to fix the issue. I can run I get some errors about ATM, I think it would be better to monkey patch EDIT: maybe these patches should be done in |
Yeah. I guess we could replace the And
|
Happy to recommend |
Added a ticket about exit: Experience-Monks/hihat#27 Not sure about shimming stderr/stdout in browserify. Seems like browserify's |
With that said; maybe a dumb polyfill could just write console.log and error synchronously, but not attempt to support any other aspect of the stdout/stderr streams. |
This is the line that fails with the As for process.stderr I think the issue is not as straightforward as I thought.
The issue with |
Agreed.
How would it do that? Prefix the console output with logging level? |
With the following (hacky) change in var log = new Squeak({separator: ' ', stream: {write: console.log.bind(console)}}); all the logs from type Ideally, one would like to have the following mappings between
winston offers such functionality (and multiple transports too), but it's not browserify friendly. I think the quickest win in this case would be to use as an example var logError = console.error.bind(console, figures.cross); That would work in node and in the browser. |
Shouldn't be hard to patch |
I am wondering if there is anything that I could do to help with this. Personally I wouldn't even mind if those tests would not run in parallel. If I delegate test running to some service like Saucelabs and it will run all tests in series for each browser, it should be more than fine. Going for hassle with web workers just seems like overkill. |
I think that's a fine first goal, and if it gets us to browser support faster, so be it.
We've identified other problems with web workers (see above), so that's definitely off the table. That said, isolation is way more important than parallel execution. The two best solutions for isolation (WebWorkers and iframes) also facilitate parallel execution, so I'm not sure we need to punt on either for long. I think iframes should work OK. We may need to come up with something to allow for apps that care about
Reviewing and commenting on #887 is a good start. If you've got alternate ideas, proof-of-concept PR's wouldn't hurt. |
Sounds to me like trying to cover for some eventuality that is actually rarely needed. Or at least I don't have any experience when I would need to rely on In my case it's merely about having ability to run library unit tests in browser environment to ensure there isn't some incompatibility. As much as its nice to have tests written in same way, I wouldn't probably choose Ava for writing/running E2E tests as there are surely some other more mature tools for that. I will have a look at that PR, thanks. |
Yeah, surely iframe issues are rare, but if you never know what hacks polyfills and such have to rely on. Also what happens when two iframes try to interact with the History API? That's another one |
Hmm. Maybe we should start with running test files one at a time, top-level, launching a new browser/tab for each one. That will be really slow, but it's probably the easiest to accomplish. Then we can work towards parallelism. |
That sounds like a splendid idea. |
I'm curious what kind of browser support people are looking for.
Please add anything else that seems relevant to the discussion. |
I'd use this on Travis+SauceLabs to verify real compatibility with browsers, rather than "compatibility with jsdom." My issue is I have no experience in setting this up, so documentation specific to AVA+selenium would be great, perhaps that's the only thing missing. |
I give it a try with my current setup and use cases. On local (developer) machine tests get executed in jsdom environment for best performance. On CI server these tests should run in a real browser environment. If one of these tests fail, I want to be able to debug it with browsers dev tools.
CLI or file to save it for each build.
Both is needed to run a specific test in a specific browser and automate the process in a whole?
Not used these kind of tools for a long time, no real opinion here, but BroswerStack sounds good.
As this are unit tests, I think dev compiled is ok. Productivity compiled code is for integration tests, I would say. Test code/setup should be configurable like the "--require" flag already does, at the moment I setup jsdom with this flag. |
Can the title of this issue be set to "Browser support". The "Browserify" part makes it sound off-topic. |
Done |
I am finding a way to do angular 2 unit test. All I could find is karma + jasmine + browser launcher. What I expect is I could use AVA to tackle it, so this issue looks like working on providing a browser environment for client side code. I have tried |
I'm currently playing around with using AVA to unit test a framework I'm working on (wooo Observables!), but without being able to run the unit tests themselves in the browser, it's a non-starter. I'm definitely interested in helping out; I played around with Is there any movement on this, or anything I can look at or help out with? |
@mAAdhaTTah we're still evolving AVA's internals too much to really commit to browser support, sorry. |
To be really specific, the ideal outcome for Mixmax would be for Ava to work with the Karma test runner. What Karma lets you do is take the same test files that you would run in a Node environment, and run them using real browsers or devices or PhantomJS or headless Chrome instances. Karma launches the browser, and logs results to the CLI (at least how we use it); and as far as CI goes, headless Chrome works just fine, without special configuration, on Travis. The tests do need to be compiled for the browser i.e. bundle any dependencies (including Node modules) into a single IIFE or load them as globals. We see that there is a Karma plugin for Ava here but it says "alpha level" currently, not sure if that's blocked on anything in this project. (Want to try out Karma? See installation and configuration instructions here, though we can't vouch for those, we use/maintain https://github.com/mixmaxhq/erik i.e. currently use Jasmine for running unit tests in the browser, Ava only for server tests—though it would be nice to use Ava everywhere!) |
Hey all, it's hopefully become apparent since this issue was first opened that browser support is not a priority for AVA. I am therefore closing this issue. We are interested in letting you use AVA to drive browser tests, through Karma or other solutions. If you've got experience with this we'd love to see updates to the browser testing recipe, or indeed new recipes. If you want to help out integrating browser tests by building on top of AVA then please get in touch. We don't have the resources to spearhead these efforts ourselves, but we'd love to include mature solutions in our GitHub and npm organizations, or promote them in recipes. Forking Thank you all for your interest in AVA and participation in this issue ❤️ |
sorry to bump an old issue, but I just tried using ava for the first time to test some client side js that uses Blob and SubtleCrypto apis, but they are not defined i node (I guess? I've never used node...). Is the only way to use these APIs to run in browser? |
@bj0 you'll have to stub those APIs in Node.js. Have a look at our browser testing recipe — the libraries mentioned there may already implement these APIs. (Or not, I haven't actually checked for you, sorry.) |
[See here][ava]. Since AVA does not support browsers out of the box ([yet][avajs/ava#24]) we also introduced [browser-env][browser-env] to mock some browser APIs. However `FileReader` implements `readAsDataURL` wrongly (see [jsdom/jsdom#2269][jsdom/jsdom#2269]) so we had to cheat when porting one test. [ava]: https://github.com/avajs/ava [avajs/ava#24]: avajs/ava#24 [browser-env]: https://github.com/lukechilds/browser-env [jsdom/jsdom#2269]: jsdom/jsdom#2269
[See here][ava]. Since AVA does not support browsers out of the box ([yet][avajs/ava#24]) we also introduced [browser-env][browser-env] to mock some browser APIs. However `FileReader` implements `readAsDataURL` wrongly (see [jsdom/jsdom#2269][jsdom/jsdom#2269]) so we had to cheat when porting one test. [ava]: https://github.com/avajs/ava [avajs/ava#24]: avajs/ava#24 [browser-env]: https://github.com/lukechilds/browser-env [jsdom/jsdom#2269]: jsdom/jsdom#2269
[See here][ava]. Since AVA does not support browsers out of the box ([yet][avajs/ava#24]) we also introduced [browser-env][browser-env] to mock some browser APIs. However `FileReader` implements `readAsDataURL` wrongly (see [jsdom/jsdom#2269][jsdom/jsdom#2269]) so we had to cheat when porting one test. [ava]: https://github.com/avajs/ava [avajs/ava#24]: avajs/ava#24 [browser-env]: https://github.com/lukechilds/browser-env [jsdom/jsdom#2269]: jsdom/jsdom#2269
Hello there, for anybody interested in this I'm kind of rewriting ava for browser support: https://github.com/fabiospampinato/fava, the thing currently has many drawbacks compared to ava, but it's designed to work in the browser, so if you need that maybe give it a try, if you find issues with it I'll be happy to address them. It's not quite the same as just running ava itself in the browser, but the APIs are largely the same so you can switch back to ava once that's implemented here if you like. |
Hello There, For anyone interested in running ava tests in a browser, I've got a way to do that documented in this PR: #3086 . Basically, you run ava in a node process like usual, and a macro delegates execution of the test code to a headless Puppeteer browser. |
Trying to get this working in the browser, and then later hihat for debugging/breakpoints/etc.
After browserifying the demo in the readme, I get the following:
Uncaught ReferenceError: setImmediate is not defined
relevant line
(weird cause I thought browserify would have shimmed this)
The text was updated successfully, but these errors were encountered: