From 016e25941b21ba6a82fb59af111fc9c73915f9f3 Mon Sep 17 00:00:00 2001 From: lpalmes Date: Tue, 14 Mar 2017 15:24:58 -0300 Subject: [PATCH 1/4] Added test to check for accidental dependencies --- tasks/e2e-installs.sh | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tasks/e2e-installs.sh b/tasks/e2e-installs.sh index cacf4f96e1..d440d2cd09 100755 --- a/tasks/e2e-installs.sh +++ b/tasks/e2e-installs.sh @@ -84,6 +84,33 @@ cli_path=$PWD/`npm pack` cd "$temp_cli_path" npm install "$cli_path" +# ****************************************************************************** +# Test for accidental dependencies +# ****************************************************************************** + +cd "$temp_app_path" +create_react_app test-app-accidental-dependencies +cd test-app-accidental-dependencies + +# Check if accidental extraneous dependencies are present +# Only react, react-dom, react-scripts should be present +if ! awk '/"dependencies": {/{y=1;next}/},/{y=0; next}y' package.json | \ +grep -v -q -E '^\s*"react(?:-dom|-scripts)?"'; then + echo "Dependencies are correct" +else + echo "There are extraneous dependencies in package.json" + exit 1 +fi + + +if ! awk '/"devDependencies": {/{y=1;next}/},/{y=0; next}y' package.json | \ +grep -v -q -E '^\s*"react(?:-dom|-scripts)?"'; then + echo "Dev Dependencies are correct" +else + echo "There are extraneous devDependencies in package.json" + exit 1 +fi + # ****************************************************************************** # Test --scripts-version with a version number # ****************************************************************************** @@ -169,7 +196,6 @@ mkdir -p test-app-nested-paths-t1/aa/bb/cc/dd create_react_app test-app-nested-paths-t1/aa/bb/cc/dd cd test-app-nested-paths-t1/aa/bb/cc/dd npm start -- --smoke-test - #Testing a path that does not exist cd "$temp_app_path" create_react_app test-app-nested-paths-t2/aa/bb/cc/dd From 15a22b80aef28c156d1f7d1ddc4ec73a445d41e4 Mon Sep 17 00:00:00 2001 From: lpalmes Date: Thu, 16 Mar 2017 15:16:28 -0300 Subject: [PATCH 2/4] Refactored test into a function --- tasks/e2e-installs.sh | 53 +++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/tasks/e2e-installs.sh b/tasks/e2e-installs.sh index d440d2cd09..628a41c2fe 100755 --- a/tasks/e2e-installs.sh +++ b/tasks/e2e-installs.sh @@ -46,6 +46,26 @@ function exists { done } +# Check for accidental dependencies in package.json +function checkDependencies { + if ! awk '/"dependencies": {/{y=1;next}/},/{y=0; next}y' package.json | \ + grep -v -q -E '^\s*"react(?:-dom|-scripts)?"'; then + echo "Dependencies are correct" + else + echo "There are extraneous dependencies in package.json" + exit 1 + fi + + + if ! awk '/"devDependencies": {/{y=1;next}/},/{y=0; next}y' package.json | \ + grep -v -q -E '^\s*"react(?:-dom|-scripts)?"'; then + echo "Dev Dependencies are correct" + else + echo "There are extraneous devDependencies in package.json" + exit 1 + fi +} + function create_react_app { node "$temp_cli_path"/node_modules/create-react-app/index.js $* } @@ -84,33 +104,6 @@ cli_path=$PWD/`npm pack` cd "$temp_cli_path" npm install "$cli_path" -# ****************************************************************************** -# Test for accidental dependencies -# ****************************************************************************** - -cd "$temp_app_path" -create_react_app test-app-accidental-dependencies -cd test-app-accidental-dependencies - -# Check if accidental extraneous dependencies are present -# Only react, react-dom, react-scripts should be present -if ! awk '/"dependencies": {/{y=1;next}/},/{y=0; next}y' package.json | \ -grep -v -q -E '^\s*"react(?:-dom|-scripts)?"'; then - echo "Dependencies are correct" -else - echo "There are extraneous dependencies in package.json" - exit 1 -fi - - -if ! awk '/"devDependencies": {/{y=1;next}/},/{y=0; next}y' package.json | \ -grep -v -q -E '^\s*"react(?:-dom|-scripts)?"'; then - echo "Dev Dependencies are correct" -else - echo "There are extraneous devDependencies in package.json" - exit 1 -fi - # ****************************************************************************** # Test --scripts-version with a version number # ****************************************************************************** @@ -122,6 +115,7 @@ cd test-app-version-number # Check corresponding scripts version is installed. exists node_modules/react-scripts grep '"version": "0.4.0"' node_modules/react-scripts/package.json +checkDependencies # ****************************************************************************** # Test --scripts-version with a tarball url @@ -134,6 +128,7 @@ cd test-app-tarball-url # Check corresponding scripts version is installed. exists node_modules/react-scripts grep '"version": "0.4.0"' node_modules/react-scripts/package.json +checkDependencies # ****************************************************************************** # Test --scripts-version with a custom fork of react-scripts @@ -145,6 +140,7 @@ cd test-app-fork # Check corresponding scripts version is installed. exists node_modules/react-scripts-fork +checkDependencies # ****************************************************************************** # Test project folder is deleted on failing package installation @@ -155,6 +151,7 @@ cd "$temp_app_path" create_react_app --scripts-version=`date +%s` test-app-should-not-exist || true # confirm that the project folder was deleted test ! -d test-app-should-not-exist +checkDependencies # ****************************************************************************** # Test project folder is not deleted when creating app over existing folder @@ -171,6 +168,7 @@ test -e test-app-should-remain/README.md if [ "$(ls -1 ./test-app-should-remain | wc -l | tr -d '[:space:]')" != "1" ]; then false fi +checkDependencies # ****************************************************************************** # Test --scripts-version with a scoped fork tgz of react-scripts @@ -183,6 +181,7 @@ cd test-app-scoped-fork-tgz # Check corresponding scripts version is installed. exists node_modules/@enoah_netzach/react-scripts +checkDependencies # ****************************************************************************** # Test nested folder path as the project name From f3b503b1a7dddd41e330a9f5b03bf8017ac3fdbf Mon Sep 17 00:00:00 2001 From: lpalmes Date: Thu, 16 Mar 2017 15:31:40 -0300 Subject: [PATCH 3/4] Removed non capturing group from grep --- tasks/e2e-installs.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/e2e-installs.sh b/tasks/e2e-installs.sh index 628a41c2fe..431196d0ca 100755 --- a/tasks/e2e-installs.sh +++ b/tasks/e2e-installs.sh @@ -49,7 +49,7 @@ function exists { # Check for accidental dependencies in package.json function checkDependencies { if ! awk '/"dependencies": {/{y=1;next}/},/{y=0; next}y' package.json | \ - grep -v -q -E '^\s*"react(?:-dom|-scripts)?"'; then + grep -v -q -E '^\s*"react(-dom|-scripts)?"'; then echo "Dependencies are correct" else echo "There are extraneous dependencies in package.json" @@ -58,7 +58,7 @@ function checkDependencies { if ! awk '/"devDependencies": {/{y=1;next}/},/{y=0; next}y' package.json | \ - grep -v -q -E '^\s*"react(?:-dom|-scripts)?"'; then + grep -v -q -E '^\s*"react(-dom|-scripts)?"'; then echo "Dev Dependencies are correct" else echo "There are extraneous devDependencies in package.json" From a6185254bbb67f7ab3ba46edf6c4327c4336a642 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Wed, 22 Mar 2017 20:50:37 -0400 Subject: [PATCH 4/4] Update e2e-installs.sh --- tasks/e2e-installs.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tasks/e2e-installs.sh b/tasks/e2e-installs.sh index 431196d0ca..b8f401680a 100755 --- a/tasks/e2e-installs.sh +++ b/tasks/e2e-installs.sh @@ -140,7 +140,6 @@ cd test-app-fork # Check corresponding scripts version is installed. exists node_modules/react-scripts-fork -checkDependencies # ****************************************************************************** # Test project folder is deleted on failing package installation @@ -151,7 +150,6 @@ cd "$temp_app_path" create_react_app --scripts-version=`date +%s` test-app-should-not-exist || true # confirm that the project folder was deleted test ! -d test-app-should-not-exist -checkDependencies # ****************************************************************************** # Test project folder is not deleted when creating app over existing folder @@ -168,7 +166,6 @@ test -e test-app-should-remain/README.md if [ "$(ls -1 ./test-app-should-remain | wc -l | tr -d '[:space:]')" != "1" ]; then false fi -checkDependencies # ****************************************************************************** # Test --scripts-version with a scoped fork tgz of react-scripts @@ -181,13 +178,12 @@ cd test-app-scoped-fork-tgz # Check corresponding scripts version is installed. exists node_modules/@enoah_netzach/react-scripts -checkDependencies # ****************************************************************************** # Test nested folder path as the project name # ****************************************************************************** -#Testing a path that exists +# Testing a path that exists cd "$temp_app_path" mkdir test-app-nested-paths-t1 cd test-app-nested-paths-t1 @@ -195,13 +191,14 @@ mkdir -p test-app-nested-paths-t1/aa/bb/cc/dd create_react_app test-app-nested-paths-t1/aa/bb/cc/dd cd test-app-nested-paths-t1/aa/bb/cc/dd npm start -- --smoke-test -#Testing a path that does not exist + +# Testing a path that does not exist cd "$temp_app_path" create_react_app test-app-nested-paths-t2/aa/bb/cc/dd cd test-app-nested-paths-t2/aa/bb/cc/dd npm start -- --smoke-test -#Testing a path that is half exists +# Testing a path that is half exists cd "$temp_app_path" mkdir -p test-app-nested-paths-t3/aa create_react_app test-app-nested-paths-t3/aa/bb/cc/dd