惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Full Disclosure
Stack Overflow Blog
Stack Overflow Blog
H
Help Net Security
Microsoft Azure Blog
Microsoft Azure Blog
The GitHub Blog
The GitHub Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Recorded Future
Recorded Future
Y
Y Combinator Blog
Cloudbric
Cloudbric
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Schneier on Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
Cybersecurity and Infrastructure Security Agency CISA
TaoSecurity Blog
TaoSecurity Blog
Security Latest
Security Latest
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
D
DataBreaches.Net
Security Archives - TechRepublic
Security Archives - TechRepublic
H
Hacker News: Front Page
C
Cisco Blogs
L
LangChain Blog
aimingoo的专栏
aimingoo的专栏
Recent Commits to openclaw:main
Recent Commits to openclaw:main
V
Vulnerabilities – Threatpost
L
LINUX DO - 最新话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
A
About on SuperTechFans
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Jina AI
Jina AI
C
CXSECURITY Database RSS Feed - CXSecurity.com
Schneier on Security
Schneier on Security
T
Tenable Blog
N
News and Events Feed by Topic
W
WeLiveSecurity
有赞技术团队
有赞技术团队
AI
AI
爱范儿
爱范儿
大猫的无限游戏
大猫的无限游戏
Latest news
Latest news
T
The Blog of Author Tim Ferriss
S
Security Affairs
Know Your Adversary
Know Your Adversary
Simon Willison's Weblog
Simon Willison's Weblog
G
GRAHAM CLULEY
Google DeepMind News
Google DeepMind News
The Cloudflare Blog

Maxime Heckel's Blog

On Rendering the Sky, Sunsets, and Planets - The Blog of Maxime Heckel Shades of Halftone - The Blog of Maxime Heckel Field Guide to TSL and WebGPU - The Blog of Maxime Heckel On Shaping Light: Real-Time Volumetric Lighting with Post-Processing and Raymarching for the Web - The Blog of Maxime Heckel Speaking at Figma Config 2025 - The Blog of Maxime Heckel Post-Processing Shaders as a Creative Medium - The Blog of Maxime Heckel On Crafting Painterly Shaders - The Blog of Maxime Heckel The Art of Dithering and Retro Shading for the Web - The Blog of Maxime Heckel Moebius-style post-processing and other stylized shaders - The Blog of Maxime Heckel Shining a light on Caustics with Shaders and React Three Fiber - The Blog of Maxime Heckel Real-time dreamy Cloudscapes with Volumetric Raymarching - The Blog of Maxime Heckel Painting with Math: A Gentle Study of Raymarching - The Blog of Maxime Heckel Building a magical AI-powered semantic search from scratch - The Blog of Maxime Heckel Beautiful and mind-bending effects with WebGL Render Targets - The Blog of Maxime Heckel Refraction, dispersion, and other shader light effects - The Blog of Maxime Heckel The magical world of Particles with React Three Fiber and Shaders - The Blog of Maxime Heckel The Study of Shaders with React Three Fiber - The Blog of Maxime Heckel Building a Design System from scratch - The Blog of Maxime Heckel Everything about Framer Motion layout animations - The Blog of Maxime Heckel Building a Vaporwave scene with Three.js - The Blog of Maxime Heckel Cubic Bézier: from math to motion - The Blog of Maxime Heckel First steps with GPT-3 for frontend developers - The Blog of Maxime Heckel Building the perfect GitHub CI workflow for your frontend team - The Blog of Maxime Heckel Migrating to Next.js - The Blog of Maxime Heckel Static Tweets with MDX and Next.js - The Blog of Maxime Heckel Advanced animation patterns with Framer Motion - The Blog of Maxime Heckel Scrollspy demystified - The Blog of Maxime Heckel The Power of Composition with CSS Variables - The Blog of Maxime Heckel My first failed SwiftUI project - The Blog of Maxime Heckel Guide to creating animations that spark joy with Framer Motion - The Blog of Maxime Heckel Using Shortcuts and serverless to build a personal Apple Health API - The Blog of Maxime Heckel SEO mistakes I've made and how I fixed them - The Blog of Maxime Heckel Going native: SwiftUI from the perspective of a React developer - The Blog of Maxime Heckel Build your own preview deployment service - The Blog of Maxime Heckel The little guide to CI/CD for frontend developers - The Blog of Maxime Heckel Immigrating to the US - The Blog of Maxime Heckel The physics behind spring animations - The Blog of Maxime Heckel Generate screenshots of your code with a serverless function - The Blog of Maxime Heckel How to use Framer Motion with Emotion styled-components - The Blog of Maxime Heckel Data Fetching with NextJS: What I learned - The Blog of Maxime Heckel Learning in public - The Blog of Maxime Heckel Fixing the dark mode flash issue on server rendered websites - The Blog of Maxime Heckel How to fix NPM link duplicate dependencies issues - The Blog of Maxime Heckel Running scheduled cross-browser end-to-end tests on Github CI - The Blog of Maxime Heckel How I built my first custom ESLint rule - The Blog of Maxime Heckel React Lazy: a take on preloading views - The Blog of Maxime Heckel Automated UI accessibility testing with Cypress - The Blog of Maxime Heckel Building a GraphQL wrapper for the Docker API - The Blog of Maxime Heckel Switching off the lights - Adding dark mode to your React app - The Blog of Maxime Heckel Getting started with Typescript on Gatsby - The Blog of Maxime Heckel Rebuilding Redux with Hooks and Context - The Blog of Maxime Heckel Asynchronous rendering with React - The Blog of Maxime Heckel Using Flow generics to type generic React components - The Blog of Maxime Heckel How to efficiently type your styled-components with Flow - The Blog of Maxime Heckel How I got started with Kubernetes on GKE - The Blog of Maxime Heckel React sub-components Part 3: Whitelisting sub-components with flow - The Blog of Maxime Heckel React sub-components Part 2: Using the new Context API - The Blog of Maxime Heckel React sub-components - The Blog of Maxime Heckel No title No title
Running Golang tests with Jest - The Blog of Maxime Heckel
Maxime Heckel · 2018-01-11 · via Maxime Heckel's Blog

For the last few months, I focused a lot on testing several projects in React, which led to me hearing a lot about Jest: a zero configuration and instant feedback testing platform for JavaScript code. It’s the tool I was waiting for to help me appreciate the true value of testing my code, without it being a pain thanks to its great UX, watch mode feature, filename pattern filtering or the ability to only test modified files. However, since I’m usually working on a Golang + React stack, whenever I had to focus on Go code, it was always hard to get back to using go test after enjoying Jest and its features so much. Additionally this required context switching between the testing platforms of Javascript and Go.

A few weeks ago, I got the privilege to hear about “Jest as a test platform” from one of the top contributor of the Jest project Rogelio Guzman , and especially about jest runners and what they can achieve. For those who want a great introduction to what Jest is and what kind of problem it solves, I highly recommend you to check out his talk from React Conf 2017.

The story behind jest runners inspired me and several days later, I wrote jest-runner-go, a jest runner that enables anyone to execute Golang tests using the Jest platform and its features.

First, what are Jest runners?

In a nutshell, Jest is composed of multiple packages that are each one responsible for a specific step in your test run lifecycle. Runners are the packages that focus on “running” tests. Jest provides an interface to plug your own runner on both the interface package, which is in charge of finding files, providing the UX and filtering, and the result reporting package, which basically manages the output of your tests.

Diagram representing the lifecycle of a test run with Jest including multiple Jest runners.

Diagram representing the lifecycle of a test run with Jest including multiple Jest runners.

The ability to add custom runners is interesting in case you want to run other types of tests than the default ones supported by Jest. In the case of jest-runner-go, the runner will simply run go test against all Go tests files found by the Jest interface and parse the output in a way the Jest result reporting package can understand it and present the results in a more human readable way.

Using jest-runner-go with Jest

Using Jest to test both the Golang backend and the React frontend of an app has brought me a certain peace of mind, especially when running the tests during CI: the output is consistent and clear across my stack when running my tests. Additionally I get features that are not available with go tests like a native watch mode or running tests with a specific pattern which makes the experience of running tests in Go better.

To integrate jest-runner-go in your project, first run yarn add jest jest-runner-go then simply add the following to whichever Jest config you’re using, either jest.config.js or a specific config that will be passed with the --config flag when running Jest, or even the package.json of the project:

1

"moduleFileExtensions": \[

4

"runner": "jest-runner-go",

Then running jest or jest --config my-go-test-config will find all the files matching _test.go, execute go test against each of these files and finally parse the output produced by go test so Jest will get the required data to output.

As mentioned before, most of my use cases for jest-runner-go along with the classic jest-runner include whenever one of my projects uses both Go and React. It’s possible to run the tests of both sides of the project in a single test run by using the --projects flag and pass multiple Jest configs. In the example below, I added the previous config to a config file called gojest.config.js and then used the following command in a small project generated with create-react-app that also includes some Go code with unit tests:

Running Jest with multiple Jest configs

1

jest --projects jest.config.js gojest.config.js

which gives us the following output:

Jest-runner-go Recorded by maxime_asciinema.org

Other runners

Other Jest runners have been written these last few months, the most notable ones that I’ve found or been introduced to so far are:

What’s coming next?

This article focused a lot on using jest-runner-go to run Go tests along with Javascript tests, but what if we want to use it to only test Go code?

This case is a tricky one as many Go projects owners don’t want to have a dependency on Node to run their tests, as well as everything that comes with it: a node_modules folder, a package.json and a Jest config.

That’s why I started working on Gojest: a standalone binary to run Go tests using the Jest platform and jest-runner-go. The project is compiled for Linux, macOS and Windows using pkg and is available here. This is purely experimental and is obviously not intended to be used in production given how new and not widely used the project and jest-runner-go currently are.

If you want to get the latest version of Gojest you can either download the binaries from the release page of the project or install them using Docker by running the following:

For macOS

Install command for gojest on macOS

1

docker pull maximeheckel/gojest:latest &&

2

id=$(docker create maximeheckel/gojest:latest) &&

3

docker cp $id:/gojest-macos /usr/local/bin/gojest && (docker rm \$id >/dev/null)

For Linux

Install command for gojest on Linux

1

docker pull maximeheckel/gojest:latest &&

2

id=$(docker create maximeheckel/gojest:latest) &&

3

docker cp $id:/gojest-linux /usr/local/bin/gojest && (docker rm \$id >/dev/null)

For Windows

Install command for gojest on Windows

1

docker pull maximeheckel/gojest:latest &&

2

id=$(docker create maximeheckel/gojest:latest) &&

3

docker cp $id:/gojest-win.exe gojest.exe && (docker rm \$id >/dev/null)

Here’s an example of using Gojest to run unit tests in a Go project:

Gojest running Docker tests Recorded by MaximeHeckel_asciinema.org

I really hope to make jest-runner-go and Gojest stable enough to be used by the Go community in a decent timeframe. If you want to contribute or give feedback, both projects are available on Github at

Pull requests are more than welcome.