Skip to content

Commit

Permalink
Merge pull request apache#442 from raphinesse/fix-tests
Browse files Browse the repository at this point in the history
Fixes and cleanup for Java tests and CI
  • Loading branch information
raphinesse authored Jun 13, 2018
2 parents bf29fe0 + d3c80ea commit 2106e2e
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 74 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ example
/framework/javadoc-public
/framework/javadoc-private
/test/.externalNativeBuild
/test/build.gradle
/test/gradle
/test/gradlew
/test/gradlew.bat
Expand Down
37 changes: 23 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,36 @@ language: android
sudo: false
jdk:
- oraclejdk8
env:
global:
- ANDROID_TOOLS=${ANDROID_HOME}/tools
before_install:
- nvm install 6
# ensure at least gradle 3.3 is in place.
- wget http://services.gradle.org/distributions/gradle-3.3-bin.zip
- unzip gradle-3.3-bin.zip
- export GRADLE_HOME=$PWD/gradle-3.3
- export PATH=${GRADLE_HOME}/bin:${ANDROID_HOME}:${ANDROID_HOME}/emulator:${ANDROID_TOOLS}:${ANDROID_TOOLS}/bin:${ANDROID_HOME}/platform-tools:$PATH
- node --version
- gradle --version
- echo y | android --silent update sdk --no-ui --all --filter platform-tools,tools,build-tools-26.0.2,android-26,android-25,extra-google-m2repository,extra-android-m2repository

android:
components:
- tools
- build-tools-26.0.2
env:
global:
# Keep gradle from crapping all over the log
- TERM=dumb
matrix:
- nodejs_version=6
- nodejs_version=8
- nodejs_version=10

install:
# Install a sdkmanager version that supports the --licenses switch and
# accept any Android SDK licenses. The output redirection prevents us from
# hitting the travis log size limit of 4MB which would fail the build.
- yes | sdkmanager tools > /dev/null
- yes | sdkmanager --licenses > /dev/null

- nvm install $nodejs_version
- npm install
- npm install -g codecov

script:
- gradle --version
- node --version
- npm --version
- npm test
- npm run cover

after_script:
- codecov
60 changes: 29 additions & 31 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
image:
- Previous Visual Studio 2015

environment:
ANDROID_HOME: "C:\\android"
matrix:
- nodejs_version: "4"
- nodejs_version: "6"
- nodejs_version: "8"

init:
- mkdir "%ANDROID_HOME%
- cd "%ANDROID_HOME%"
- appveyor DownloadFile "https://dl.google.com/android/repository/tools_r25.2.3-windows.zip"
- 7z x "tools_r25.2.3-windows.zip" > nul
- cd "C:\projects\cordova-android"
ANDROID_HOME: "C:\\android"

# If the gradle daemon is used, the build hangs after generating the wrapper
GRADLE_OPTS: -Dorg.gradle.daemon=false

# URL for SDK Tools, Revision 26.1.1 (September 2017)
SDK_TOOLS_URL: https://dl.google.com/android/repository/sdk-tools-windows-3859397.zip

matrix:
- nodejs_version: 6
- nodejs_version: 8
- nodejs_version: 10

install:
- choco install gradle -version 3.4.1
- gradle -version
- echo y | "%ANDROID_HOME%\tools\android.bat" --silent update sdk --no-ui --all --filter platform-tools,tools,build-tools-26.0.2,android-26,android-25,extra-google-m2repository,extra-android-m2repository
# on windows we need to accept sublicenses for the new tooling, wee. 30 is an arbitrary number,
# but should be the maximum number of licenses we explicitly need to type "Y ENTER" for.
# also, the sdkmanager in all its glory leaks a bit of output to stderr, and powershell
# and appveyor interpret that as errors, and blows up. so, when piping in our "Y ENTER"
# responses, we invoke cmd so we can redirect stderr to stdout, and tell it to --update itself.
- ps: for($i=0;$i -lt 30;$i++) { $response += "y`n"}; $response | cmd /c 'C:\android\tools\bin\sdkmanager.bat 2>&1' --update
- ps: Install-Product node $env:nodejs_version
- npm install
# below is a workaround on using gradle installed via choco on appveyor
- set path=C:\ProgramData\chocolatey\lib\gradle\tools\gradle-3.4.1\bin;%path%
# Install Android SDK Tools
- mkdir "%ANDROID_HOME%"
- appveyor DownloadFile "%SDK_TOOLS_URL%" -FileName "%TMP%/sdk-tools.zip"
- 7z x "%TMP%/sdk-tools.zip" -o"%ANDROID_HOME%" > nul
- set PATH=%PATH%;"%ANDROID_HOME%\tools\bin"

- yes 2> nul | sdkmanager --licenses > nul
- sdkmanager "build-tools;26.0.2"

- choco install gradle --version 3.4.1

- ps: Install-Product node $env:nodejs_version
- npm install

build: off

test_script:
- node --version
- npm --version
- npm test
- gradle --version
- node --version
- npm --version
- npm test
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"unit-tests": "jasmine --config=spec/unit/jasmine.json",
"cover": "istanbul cover --root bin --print detail jasmine -- --config=spec/unit/jasmine.json",
"e2e-tests": "jasmine --config=spec/e2e/jasmine.json",
"java-unit-tests": "cd test && node run_java_unit_tests.js && cd ..",
"java-unit-tests": "node test/run_java_unit_tests.js",
"eslint": "eslint bin spec test"
},
"author": "Apache Software Foundation",
Expand Down Expand Up @@ -60,7 +60,7 @@
"rewire": "^2.1.3"
},
"engines": {
"node": ">=4.0.0"
"node": ">=6.0.0"
},
"engineStrict": true
}
6 changes: 0 additions & 6 deletions test/gradle/wrapper/gradle-wrapper.properties

This file was deleted.

42 changes: 22 additions & 20 deletions test/run_java_unit_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,28 @@
var Q = require('q');
var path = require('path');
var superspawn = require('cordova-common').superspawn;

// First we make sure the gradlew helper file is built and ready.
var GradleBuilder = require('../bin/templates/cordova/lib/builders/GradleBuilder');
var builder = new GradleBuilder(__dirname);
var needs_gradlew_built = builder.runGradleWrapper('gradle', 'build.gradle');

if (!needs_gradlew_built) {
// Due to interface of gradle builder, if the gradlew file already exists, `runGradleWrapper` returns undefined.
// In this case, we will fill the gap and create a resolved promise here now, this way the next bit of code
// will jump straight to running the tests
// TODO: maybe this should be done in GradleBuilder `runGradleWrapper` method instead?
needs_gradlew_built = Q.fcall(function () { return true; });
}

needs_gradlew_built.then(function () {
return superspawn.spawn(path.join(__dirname, 'gradlew'), ['test'], {stdio: 'inherit'});
}, function (err) {
console.error('There was an error building the gradlew file:', err);
}).then(function () {
console.log('Tests completed successfully.');
}).fail(function (err) {
console.error('Tests failed!', err);
Q.resolve()
.then(_ => console.log('Preparing Gradle wrapper for Java unit tests.'))
.then(_ => new GradleBuilder(__dirname).runGradleWrapper('gradle'))
.then(_ => gradlew('--version'))

.then(_ => console.log('Gradle wrapper is ready. Running tests now.'))
.then(_ => gradlew('test'))
.then(_ => console.log('Java unit tests completed successfully.'));

process.on('unhandledRejection', err => {
// If err has a stderr property, we have seen the message already
if (!('stderr' in err)) console.error(err.message);
console.error('JAVA UNIT TESTS FAILED!');
process.exitCode = err.code || 1;
});

function gradlew () {
const wrapperPath = path.join(__dirname, 'gradlew');
return superspawn.spawn(wrapperPath, Array.from(arguments), {
stdio: 'inherit',
cwd: __dirname
});
}
3 changes: 3 additions & 0 deletions test/wrapper.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
wrapper {
gradleVersion = '4.4.1'
}

0 comments on commit 2106e2e

Please sign in to comment.