Showing posts with label learning. Show all posts
Showing posts with label learning. Show all posts

Wednesday, June 17, 2020

The Cost of Hidden Wires

In working on the Calm codebase one of the first things I did was wire in Wallaby.js because, well... it's amazing, and I absolutely love it. Having been in a mix of C# and JavaScript, Wallaby gives me the immediate feedback I find most useful in my TDD cycle. I do have a small love affair with the test runner, but... I will be using it as an example of how I used in a manner that gave me issues once I moved Calm into CI. I don't hold Wallaby responsible for it, I just hit a snag that needed to be addressed.

I've long held the belief that starting a project comes with it a special set of skills that I admittedly continue personal growth within. Wiring a project together to fit the needs of the overall longevity of it caries a set of unknowns sometimes that may or may not be obvious to you in the moment. And often that wiring is hidden away where you're unlikely to bump into it or have a need to go seek it out. Here is my simple example.



There is a small cost in time and a little bit of re-work that I had to pay in detangling some hidden wires in my specs. Wallaby provides a setup function that I had been leaning on until now. It was taking care of wiring some dependancies that each of my spec's needed... like hooking up chai and sinon, and it looked something like this:

'use strict';

module.exports = function () {
return {
name: 'Calm',

...
setup: function() {
chai.should();
var sinonChai = require('sinon-chai');
chai.use(sinonChai);
global.sinon = require('sinon');
global.next = function() {};
},
...
};
};
Having this configuration and wiring in the Wallaby configuration file meant that I did not have to import  those into every test file I created, which was great! That's the point of hidden wires... they are out of your way and do some special sauce to make you more productive. Once I spun up a test file, I could get on with the work that I truly cared about... my tests, without having to pull in that setup every time. I had even setup up my package.json to tell you that you could not run the specs from the command line if you ran "npm run test"... you would get the message:

"scripts": {
"test": "echo \"Error: use Wallaby to run tests from within your favorite Wallaby configured IDE\"",
"start": "node app.js"
}

I naturally hit a wall the second I began wiring up Continuous Integration in Circle Ci. Up to this moment, I hadn't had a need to run the tests from the command line. Remember, I'm still very early in the lifetime of this project, so I don't have a ton of code... it's still just basically a holding page with a few experiments in it that I've done along the way:




This issue could have been addressed in several ways, some involving more complexity than others, and I'm still deciding what I want to do long term. My immediate desire was to get specs running in CI... and CI deploying the application, that was it. And I was looking for the smallest commitment I could make in getting that there from a codebase perspective because I knew I would have my hands full enough understanding the CircleCI ecosphere.

In the short term, I've chosen to write a function containing all of the same configuration, moving it out of the Wallaby configuration to somewhere that can be exercised when specs are run from the command line, like this... testHarness.js is then imported into each spec file:





This may not be where things live long term, or maybe they are... the project still has a long way to go. This was a good first step though towards getting all the specs to run in CircleCi and deployments going out when things merge into the primary branch. As for the npm configuration to to run on the command line... it's now a punt to mocha :).



I haven't lost anything in my usage of Wallaby and CI works... a win win. My point in all of this is that the hidden wiring of pieces of our system often give us some efficiency or clarity in some other part of the system. The system is more scannable when reading the codebase, reducing some level of cognitive load along the way which is for sure valuable. Anytime I can reduce the amount of stuff I have to think about is typically a great thing. It can however come out of hiding as the system evolves though, and we need to be prepared for those types of moments. In my case it was a straightforward enough fix to make progress.


Wednesday, May 20, 2020

Sometimes... you take a detour



To say it's been a while since I've touched my side project (Calm) would be a complete misrepresentation of how long it's actually been. As you can see from my last post back in... um.... 2018... it's been a little bit longer than "a while". But, that's cool, life happens and I'm back at it, and that feels good 😊.

Since I've started picking back up the pieces and hints that I left myself, I've been somewhat confused by the highly technical notes that I left behind. Current me is trying hard to remember the context of some of these notes that past me left!! Nonetheless, I'm making some progress. One string of the yarnball that I started to pull on was beginning to use an environment file for some of the application level configuration (a tenet of The Twelve-Factor App). If you're unaware of the principals behind what is described at The Twelve-Factor App, I encourage you to give their site a read. As for configuration for your app, they require a strict separation of the config from the code. Things like port numbers, database connection strings, and 3rd party api tokens.

That's all well and fine! I did hit a little bit of a snag with my unit tests gaining the appropriate load of my environment variables when running my tests through Wallaby.js though. I took a dependency on the 'dotenv-flow' npm package into my app.js file, and wrote a test that ensured it was being used and that the port I was expecting was also being used where I anticipated it should be.

Perhaps not the most useful of tests I know, but sometimes I push things to the dogmatic edge just to see if I can, and to experience what challenges there are in doing so. Lo and behold, an unexpected challenge presented itself. My port was continually getting reported as undefined, regardless of what I tried. When I ran the app on it's own via 'npm run start', the port was console.log'ed as expected. I was not as lucky from within my test suite though. I was having a hard time finding an answer, and my google foo... for whatever reason... was failing me.

That was until I stumbled on this issue in the Wallaby.js repo. The Wallaby configuration file needed to load the .env file in order to make it's contents available to my testing context apparently... like this:

'use strict';
require('dotenv-flow').config();

module.exports = function () {
    return {
        name: 'Calm',

        files: [
            {pattern: 'src/**/*.js'},
            {pattern: 'app.js'},
            //list helpers for tests last, per wallaby's suggestion
            {pattern: 'testHelpers/*.js', instrument: false}
        ],

        tests: [
            {pattern: 'test/**/*-spec.js'}
        ],

        env: {
            type: 'node',
            runner: 'node'
        },

        testFramework: 'mocha',

        setup: function() {
            chai.should();
            var sinonChai = require('sinon-chai');
            chai.use(sinonChai);
            global.sinon = require('sinon');
            global.next = function() {};
        },

        lowCoverageThreshold: 99
    };
};

Now, does my use of a .env file completely satisfy the advice given the the author(s) of The Twelve-Factor App philosophy? No, I don't believe it does. However, it is a good first step that is better than having these types of things hard coded into the application itself. I suppose the next extension of their advice would be to have CI set the environment variables on the server itself that the code is deployed to. I'll tackle that one on some other dogmatic day, lol. Did my dogmatic requirement for this project having at least 99% code coverage force me to learn something new today? It did, and that's worth the effort to me.


Monday, February 29, 2016

Lunchtime at The Movies

Well, not exactly at the movies (although that would be nice). I've started doing something at work to try and socialize and spark discussion on either technical things or the process of building software types of things. It's a divergence from the occasional post stand-up video showing off some insane accomplishment someone does in a car, or on a motorcycle, or skateboard, or bicycle. It's a bit more serious than that, and for good reason.




One of the great things about working with a team of good people (and by good I mean you care about producing useful stuff and helping out your fellow humanzies) is that everyone has been exposed to different things, have differing bases [bey-seez] of knowledge, and hold their own ideas about technology and the world. You may find out about them either through pairing with folks, coming together as a larger team to solve a problem, over coffee, or on a team outing.

Another avenue is over lunch while watching a video. We live in a time where content is being put out at an unheard of pace. Conferences will often put out either some or all of their material after the conference for absolutely free (truly a service to fellow humanzies at large, looking at you StrangeLoop... thank you). This gives us commoners a chance to gain access to well thought out technical discussions about all kinds of things that we normally would never have access to unless we work for employers that find value in sending us to some conferences (and most employers unfortunately do not do so), or we take the initiative and foot the load ourselves.

Having an area to watch things like this is extremely helpful, and I don't mean everyone crowding into one of your fellow colleagues cubicles and squinting to watch it on their tiny laptop monitor. I mean a proper spot with a nice large screen and comfortable seating to relax, eat lunch, enjoy one another's company, and learn.

Lunchtime at the movies, for me, aids in spreading some of the thoughts and things that I may be interested in out to my larger team. I've pulled together some of the places that I look to for snagging a video from below. If you tend to watch vids of stuff from the chatterboxes in our industry, where do you cull them from? I'm not looking for Pluralsight or Udemy types of courses, but more conference or meetup/usergroup types of things.

Sunday, February 21, 2016

What are your favorite podcasts?

Being a husband to my wonderful wife, father of 2 amazing kids, employee of an awesome company, creator of things (like ShopToTrot), someone who is trying to blog more, create more, do more, yada... yada... yada, time can be scarce. One of the tools that I use to keep in touch with what's what in technology land is podcasts.


I usually sneak in a listen on my way into work after I've dropped off my little munchkins at school, which typically amounts to 15 to 20 minutes of geekery. While I typically don't make it through an entire podcast in one sitting, as most run about an hour, I get enough of a fix on my morning drive to keep tuning in the next day. It's just enough to give me something to think about either actively or on one of my many background threads that like to solve things subconsciously for me.

Is there always a direct benefit to my daily grind... no. But it does keep me abreast of techno land in a way that nothing else can. I don't always have time to sit down and read deeply about a subject, and this helps to gain a deeper than surface level understanding on some topics.

Here's what I've been listening to lately:

SE-Radio - This is one that I hit for what I call bigger fish I guess. It's where I'm more likely to run across someone like Linda Rising, someone chatting about CAP theorem, or a good hearted discussion about the GOF 20 years after the initial publication of their book.

The Changelog - This is where I go to get my open source fix and things that might be more on "the edge".

Simple Programmer - This is where I hit for good advice on moving my career forward and personal development (and in all honesty I relate to the guy).

I did a search for "github podcast" and this awesome list turned up from Guilherme Dutra (thanks dude, it's a part of the awesome list of lists). It contains quite a bit and perhaps you can discover something new there.

I've recently started using Overcast to manage and listen to my podcasts, I recommend it. One of the reasons I made the hop was I wanted something that helped in controlling what podcasts actually got pulled down to my phone vs. allow me to stream. Overcast will let you set how long to hold onto a podcast before deleting it... you can always go back and grab it again if you need it. If you decide to use it, be kind and drop the folks that make it a few bucks... nothing in life is free.

This isn't necessarily my complete list or my historical list, but it is the list that's comprised my last 6 months or so. I'm interested to know, if you listen to podcasts, regardless of if they are technology related or not, what are they? Everything I listen to isn't necessarily technology related (although lately they have been), and I would love to know what your tuning in to and why you are tuning in.