Category: Development

Debugging Vue Mocha unit tests in VSCode

View of Vscode debug pane

I have been struggling to be able to debug Vue Mocha unit tests in VSCode, but I think I might have the answer.

Running a Vue application is easy enough and debugging the running application in Chrome or VSCode is relatively straightforward.

Creating and running unit tests for Vue is also relatively straightforward, thanks to the excellent Vue Test Utils.

However, when you want to debug those unit tests, things seem to get a little trickier.

The problem I was having was that either my breakpoints in VSCode would not break or, in the case of the Vue files, they would break in the wrong place (presumably because of confusion caused by the template section).

I’ve create a demo project that can be installed and run. It should run in a browser and you should be able to run the unit tests from the command line or from within VSCode. You can add breakpoints in VSCode to either test files or Vue files and it should break in the correct place.

I’ve used Mochapack, which is an excellent module that makes working with Mocha and Webpack easy. To get the breakpoints working in VSCode, the correct source map config needs to be used.

Mochapack requires source maps be inlined, so the Webpack config needs to be:

  devtool: 'inline-source-map',

VSCode needs source maps to be enabled and the source map path overrides to be set correctly:

  "sourceMaps": true,
  "sourceMapPathOverrides": {
    "webpack:///*": "${workspaceFolder}/*"

Hopefully this helps others trying to combine Vue, unit tests and debugging!

Navigation in iTerm2 on Mac

iTerm2 preferences

Using iTerm2 for development is awesome. You can use CTRL + a to move to the start of the current line and CTRL + e to move to the end.

With long commands, it would be convenient to just jump back a few words, edit the command and then execute it. Whilst this is possible by default in iTerms2, the keys are cumbersome.


CSS Grid and grid areas

CSS Grid example

Having played around with CSS Grid for a while, I had been very impressed with it. But having watched this excellent video on the use of grid areas, I realise that I have been holding the hammer by the head.

Despite reading about grid areas, it hadn’t sunk in just how easily they can be used to solve basic layout requirements – especially when handling responsive layouts.


The Holy Grail:, Browsersync automatically rerun tests

Cypress is an amazing front-end JavaScript test runner and framework. It simultaneously simplifies the set-up and test creation whilst providing a more useful features than most alternatives.


How to lazy load custom field images in wordpress

Lazy load text

WP Rocket is a great, paid-for module for improving the performance of WordPress. Their Lazy Load module improves perfomance further by online preloading images above the page fold.


BDD with Visual Studio – part 2: First scenario and first test

In this second part of this series, we look at creating a first scenario and step definitions.

BDD in Visual Studio – part 1: introduction

As a natural extension of Test Driven Development (TDD), BDD takes things a stage further.

TDD focuses on the use of Unit Tests to drive out a specification for your code and to guide your development. The nature of unit tests means that they are mainly practical for use by developers and, as the name suggests, only for unit testing.


A guide to SRP, Open/Closed, Dependency Injection, Interfaces, Unit Testing and Mocks

This video is a guide for developers to help them understand what changes need to be made to code to make it testable and sustainable. It uses parts of the SOLID principles to refine an example class.

Topics covered:

  • Single Responsibility Principle (SRP)
  • Open/Closed principle
  • Dependency Injection
  • Interfaces
  • Unit Testing
  • Mocks

Geospatial search using MongoDB and PHP

A short tutorial showing how to use MongoDB to create a geospatial index.