Skip to content

Commit

Permalink
Check Flow and run basic packager tests using open source RN config
Browse files Browse the repository at this point in the history
Summary:
Most of the changes associated with this commit will not be visible on GitHub, as they concern files in the internal Facebook monorepo. The bulk of this change is the addition of a new test that runs on the internal test infrastructure. The actual script used by the test has various references to the internal test infra, but a copy is produced below with some changes that should allow it to run on open source should anyone be interested in testing this outside of Facebook.

The test has the main goal of catching common sources of FB-to-GitHub breakages, such as the OSS Flow config falling out of date (we use a different flow config than what is synced out in .flowconfig, and hence internally we rename this file to .github.flowconfig). It also checks that the packager can run on a brand new project, among other things.

```

set -e

THIS_DIR=$(pwd)

REACT_NATIVE_TEMP_DIR=$(mktemp -d /tmp/react-native-XXXXXXXX)
REACT_NATIVE_APP_TEMP_DIR=$(mktemp -d /tmp/react-native-XXXXXXXX)

OFFLINE_MIRROR=$(yarn config get yarn-offline-mirror)

function describe {
  printf "\\n\\n>>>>> %s\\n\\n\\n" "$1"
}

function cleanup {
  set +e
  rm -rf "$REACT_NATIVE_TEMP_DIR"
  rm -rf "$REACT_NATIVE_APP_TEMP_DIR"
  rm "$OFFLINE_MIRROR/react-native-v1000.0.0.tgz"
  set -e
}

trap cleanup EXIT

describe "Creating temporary react-native-github clone"
cp -R "react-native" "$REACT_NATIVE_TEMP_DIR"
pushd "$REACT_NATIVE_TEMP_DIR/react-native" >/dev/null

echo yarn-offline-mirror="$OFFLINE_MIRROR" > .npmrc

describe "Installing react-native node_modules from offline cache"
yarn install --mutex network --offline --frozen-lockfile --ignore-engines --ignore-scripts 2>&1

describe "Running a Flow check"
mv .github.flowconfig .flowconfig
./node_modules/.bin/flow check

describe "Running a basic packager test"
touch .watchmanconfig
node local-cli/cli.js bundle --platform android --dev true --entry-file ReactAndroid/src/androidTest/js/TestBundle.js --bundle-output ReactAndroid/src/androidTest/assets/AndroidTestBundle.js

describe "Creating package for e2e test"
yarn pack
REACT_NATIVE_PACKAGE="$(pwd)/react-native-v1000.0.0.tgz"
REACT_VERSION=$(node -p -e "require('./package.json').peerDependencies['react']")
REACT_NATIVE_HASH=$(shasum "$REACT_NATIVE_PACKAGE" | awk '{print $1;}')
REACT_NATIVE_DEPS=$(node -p -e "const deps=require('./package.json').dependencies; '    ' + Object.keys(deps).map(dep => dep + ' \"' + deps[dep] +'\"').join('\n    ')")

popd >/dev/null

describe "Installing temporary RN app"

mkdir "$REACT_NATIVE_APP_TEMP_DIR/PackagerTest"
pushd "$REACT_NATIVE_APP_TEMP_DIR/PackagerTest" >/dev/null

cp "$REACT_NATIVE_PACKAGE" ./
cp "$REACT_NATIVE_PACKAGE" "$OFFLINE_MIRROR"
cp "$REACT_NATIVE_TEMP_DIR/react-native/.npmrc" ./
cp "$REACT_NATIVE_TEMP_DIR/react-native/yarn.lock" ./

cat <<LOCKFILE >> yarn.lock
react-native@1000.0.0:
  version "1000.0.0"
  resolved react-native-v1000.0.0.tgz#$REACT_NATIVE_HASH
  dependencies:
$REACT_NATIVE_DEPS
LOCKFILE

cat > package.json <<- EndOfFile
{
  "name": "packager-test",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start"
  },
  "dependencies": {
    "react": "$REACT_VERSION",
    "react-native": "1000.0.0"
  }
}
EndOfFile

yarn install --mutex network --offline --frozen-lockfile --ignore-engines --ignore-scripts 2>&1
sed -e s/"HelloWorld"/PackagerTest/g "react-native/local-cli/templates/HelloWorld/app.json" > app.json
cp "react-native/local-cli/templates/HelloWorld/_buckconfig" .buckconfig
cp "react-native/local-cli/templates/HelloWorld/_flowconfig" .flowconfig
cp "react-native/local-cli/templates/HelloWorld/_watchmanconfig" .watchmanconfig
cp "react-native/local-cli/templates/HelloWorld/App.js" App.js
cp "react-native/local-cli/templates/HelloWorld/index.js" index.js

describe "Running a Flow check on a new RN app"
flow check

describe "Verifying packager can produce JS bundle for a new RN app on both platforms"
node ./node_modules/react-native/local-cli/cli.js bundle --platform ios --dev true --entry-file index.js --bundle-output ios-bundle.js
test -e ios-bundle.js
rm ios-bundle.js
node ./node_modules/react-native/local-cli/cli.js bundle --platform android --dev true --entry-file index.js --bundle-output android-bundle.js
test -e android-bundle.js
rm android-bundle.js

popd >/dev/null
```

Reviewed By: arcanis

Differential Revision: D9129463

fbshipit-source-id: a91eeaa150ae6623ee67bd758bc8a98bb31e57b8
  • Loading branch information
hramos authored and facebook-github-bot committed Aug 9, 2018
1 parent eb1ce28 commit b21575f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ module.system.haste.name_reducers='^\(.*\)\.android$' -> '\1'
module.system.haste.name_reducers='^\(.*\)\.native$' -> '\1'
module.system.haste.paths.blacklist=.*/__tests__/.*
module.system.haste.paths.blacklist=.*/__mocks__/.*
module.system.haste.paths.blacklist=<PROJECT_ROOT>/Libraries/Animated/src/polyfills/.*
module.system.haste.paths.whitelist=<PROJECT_ROOT>/Libraries/.*
module.system.haste.paths.whitelist=<PROJECT_ROOT>/RNTester/.*
module.system.haste.paths.whitelist=<PROJECT_ROOT>/IntegrationTests/.*
Expand All @@ -78,6 +77,7 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

[lints]
all=warn
unnecessary-optional-chain=off

# There is an ESLint rule for this
unclear-type=off
Expand Down
4 changes: 2 additions & 2 deletions .github.flowconfig.android
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ module.system.haste.name_reducers='^\(.*\)\.android$' -> '\1'
module.system.haste.name_reducers='^\(.*\)\.native$' -> '\1'
module.system.haste.paths.blacklist=.*/__tests__/.*
module.system.haste.paths.blacklist=.*/__mocks__/.*
module.system.haste.paths.blacklist=<PROJECT_ROOT>/Libraries/Animated/src/polyfills/.*
module.system.haste.paths.whitelist=<PROJECT_ROOT>/Libraries/.*
module.system.haste.paths.whitelist=<PROJECT_ROOT>/RNTester/.*
module.system.haste.paths.whitelist=<PROJECT_ROOT>/IntegrationTests/.*
Expand All @@ -78,6 +77,7 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

[lints]
all=warn
unnecessary-optional-chain=off

# There is an ESLint rule for this
unclear-type=off
Expand All @@ -100,4 +100,4 @@ untyped-import
untyped-type-import

[version]
^0.77.0
^0.78.0
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ node_modules
*.log
.nvm
/bots/node_modules/

# TODO: Check in yarn.lock in open source. Right now we need to keep it out
# from the GitHub repo as importing it might conflict with internal workspaces
yarn.lock
package-lock.json

# OS X
Expand Down

0 comments on commit b21575f

Please sign in to comment.