cordova-android/test/run_java_unit_tests.js
Raphael von der Grün a254cfc841 Fix Java tests for older Gradle versions
Before this, Gradle 4.4 was required to build the Gradle wrapper and
thus run the Java tests. This was because of all the stuff that had to
be configured when running the wrapper task using the build.gradle file.

Now we use a config file that only specifies the required Gradle version
and nothing else to run the wrapper task. This allows tests to be run
with Gradle versions beginning with 2.
2018-06-13 16:09:04 +02:00

52 lines
2.2 KiB
JavaScript

#!/usr/bin/env node
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
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');
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 () {
console.log('Gradle wrapper is ready. Running tests now.');
return superspawn.spawn(path.join(__dirname, 'gradlew'), ['test'], {stdio: 'inherit'});
}).then(function () {
console.log('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;
});