From 392ee16aaa383c402d2091c05f2b9cc2f175ea0e Mon Sep 17 00:00:00 2001 From: Ryan Ashcraft Date: Mon, 10 Jun 2019 08:52:52 -0700 Subject: [PATCH] Only set babel node target for test env --- babel.config.js | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/babel.config.js b/babel.config.js index 323dd570..876daeea 100644 --- a/babel.config.js +++ b/babel.config.js @@ -2,17 +2,25 @@ 'use strict'; +// NOTE(ryan): Set node target to current for @babel/preset-env to avoid errors when running jest +// `async` test functions ("ReferenceError: regeneratorRuntime is not defined"). +// https://github.com/facebook/jest/issues/3126#issuecomment-483320742 + module.exports = { - presets: [ - '@babel/preset-react', - [ - '@babel/preset-env', - { - targets: { - node: 'current', - }, - }, - ], - ], + presets: ['@babel/preset-react', '@babel/preset-env'], plugins: ['@babel/plugin-proposal-object-rest-spread'], + env: { + test: { + presets: [ + [ + '@babel/preset-env', + { + targets: { + node: 'current', + }, + }, + ], + ], + }, + }, };