Mocking Firestore in Flutter

Posted on Leave a comment

I have been writing unit tests like crazy for my muse Flutter app, in my own TDD-like fashion. Writing meaningful tests and watch them go from red to green is a great feeling for real. If you aren’t doing that yet, I highly recommended.

Flutter comes with an excellent testing library called — wait a minute — test. It has one of the most comprehensive set of assertion matchers I have ever seen.

  • Want to test a type? Check.
  • Want to test a future? Check.
  • Want to test an error emitted by a stream? Check.
  • Want to test if your method accidentally rings your neighbor’s door? Umm, well, you gotta do it yourself.

A lot of times you will need to create mocks to avoid side effects in your production database or APIs. Mockito is an awesome package for that. While Mockito works great for general-purpose mocking, I found cloud_firestore_mocks to be closer to the real deal in my testing.

I have used it so extensively in my own tests that I found myself wanting for more. cloud_firestore_mocks, as awesome as it is, does not yet support 100% of Firestore’s APIs. For example, it does not yet support arrayContainsAny where query clause. Same is true for startAt and endAt.

I wanted it so much that I implemented it myself and sent a pull request to Ahn, cloud_firestore_mocks original author. The PR has been merged and the change will land on pub.dev soon. More power to open source!

If you are using Firestore with Flutter, check out cloud_firestore_mocks today and save yourself shit loads of time troubleshooting bugs later. Highly recommended.

Contributing to open source projects

Posted on Leave a comment

It’s high time for me to level up my developer mojo. Clearly, doing side projects isn’t the way to do so. They usually aren’t tough enough. Then what is? Why, of course, large enterprise projects. Based on this logic, I have decided to dedicate a couple of hours everyday to working on complex, large-scale open-source projects.

I recently picked up a new skill, Redux, and renewed my knowledge of React. So much so that I have drifted away from Angular in favor of React. React+Redux is a deadly combination. It sort of brings out the JS nerd out of you, and makes you better at best practices. No wonder why the best websites around are using React. (install the React DevTools browser extension and discover for yourself)

After looking around, I have shortlisted these two projects to focus on:

  • Calypso – a new frontend for WordPress.com
  • Mattermost webapp – frontend for an amazing free & open-source Slack replacement

Both are written in JavaScript (my love) and extensively make use of React and Redux. I have already started making slow but steady progress. My first pull request, although trivial, was recently approved and merged at wp-calypso.

The Exciting New Puppy

Posted on 2 Comments

LXPUP -- Puppy with LXDE
LXPUP — Puppy with LXDE

A couple of days back, I got myself a new puppy. Nope, not the dog sort. It’s a variant of Puppy Linux, and comes with LXDE. The most wonderful aspect of Lxpup is that it is a perfect fusion of an ultra-lightweight feel (of Puppy) and a more usable (and beautiful looking) desktop environment (LXDE). Really, Puppy works so amazingly out-of-the-box and is so incredibly damn fast that it is pretty hard to resist. Add to it its binary compatibility with Ubuntu 12.04 (Precise), and that makes it nothing short of legendary. In short, that gives users the ability to download apps from one of the biggest package repositories on planet.

Puppy’s default window manager, JWM, is kinda annoying to say the least. LXDE is a decent mix of usability and small size, and blends so well with Puppy. In fact, Lxpup’s default customization of LXDE is pretty enough to make you want to keep using it for long.

I’m currently loving my Puppy experience. It runs completely off my USB pendrive. And needless to say, I’m making this post from within Puppy. 🙂

The mighty impressive Slax 7

Posted on Leave a comment

Slax 7 Desktop
Slax 7 Desktop

I was so impressed with the latest iteration of my oldest favorite mini distro, especially its KDE implementation, that I immediately wanted to make Granular’s next release look like and as fast as Slax. Slax 7 comes loaded with all the bare essentials that actually make sense. Plus its ability to run from a USB drive without much efforts makes it a winner to me.

Everything just works, very straightforwardly. It has a lot of stuff packed in a small size of 220MB, which is a marvelous feat (made possible by use of compressed/packaged modules). But it may or may not detect all of your hardware correctly. For me, it didn’t recognize my WiFi module, which I got working by installing the necessary firmware files (look here for instructions). My laptop’s (Synaptics) touchpad performed fine, but its vertical edge scrolling didn’t. I corrected that using the command synclient VertEdgeScroll=1.