mirror of
https://github.com/apache/cordova-android.git
synced 2026-04-04 00:02:03 +08:00
refactor(check_reqs): cleanup default Java location detection on Windows (#1102)
* test(check_reqs): test default Java location detection on Windows * refactor(check_reqs): use glob for default Java location detection on Windows This changes the implementation to be closer to what it was before #842 with everything being in one place. * fix: remove always-taken if statement * feat: take both Program Files variants from env * refactor(check_reqs): cosmetic changes
This commit is contained in:
committed by
GitHub
parent
d5b9029a23
commit
0e8234abfd
@@ -19,6 +19,7 @@
|
||||
|
||||
var rewire = require('rewire');
|
||||
var android_sdk = require('../../bin/templates/cordova/lib/android_sdk');
|
||||
var os = require('os');
|
||||
var fs = require('fs-extra');
|
||||
var path = require('path');
|
||||
var events = require('cordova-common').events;
|
||||
@@ -45,6 +46,38 @@ describe('check_reqs', function () {
|
||||
});
|
||||
Object.assign(process.env, original_env);
|
||||
});
|
||||
|
||||
describe('check_java', () => {
|
||||
let tmpDir;
|
||||
beforeEach(() => {
|
||||
const tmpDirTemplate = path.join(os.tmpdir(), 'cordova-android-test-');
|
||||
tmpDir = fs.realpathSync(fs.mkdtempSync(tmpDirTemplate));
|
||||
});
|
||||
afterEach(() => {
|
||||
fs.removeSync(tmpDir);
|
||||
});
|
||||
|
||||
it('detects JDK in default location on windows', async () => {
|
||||
check_reqs.isWindows = () => true;
|
||||
check_reqs.__set__({
|
||||
execa: async () => ({}),
|
||||
forgivingWhichSync: () => ''
|
||||
});
|
||||
|
||||
delete process.env.JAVA_HOME;
|
||||
process.env.ProgramFiles = tmpDir;
|
||||
|
||||
const jdkDir = path.join(tmpDir, 'java/jdk1.6.0_02');
|
||||
fs.ensureDirSync(jdkDir);
|
||||
|
||||
await check_reqs.check_java();
|
||||
|
||||
expect(process.env.JAVA_HOME).toBe(jdkDir);
|
||||
expect(process.env.PATH.split(path.delimiter))
|
||||
.toContain(path.join(jdkDir, 'bin'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('check_android', function () {
|
||||
describe('find and set ANDROID_HOME when ANDROID_HOME and ANDROID_SDK_ROOT is not set', function () {
|
||||
beforeEach(function () {
|
||||
|
||||
Reference in New Issue
Block a user