Latest Posts

This is an error that I've seen plague several projects when using the Jest Test runner in WebStorm.  I have found two working resolutions to this.  You can either.

  1. Add this block of code below the imports in the test file that is having the error.
    import jsdom from 'jsdom';
    const doc = jsdom.jsdom('<!doctype html>test');
    global.document = doc;
    global.window = doc.defaultView;
  2. Alternatively put "--env=jsdom" in the "Jest options" field in the specific runners configuration.  Should look something like this.




Either way the error should now be gone when you run your tests.

Like most of the developers I work with my system of choice is at 15" Macbook Pro.  Whether or not you like Apple for the kind of work I do MacOS provides a good balance of Open Source tools and commercial support.  I've certaintly had a better experience overall than on Windows or Linux.

Unfortunately quite recently my Macbook started crashing while in sleep mode while all on battery.  This quite often occured when I had to quickly close the lid and go somewhere.  For some reason when I got to the other end the fans were very loud and the system wouldn't wake up.  

I initially tried to solve this myself by whiping the OS, reinstalling and restoring my account from a timemachine backup.  This unfortunately proved to be unsuccessfull.  Following doing this over a weekend I discovered that the following Monday morning when I started my laptop at the office it informed me that my machine was not compatible with the OS and would only start up in Recovery of Safe mode.  Since I work a block from and Apple store I took it into the genius bar and was able to have it quickly repaired.  They also tested the laptop and discovered that one of the heat sensors war erroring.  This was quickly fixed by cleaning the dust out of the internals.  I discovered this is free of charged at an Apple store.

This unfortunately did not resolved the issue so I had to book and appointment to have it thoroughly tested........ Read More

Part 2

Step 1 - The REST API

The first step is to build the basic App.  Since this will connected to from a Node.js based front-end a REST API is the obvious choice plus the Spring Boot website has an easy tutorial and git repo that will get us started.

To start pull down the spring-boot repo with the following command:

git clone https://github.com/spring-guides/gs-rest-service.git

Note: you will need git installed for this command to work.

First things first.  Create a test.

@Test
public void testVPSAPIRoute() throws Exception {
this.mockMvc.perform(get("/api/1.0/vpsmanager/").param("test", "content"))
.andDo(print()).andExpect(status().isOk());
}

Now that we have a test we need a route in the controller.

@RequestMapping("/api/1.0/vpsmanager")
public Greeting vpsmanager(@RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));Read More

The aim of this project is create Services that runs system level utilities, an API gateway that talks to this with RabbitMQ in the middle.  The main reason behind RabbitMQ is the eventual aim of this is to manage virtual machines.  That is creating and running them is not a instantaneous process to RabbitMQ will allow decoupling of the API from the service back-end.  I currently have a python/flask version of this however it isn't using a messaging bus and has gotten to the point of needing one.  Since my work has more of a call for Java/Spring and JavaScript/React skills I thought I would rewrite the middleware API in Java/Spring and the front-end in JavaScript/React

RabbitMQ via Docker 

First step it to get RabbitMQ running.  Since my laptop already has Docker on it and I want to learn it better I thought I would start with that. This was pretty straight forward, just run the following command.

docker run -d --hostname vpsmanager-rabbitmq --name vpsmanager-rabbitmq -p 15672:15672 -p 5672:5672 rabbitmq:3-management

Note:  The web gui is on 15672 and applications will talk to it on 5672.

Once up and running point your browser at:

localhost:15672

You should now see the RabbitMQ login page.  Using guest/g....... Read More

Testing React using Jest and Enzyme

Dec 01,2017 at 06:34 pm By Ben Hutton

Testing React is an interesting endeavor.  Since it is almost entirely UI (User Interface) specific you shouldn't need to test everything.  At least with regards to Unit Tests.  When it does come down to testing there seems to be quite a bit of confusion as to how to test.  

Recently I have been working with a React codebase and have been attempting to write tests as these were almost completely absent.  This has proven more difficult than most testing I do these days.  I believe this is due to the fast based development of Javascript frameworks.  Generally I am developing in Java, Python or PHP.  These have fairly muture test frameworks. 

Since the codebase I have been working on is using Jest and Enzyme I decided to go with that.  The two primary methods of testing the codebase I have come across is shallow and mount.  Shallow as the name suggests doesn't drill into the dependancies, whereas mount does the opposite.  The preferable option is to use shallow, however a gotcha with this is the props.  Since these don't appear to be in the scope of the class being called you have to mock these, otherwise you will not be able to testing anything that requires the props.  You can mock props as follows:

describe('When MyPage is rendered with data', () => {
const profilePage = shallow(<MyComponent
myprop1={10}
....... Read More

Copyright © 2017 | Ben Hutton