From 0ace417c459dc5f1355f5f9a820c5b847feb4e35 Mon Sep 17 00:00:00 2001 From: David 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 69f249f22a3..fe4ec959d4d 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 8edc441002e..e07a57ba5e7 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 9e2ea5cdcd0..87d87e621e7 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 142a1f6d705..12cce8ed313 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 e3a0094f982..5c395999d97 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.