Skip to content
This repository has been archived by the owner on Feb 18, 2019. It is now read-only.

Commit

Permalink
Improved OSS flow and lint reporting
Browse files Browse the repository at this point in the history
Summary:- lint bot is now managed by Circle CI
- checked that flow and lint errors are caught both by bot and CI
- flow fix for npm 3
- Travis is now using npm 2 and Circle CI npm 3
- Refactored Travis script to be able to be able to fail on multiple lines
Closes facebook#6508

Differential Revision: D3069500

Pulled By: davidaurelio

fb-gh-sync-id: 02772bf1eae5f2c44489c2e3a01899428a9640cb
shipit-source-id: 02772bf1eae5f2c44489c2e3a01899428a9640cb
  • Loading branch information
bestander authored and Facebook Github Bot 8 committed Mar 18, 2016
1 parent 31c9a2f commit 84183ff
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 89 deletions.
2 changes: 2 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
.*/node_modules/binary-extensions/binary-extensions.json
.*/node_modules/url-regex/tlds.json
.*/node_modules/joi/.*\.json
.*/node_modules/isemail/.*\.json
.*/node_modules/tr46/.*\.json
.*/build/.*\.json
.*/\.buckd/.*

Expand Down
41 changes: 8 additions & 33 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,20 @@ install:
- mkdir -p .nvm
- export NVM_DIR="$PWD/.nvm"
- source $(brew --prefix nvm)/nvm.sh
- nvm install 5
# testing with npm@2 for diversity, Circle tests with npm@3
- nvm install 4.4.0
- rm -Rf "${TMPDIR}/jest_preprocess_cache"
- npm config set spin=false
- npm config set progress=false
- npm install

script:
- |
if [ "$TEST_TYPE" = objc ]
then
travis_retry ./scripts/objc-test.sh
elif [ "$TEST_TYPE" = js ]
then
npm install [email protected]
cat <(echo eslint; npm run lint --silent -- --format=json; echo flow; npm run flow --silent -- --json) | GITHUB_TOKEN="af6ef0d15709bc91d""06a6217a5a826a226fb57b7" node bots/code-analysis-bot.js
npm run flow && npm test
# testing js e2e with npm3
npm install -g npm@3
npm --version
./scripts/e2e-test.sh --packager
# testing js e2e with npm2
rm -rf node_modules
npm install -g npm@2
npm install
npm --version
./scripts/e2e-test.sh --packager
elif [ "$TEST_TYPE" = e2e-objc ]
then
travis_retry ./scripts/e2e-test.sh --ios
else
echo "Unknown test type: $TEST_TYPE"
exit 1
fi
- if [[ "$TEST_TYPE" = objc ]]; then travis_retry ./scripts/objc-test.sh; fi
- if [[ "$TEST_TYPE" = e2e-objc ]]; then travis_retry ./scripts/e2e-test.sh --ios; fi
# temporarily disable flow check because it went mad on Travis
# - if [[ "$TEST_TYPE" = js ]]; then npm run flow check; fi
- if [[ "$TEST_TYPE" = js ]]; then npm test -- --maxWorkers=1; fi
- if [[ "$TEST_TYPE" = js ]]; then ./scripts/e2e-test.sh --packager; fi

env:
matrix:
Expand Down
22 changes: 12 additions & 10 deletions bots/code-analysis-bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
*/
'use strict';

if (!process.env.TRAVIS_REPO_SLUG) {
console.error('Missing TRAVIS_REPO_SLUG. Example: facebook/react-native');
if (!process.env.CI_USER) {
console.error('Missing CI_USER. Example: facebook');
process.exit(1);
}
if (!process.env.CI_REPO) {
console.error('Missing CI_REPO. Example: react-native');
process.exit(1);
}
if (!process.env.GITHUB_TOKEN) {
console.error('Missing GITHUB_TOKEN. Example: 5fd88b964fa214c4be2b144dc5af5d486a2f8c1e');
process.exit(1);
}
if (!process.env.TRAVIS_PULL_REQUEST) {
console.error('Missing TRAVIS_PULL_REQUEST. Example: 4687');
if (!process.env.PULL_REQUEST_NUMBER) {
console.error('Missing PULL_REQUEST_NUMBER. Example: 4687');
process.exit(1);
}

Expand Down Expand Up @@ -231,12 +235,10 @@ process.stdin.on('end', function() {
delete messages[absolutePath];
}

// TRAVIS_REPO_SLUG // 'facebook/react-native'
var user_repo = process.env.TRAVIS_REPO_SLUG.split('/');
var user = user_repo[0];
var repo = user_repo[1];
var number = process.env.TRAVIS_PULL_REQUEST;
var user = process.env.CI_USER;
var repo = process.env.CI_REPO;
var number = process.env.PULL_REQUEST_NUMBER;

// intentional lint warning to make sure that the bot is working :)
main(messages, user, repo, number)
main(messages, user, repo, number);
});
51 changes: 30 additions & 21 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,40 @@ machine:
node:
version: 5.6.0
environment:
PATH: "~/$CIRCLE_PROJECT_REPONAME/gradle-2.9/bin:$PATH"
PATH: "~/$CIRCLE_PROJECT_REPONAME/gradle-2.9/bin:/home/ubuntu/buck/bin:$PATH"
TERM: "dumb"
ADB_INSTALL_TIMEOUT: 10
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx512m -XX:+HeapDumpOnOutOfMemoryError"'

dependencies:
pre:
# BUCK
- if [[ ! -e buck ]]; then git clone https://github.com/facebook/buck.git; fi
- cd buck && ant
- buck/bin/buck --version
- buck/bin/buck fetch ReactAndroid/src/test/java/com/facebook/react/modules
- buck/bin/buck fetch ReactAndroid/src/main/java/com/facebook/react
- buck/bin/buck fetch ReactAndroid/src/main/java/com/facebook/react/shell
- buck/bin/buck fetch ReactAndroid/src/test/...
- buck/bin/buck fetch ReactAndroid/src/androidTest/...
override:
# BUCK and android
- if [[ ! -e /home/ubuntu/buck ]]; then git clone https://github.com/facebook/buck.git /home/ubuntu/buck; fi
- cd /home/ubuntu/buck && ant
- buck --version
- buck fetch ReactAndroid/src/test/java/com/facebook/react/modules
- buck fetch ReactAndroid/src/main/java/com/facebook/react
- buck fetch ReactAndroid/src/main/java/com/facebook/react/shell
- buck fetch ReactAndroid/src/test/...
- buck fetch ReactAndroid/src/androidTest/...
- source scripts/circle-ci-android-setup.sh && getAndroidSDK
- ./gradlew :ReactAndroid:downloadBoost :ReactAndroid:downloadDoubleConversion :ReactAndroid:downloadFolly :ReactAndroid:downloadGlog
cache_directories:
- "ReactAndroid/build/downloads"
- "buck"
- "buck-out/bin"
- "website/node_modules"
override:
# CIRCLE_NPM_TOKEN is in React Native project settings in Circle CI.
# It was generated for bestander user, easy to replace with anyone's else
- echo "//registry.npmjs.org/:_authToken=${CIRCLE_NPM_TOKEN}" > ~/.npmrc
- npm config set spin=false
- npm config set progress=false
- npm install
# for eslint bot
- npm install [email protected]
# for deployment scripts
- npm install [email protected]
- cd website && npm install
cache_directories:
- "ReactAndroid/build/downloads"
- "/home/ubuntu/buck"
- "website/node_modules"
- "node_modules"

test:
pre:
Expand All @@ -46,12 +49,18 @@ test:
- source scripts/circle-ci-android-setup.sh && waitForAVD

override:
# eslint bot
- cat <(echo eslint; npm run lint --silent -- --format=json; echo flow; npm run flow --silent -- check --json) | GITHUB_TOKEN="af6ef0d15709bc91d""06a6217a5a826a226fb57b7" CI_USER=$CIRCLE_PROJECT_USERNAME CI_REPO=$CIRCLE_PROJECT_REPONAME PULL_REQUEST_NUMBER=$CIRCLE_PR_NUMBER node bots/code-analysis-bot.js
# JS tests for dependencies installed with npm3
- npm run flow check
- npm test -- --maxWorkers=1

# build app
- buck/bin/buck build ReactAndroid/src/main/java/com/facebook/react
- buck/bin/buck build ReactAndroid/src/main/java/com/facebook/react/shell
- buck build ReactAndroid/src/main/java/com/facebook/react
- buck build ReactAndroid/src/main/java/com/facebook/react/shell

# unit tests
- buck/bin/buck test ReactAndroid/src/test/... --config build.threads=1
- buck test ReactAndroid/src/test/... --config build.threads=1

# instrumentation tests
# compile native libs with Gradle script
Expand All @@ -60,7 +69,7 @@ test:
# build JS bundle for instrumentation tests
- node local-cli/cli.js bundle --platform android --dev true --entry-file ReactAndroid/src/androidTest/assets/TestBundle.js --bundle-output ReactAndroid/src/androidTest/assets/AndroidTestBundle.js
# build test APK
- buck/bin/buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=1
- buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=1
# run installed apk with tests
- source scripts/circle-ci-android-setup.sh && retry3 ./scripts/run-android-instrumentation-tests.sh com.facebook.react.tests

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@
"flow-bin": "0.22.0",
"jest-cli": "0.9.2",
"portfinder": "0.4.0",
"react": "^0.14.5",
"shelljs": "^0.6.0"
"react": "^0.14.5"
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

jest
.dontMock('node-haste/lib/lib/getPlatformExtension')
.dontMock('node-haste/node_modules/throat')
.dontMock('../');
jest.autoMockOff();

jest
.mock('crypto')
Expand Down
21 changes: 15 additions & 6 deletions packager/react-packager/src/Bundler/__tests__/Bundler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@
*/
'use strict';

jest.autoMockOff();

jest
.setMock('worker-farm', () => () => undefined)
.dontMock('node-haste/node_modules/throat')
.dontMock('lodash')
.dontMock('../../lib/ModuleTransport')
.setMock('uglify-js')
.dontMock('../');

jest.mock('fs');
.mock('image-size')
.mock('fs')
.mock('assert')
.mock('progress')
.mock('node-haste')
.mock('../../JSTransformer')
.mock('../../lib/declareOpts')
.mock('../../Resolver')
.mock('../Bundle')
.mock('../PrepackBundle')
.mock('../HMRBundle')
.mock('../../Activity')
.mock('../../lib/declareOpts');

var Bundler = require('../');
var Resolver = require('../../Resolver');
Expand Down
22 changes: 11 additions & 11 deletions packager/react-packager/src/Server/__tests__/Server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
*/
'use strict';

jest.autoMockOff();

jest.setMock('worker-farm', function() { return () => {}; })
.dontMock('node-haste/node_modules/throat')
.dontMock('os')
.dontMock('lodash')
.dontMock('path')
.dontMock('url')
.setMock('timers', { setImmediate: (fn) => setTimeout(fn, 0) })
.setMock('uglify-js')
.dontMock('../')
.setMock('crypto');
.setMock('crypto')
.mock('../../Bundler')
.mock('../../AssetServer')
.mock('../../lib/declareOpts')
.mock('node-haste')
.mock('../../Activity');

const Promise = require('promise');

var Bundler = require('../../Bundler');
var Server = require('../');
var Server = require('../../Server');
var AssetServer = require('../../AssetServer');

var FileWatcher;
Expand Down Expand Up @@ -108,7 +108,7 @@ describe('processRequest', () => {
requestHandler,
'mybundle.bundle?runModule=true'
).then(response => {
expect(response.getHeader('ETag')).toBeDefined()
expect(response.getHeader('ETag')).toBeDefined();
});
});

Expand All @@ -118,7 +118,7 @@ describe('processRequest', () => {
'mybundle.bundle?runModule=true',
{ headers : { 'if-none-match' : 'this is an etag' } }
).then(response => {
expect(response.statusCode).toEqual(304)
expect(response.statusCode).toEqual(304);
});
});

Expand Down Expand Up @@ -262,7 +262,7 @@ describe('processRequest', () => {

Bundler.prototype.bundle = bundleFunc;

const server = new Server(options);
server = new Server(options);
server.setHMRFileChangeListener(() => {});

requestHandler = server.processRequest.bind(server);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
*/
'use strict';

jest.autoMockOff();
jest.setMock('uglify-js')
.mock('net')
.mock('fs')
.dontMock('node-haste/node_modules/throat')
.dontMock('../SocketServer');
.mock('bser')
.mock('../../Server');

var PackagerServer = require('../../Server');
var SocketServer = require('../SocketServer');
Expand Down

0 comments on commit 84183ff

Please sign in to comment.