mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 07:02:51 +08:00
Cleanup Java tests runner
* Print Gradle version used for Java tests during build * Allow Java tests to be run from any directory * Simplify Promise wrapping in Java tests runner * Minor improvements
This commit is contained in:
parent
83ad646734
commit
032d1fa9cb
@ -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",
|
||||
|
@ -22,26 +22,16 @@
|
||||
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; });
|
||||
}
|
||||
Q.resolve()
|
||||
.then(_ => console.log('Preparing Gradle wrapper for Java unit tests.'))
|
||||
.then(_ => new GradleBuilder(__dirname).runGradleWrapper('gradle'))
|
||||
.then(_ => gradlew('--version'))
|
||||
|
||||
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.');
|
||||
});
|
||||
.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
|
||||
@ -49,3 +39,11 @@ process.on('unhandledRejection', err => {
|
||||
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
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user