cordova-android/test/run_java_unit_tests.js
Norman Breau 89a0a72da5
feat!: API 34 Support (#1678)
* feat!: Upgrade to Gradle and AGP 8

* java 17

* feat!: API 34 Support

API 34: Upgrade AGP from 8.2.0-rc01 to 8.2.0-rc02

API 34: Upgrade AGP from 8.2.0-rc02 to 8.2.0-rc03

API 34: Upgrade AGP from 8.2.0-rc03 to 8.2.0

feat: add AndroidKotlinJVMTarget preference to set the kotlin JVM target
This is in addition to the java source / target compatibility preferences.
AndroidKotlinJVMTarget is only affective if Kotlin is enabled.

chore: Upgrade Gradle from 8.4 to 8.5

AGP 8.2.0 -> 8.2.1

Gradle 8.5 -> 8.7

fix: Add --validate-url to gradle wrapper commands

AGP 8.4.0

* fix(test): ProjectBuilder using Gradle 8.3, no longer supported version

* API 34: Change Kotlin JVM Target default.

The new default value is null. When null, it will by default
to the Java Target compatibility. Updating AndroidJavaTargetCompatibility
will also influence the Kotlin JVM target, unless if AndroidKotlinJVMTarget
is also explicitly defined.

* removed leftover debug prints

* API 34: Gradle Wrapper

* API 34: ratignore generated gradle wrapper files

* fix gradle wrapper jar via git attributes

* fix(test): normalise gradle paths

* fix(windows): Gradle paths

* fix(windows): Keep CRLF endings for bat files

* chore: Updated license for Gradle Wrapper 8.7 pointer

* API 34 Support Gradle Tools project

* API 34: omit --validate-url on installing the wrapper

* revert: LICENSE notice on bundling the gradle wrapper jar

* Revert: AGP 8.4 -> 8.3

* test(ci): Added NodeJS 22 to the test matrix

---------

Co-authored-by: jcesarmobile <jcesarmobile@gmail.com>
2024-05-13 10:28:57 -03:00

94 lines
3.6 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.
*/
const path = require('path');
const execa = require('execa');
const fs = require('fs-extra');
const ProjectBuilder = require('../lib/builders/ProjectBuilder');
class AndroidTestRunner {
constructor (testTitle, projectDir) {
this.testTitle = testTitle;
this.projectDir = projectDir;
this.gradleWrapper = path.join(this.projectDir, 'tools/gradlew');
}
_gradlew (...args) {
return execa(
this.gradleWrapper,
args,
{
stdio: 'inherit',
cwd: this.projectDir
}
);
}
_getGradleVersion () {
const config = JSON.parse(
fs.readFileSync(path.resolve(this.projectDir, '../../framework/cdv-gradle-config-defaults.json'), {
encoding: 'utf-8'
})
);
return config.GRADLE_VERSION;
}
_createProjectBuilder () {
return new ProjectBuilder(this.projectDir).installGradleWrapper(this._getGradleVersion());
}
run () {
return Promise.resolve()
.then(_ => console.log(`[${this.testTitle}] Preparing Gradle wrapper for Java unit tests.`))
.then(_ => {
// TODO we should probably not only copy these files, but instead create a new project from scratch
fs.copyFileSync(path.resolve(this.projectDir, '../../framework/cdv-gradle-config-defaults.json'), path.resolve(this.projectDir, 'cdv-gradle-config.json'));
fs.copySync(path.resolve(this.projectDir, '../../templates/project/tools'), path.resolve(this.projectDir, 'tools'));
fs.copyFileSync(
path.join(__dirname, '../templates/project/assets/www/cordova.js'),
path.join(this.projectDir, 'app/src/main/assets/www/cordova.js')
);
})
.then(_ => this._createProjectBuilder())
.then(_ => this._gradlew(['--version']))
.then(_ => console.log(`[${this.testTitle}] Gradle wrapper is ready. Running tests now.`))
.then(_ => this._gradlew(['test']))
.then(_ => console.log(`[${this.testTitle}] Java unit tests completed successfully`));
}
}
Promise.resolve()
.then(_ => console.log('Starting to run all android platform tests'))
// AndroidX Test
.then(_ => new AndroidTestRunner('AndroidX Project', path.resolve(__dirname, 'androidx')))
.then(test => test.run())
.then(_ => console.log('Finished running all android platform tests'));
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;
});