From c27d7650143312fe6f6e50ad899fc9baaaffd6f9 Mon Sep 17 00:00:00 2001
From: Joe Haddad <timer150@gmail.com>
Date: Wed, 17 May 2017 14:52:55 -0500
Subject: [PATCH] Test module scoping (#2198)

* Correct readme

* Add tests

* Update README.md
---
 packages/react-dev-utils/README.md | 14 +++++++++-----
 tasks/e2e-simple.sh                | 25 +++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/packages/react-dev-utils/README.md b/packages/react-dev-utils/README.md
index 4a7effe21..11f3f8eaa 100644
--- a/packages/react-dev-utils/README.md
+++ b/packages/react-dev-utils/README.md
@@ -34,7 +34,7 @@ var publicUrl = '/my-custom-url';
 module.exports = {
   output: {
     // ...
-    publicPath: publicUrl + '/' 
+    publicPath: publicUrl + '/'
   },
   // ...
   plugins: [
@@ -68,10 +68,14 @@ var ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
 
 module.exports = {
   // ...
-  plugins: [
-    new ModuleScopePlugin(paths.appSrc),
+  resolve: {
     // ...
-  ],
+    plugins: [
+      new ModuleScopePlugin(paths.appSrc),
+      // ...
+    ],
+    // ...
+  },
   // ...
 }
 ```
@@ -132,7 +136,7 @@ console.log('Just cleared the screen!');
 
 #### `eslintFormatter(results: Object): string`
 
-This is our custom ESLint formatter that integrates well with Create React App console output.  
+This is our custom ESLint formatter that integrates well with Create React App console output.<br>
 You can use the default one instead if you prefer so.
 
 ```js
diff --git a/tasks/e2e-simple.sh b/tasks/e2e-simple.sh
index 9d5a4dfba..4795d09a8 100755
--- a/tasks/e2e-simple.sh
+++ b/tasks/e2e-simple.sh
@@ -228,6 +228,25 @@ function verify_env_url {
   mv package.json.orig package.json
 }
 
+function verify_module_scope {
+  # Create stub json file
+  echo "{}" >> sample.json
+
+  # Save App.js, we're going to modify it
+  cp src/App.js src/App.js.bak
+
+  # Add an out of scope import
+  echo "import sampleJson from '../sample'" | cat - src/App.js > src/App.js.temp && mv src/App.js.temp src/App.js
+
+  # Make sure the build fails
+  npm run build; test $? -eq 1 || exit 1
+  # TODO: check for error message
+
+  # Restore App.js
+  rm src/App.js
+  mv src/App.js.bak src/App.js
+}
+
 # Enter the app directory
 cd test-app
 
@@ -251,6 +270,9 @@ npm start -- --smoke-test
 # Test environment handling
 verify_env_url
 
+# Test reliance on webpack internals
+verify_module_scope
+
 # ******************************************************************************
 # Finally, let's check that everything still works after ejecting.
 # ******************************************************************************
@@ -287,5 +309,8 @@ npm start -- --smoke-test
 # Test environment handling
 verify_env_url
 
+# Test reliance on webpack internals
+verify_module_scope
+
 # Cleanup
 cleanup
-- 
GitLab