From 0ace417c459dc5f1355f5f9a820c5b847feb4e35 Mon Sep 17 00:00:00 2001
From: David <david.bismut@gmail.com>
Date: Tue, 14 Mar 2017 20:32:48 +0100
Subject: [PATCH] Make scripts crash on unhandled rejections (#1819)

* Makes end-to-end testing crash on unhandled rejections

* Comment fix
---
 packages/react-scripts/scripts/build.js | 7 +++++++
 packages/react-scripts/scripts/eject.js | 7 +++++++
 packages/react-scripts/scripts/init.js  | 7 +++++++
 packages/react-scripts/scripts/start.js | 7 +++++++
 packages/react-scripts/scripts/test.js  | 7 +++++++
 5 files changed, 35 insertions(+)

diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js
index 69f249f22..fe4ec959d 100644
--- a/packages/react-scripts/scripts/build.js
+++ b/packages/react-scripts/scripts/build.js
@@ -13,6 +13,13 @@
 // Do this as the first thing so that any code reading it knows the right env.
 process.env.NODE_ENV = 'production';
 
+// Makes the script crash on unhandled rejections instead of silently
+// ignoring them. In the future, promise rejections that are not handled will
+// terminate the Node.js process with a non-zero exit code.
+process.on('unhandledRejection', err => {
+  throw err;
+});
+
 // Load environment variables from .env file. Suppress warnings using silent
 // if this file is missing. dotenv will never modify any environment variables
 // that have already been set.
diff --git a/packages/react-scripts/scripts/eject.js b/packages/react-scripts/scripts/eject.js
index 8edc44100..e07a57ba5 100644
--- a/packages/react-scripts/scripts/eject.js
+++ b/packages/react-scripts/scripts/eject.js
@@ -9,6 +9,13 @@
  */
 'use strict';
 
+// Makes the script crash on unhandled rejections instead of silently
+// ignoring them. In the future, promise rejections that are not handled will
+// terminate the Node.js process with a non-zero exit code.
+process.on('unhandledRejection', err => {
+  throw err;
+});
+
 const fs = require('fs-extra');
 const path = require('path');
 const spawnSync = require('cross-spawn').sync;
diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js
index 9e2ea5cdc..87d87e621 100644
--- a/packages/react-scripts/scripts/init.js
+++ b/packages/react-scripts/scripts/init.js
@@ -9,6 +9,13 @@
  */
 'use strict';
 
+// Makes the script crash on unhandled rejections instead of silently
+// ignoring them. In the future, promise rejections that are not handled will
+// terminate the Node.js process with a non-zero exit code.
+process.on('unhandledRejection', err => {
+  throw err;
+});
+
 const fs = require('fs-extra');
 const path = require('path');
 const spawn = require('cross-spawn');
diff --git a/packages/react-scripts/scripts/start.js b/packages/react-scripts/scripts/start.js
index 142a1f6d7..12cce8ed3 100644
--- a/packages/react-scripts/scripts/start.js
+++ b/packages/react-scripts/scripts/start.js
@@ -10,6 +10,13 @@
 // @remove-on-eject-end
 'use strict';
 
+// Makes the script crash on unhandled rejections instead of silently
+// ignoring them. In the future, promise rejections that are not handled will
+// terminate the Node.js process with a non-zero exit code.
+process.on('unhandledRejection', err => {
+  throw err;
+});
+
 process.env.NODE_ENV = 'development';
 
 // Load environment variables from .env file. Suppress warnings using silent
diff --git a/packages/react-scripts/scripts/test.js b/packages/react-scripts/scripts/test.js
index e3a0094f9..5c395999d 100644
--- a/packages/react-scripts/scripts/test.js
+++ b/packages/react-scripts/scripts/test.js
@@ -13,6 +13,13 @@
 process.env.NODE_ENV = 'test';
 process.env.PUBLIC_URL = '';
 
+// Makes the script crash on unhandled rejections instead of silently
+// ignoring them. In the future, promise rejections that are not handled will
+// terminate the Node.js process with a non-zero exit code.
+process.on('unhandledRejection', err => {
+  throw err;
+});
+
 // Load environment variables from .env file. Suppress warnings using silent
 // if this file is missing. dotenv will never modify any environment variables
 // that have already been set.
-- 
GitLab