The more I learn about JavaScript development, the more I’m exposed to JavaScript build and config tools. The tools such as babel and webpack, frustrate me. The config tools, the magic software of joy that sets up all of your build tools for you via magic pixie-dust or something so you can just write code, those fascinate me. I wish we had more for WordPress and ones that did things exactly the way I think they should be done. I really dislike using templating languages for templating code. That’s what’s stopped me from building my own scaffolding tools before. I always […]
Using Express To Build A Node.js Server To Proxy The WordPress REST API
Currently, the WordPress front end is powered by JavaScript. That’s clear. But what about the server-side? We’ve always used PHP, but the more I learn JavaScript development and the more I use it, the more the switching back and forth with PHP hurts. Also, JavaScript is so much easier to deploy than PHP at this point. Serverless JavaScript apps are one click now, and serverless PHP is something I read about in Medium posts too complex for me to ever reproduce. Once you start writing front-end JavaScript with build tools like Babel and webpack, you’re pretty close to server-side JavaScript. […]
Using the WP Queue to Copy REST API Data to Files
Recently Matt Shaw from Delicious Brains published a post about a new library they created to help in one of their products. This library WP_Queue provides a Laravel-like Job management system for WordPress. A job queue is a system that allows you to schedule jobs to run in the future. We tend to use jobs for two reasons. First, we may need to wait awhile, like if we want to schedule a follow-up email in a week. The other reason is performance. Maybe we need to do something computationally expensive and don’t want the user to wait. A job manager […]
Adopting TDD for an Existing Plugin
Test-driven development (TDD) is a philosophy of software development that is based on writing tests before writing a feature or bug fix. This is a big difference in terms of how you think about development. I find it to be very hard to move to TDD, both because it’s a different mental model and because it’s hard to change how you approach a code base. Before TDD, I wrote code that should work, tested it manually in my browser to see why it didn’t work, fixed it and then wrote tests. With TDD, I write functions declarations and tests that […]
Testing jQuery with Jest in WordPress Development
I recently wrote a series of posts on testing React apps and a series on using phpunit for testing WordPress plugins. Those covered testing brand new code and writing it in a way that is testable. One of the tricky things about adopting tests in a legacy code base is that the code is often written in a way that makes testing harder. In this article, I’m going to look at two ways that jQuery is hard to test. First I will show how to use mocks to artificially isolate your code from jQuery itself. Then I will give an […]
Sharing React Components With Gutenberg
The new WordPress block-based editor Gutenberg is coming to the WordPress soon. While no one has yet defined where Gutenberg will next be used, its been well architected for reuse, which is great, because plugin developers can now use these components in other interfaces, in the WordPress admin and beyond. Because the Gutenberg team is currently moving a lot of the code that is most likely to be reused into npm modules, this makes it very simple to reuse the Gutenberg components in a React app, even if it isn’t in WordPress. That’s not the only way to import Gutenberg […]
Testing React Components With Enzyme
So far in my series of posts on React development for WordPress, I’ve covered React basics, create-react-app and testing with Jest. Jest is useful for testing the rendering of React components. There are a few big buckets of functionality we have not looked at testing yet. Specifically how the internal state of stateful component changes, DOM events, and isolated testing of component class methods. Jest alone can’t do that. Using Enzyme For DOM Testing I hope it’s clear now how Jest, with the default test renderer, can do a lot of test coverage quickly. A snapshot covers one component, with […]
Small is the New Big: An Interview with Paul Jarvis
If our server can’t keep up with the number of requests its getting, we have two basic options; scale up, add more servers or server resources, or make the program more efficient. A perfectly-optimized program would never run out of server resources. That’s a great ideal, but its hard and processing power is cheap, so we add a few more cores. Scaling up is our default. Like a lot of developers, I spend a lot of time working on these types of scaling problems. As I’ve grown my business, I’ve learned the hard way that I have to give up […]
Testing Nested Components In A React App
This post is part of a series on React development for WordPress developers. In my last post, I covered unit testing React components using Jest. Jest, when used for basic assertions and snapshot tests can cover a lot of the functionality of a React component. The “React Way” of developing interfaces calls for composing interfaces, which are themselves components, out of smaller components. Jest lets us test each component in isolation, but we’ll also need to make sure that component work as intended when nested inside of each other. This article also covers looping through React components — for example, […]
Getting Started With React Unit Testing For WordPress Development
When I first looked at Vue vs React, I chose VueJS. One of the reasons was that I felt like Vue was a better choice was the complexity of React classes and life-cycle events. I felt like that was a lot of extra complication that would help with developing frameworks, but preferred the simplicity of Vue’s HTML-like templates and Angular-like two-way data-bindings. As working with Gutenberg has caused me to readdress React, I’ve found that React can, in many ways be a lot simpler, because I can stick to small, pure functions for most of my components. One thing I […]
No Comments