-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
- Loading branch information
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
/* | ||
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('node:path'); | ||
const { CordovaError, events } = require('cordova-common'); | ||
const build = require('../../../lib/build'); | ||
const run = require('../../../lib/run'); | ||
|
||
describe('cordova/lib/run', () => { | ||
const testProjectPath = path.join('/test', 'project', 'path'); | ||
|
||
beforeEach(() => { | ||
run.root = testProjectPath; | ||
}); | ||
|
||
describe('runListDevices method', () => { | ||
beforeEach(() => { | ||
spyOn(events, 'emit'); | ||
spyOn(run, 'execListDevices').and.returnValue(Promise.resolve(["iPhone Xs"])); | ||
Check failure on line 35 in tests/spec/unit/run.spec.js GitHub Actions / NodeJS 18.x on macos-14
Check failure on line 35 in tests/spec/unit/run.spec.js GitHub Actions / NodeJS 18.x on ubuntu-latest
Check failure on line 35 in tests/spec/unit/run.spec.js GitHub Actions / NodeJS 20.x on macos-14
Check failure on line 35 in tests/spec/unit/run.spec.js GitHub Actions / NodeJS 22.x on macos-14
Check failure on line 35 in tests/spec/unit/run.spec.js GitHub Actions / NodeJS 20.x on ubuntu-latest
|
||
spyOn(run, 'execListEmulatorTargets').and.returnValue(Promise.resolve(["iPhone 15 Simulator"])); | ||
Check failure on line 36 in tests/spec/unit/run.spec.js GitHub Actions / NodeJS 18.x on macos-14
Check failure on line 36 in tests/spec/unit/run.spec.js GitHub Actions / NodeJS 18.x on ubuntu-latest
Check failure on line 36 in tests/spec/unit/run.spec.js GitHub Actions / NodeJS 20.x on macos-14
Check failure on line 36 in tests/spec/unit/run.spec.js GitHub Actions / NodeJS 22.x on macos-14
Check failure on line 36 in tests/spec/unit/run.spec.js GitHub Actions / NodeJS 20.x on ubuntu-latest
|
||
}); | ||
|
||
it('should delegate to "listDevices" when the "runListDevices" method options param contains "options.device".', () => { | ||
return run.runListDevices({ options: { device: true } }).then(() => { | ||
expect(run.execListDevices).toHaveBeenCalled(); | ||
expect(run.execListEmulatorTargets).not.toHaveBeenCalled(); | ||
|
||
expect(events.emit).toHaveBeenCalledWith('log', '\tiPhone Xs'); | ||
}); | ||
}); | ||
|
||
it('should delegate to "listDevices" when the "runListDevices" method options param contains "options.emulator".', () => { | ||
return run.runListDevices({ options: { emulator: true } }).then(() => { | ||
expect(run.execListDevices).not.toHaveBeenCalled(); | ||
expect(run.execListEmulatorTargets).toHaveBeenCalled(); | ||
|
||
expect(events.emit).toHaveBeenCalledWith('log', '\tiPhone 15 Simulator'); | ||
}); | ||
}); | ||
|
||
it('should delegate to both "listEmulators" and "listDevices" when the "runListDevices" method does not contain "options.device" or "options.emulator".', () => { | ||
return run.runListDevices().then(() => { | ||
expect(run.execListDevices).toHaveBeenCalled(); | ||
expect(run.execListEmulatorTargets).toHaveBeenCalled(); | ||
|
||
expect(events.emit).toHaveBeenCalledWith('log', '\tiPhone Xs'); | ||
expect(events.emit).toHaveBeenCalledWith('log', '\tiPhone 15 Simulator'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('run method', () => { | ||
beforeEach(() => { | ||
spyOn(build, 'run').and.returnValue(Promise.resolve()); | ||
spyOn(build, 'findXCodeProjectIn').and.returnValue('ProjectName'); | ||
spyOn(run, 'execListDevices').and.resolveTo([]); | ||
spyOn(run, 'execListEmulatorTargets').and.resolveTo([]); | ||
spyOn(run, 'listDevices').and.resolveTo(); | ||
spyOn(run, 'deployToMac').and.resolveTo(); | ||
spyOn(run, 'deployToSim').and.resolveTo(); | ||
spyOn(run, 'checkDeviceConnected').and.rejectWith(new Error('No Device Connected')); | ||
}); | ||
|
||
describe('--list option', () => { | ||
beforeEach(() => { | ||
spyOn(run, 'listEmulators').and.returnValue(Promise.resolve()); | ||
}); | ||
|
||
it('should delegate to listDevices method if `options.device` specified', () => { | ||
return run.run({ list: true, device: true }).then(() => { | ||
expect(run.listDevices).toHaveBeenCalled(); | ||
expect(run.listEmulators).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('should delegate to listEmulators method if `options.device` specified', () => { | ||
return run.run({ list: true, emulator: true }).then(() => { | ||
expect(run.listDevices).not.toHaveBeenCalled(); | ||
expect(run.listEmulators).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('should delegate to both listEmulators and listDevices methods if neither `options.device` nor `options.emulator` are specified', () => { | ||
return run.run({ list: true }).then(() => { | ||
expect(run.listDevices).toHaveBeenCalled(); | ||
expect(run.listEmulators).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should not accept device and emulator options together', () => { | ||
spyOn(Promise, 'reject'); | ||
|
||
run.run({ | ||
device: true, | ||
emulator: true | ||
}); | ||
|
||
expect(Promise.reject).toHaveBeenCalledWith(new CordovaError('Only one of "device"/"emulator" options should be specified')); | ||
}); | ||
|
||
it('should run on a simulator if --device is not specified and no device is connected', () => { | ||
return run.run({ }).then(() => { | ||
expect(run.deployToSim).toHaveBeenCalled(); | ||
expect(build.run).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('should try to run on a device if --device is not specified and a device is connected', () => { | ||
run.execListDevices.and.resolveTo(["iPhone 12 Plus"]); | ||
Check failure on line 126 in tests/spec/unit/run.spec.js GitHub Actions / NodeJS 18.x on macos-14
Check failure on line 126 in tests/spec/unit/run.spec.js GitHub Actions / NodeJS 18.x on ubuntu-latest
Check failure on line 126 in tests/spec/unit/run.spec.js GitHub Actions / NodeJS 20.x on macos-14
Check failure on line 126 in tests/spec/unit/run.spec.js GitHub Actions / NodeJS 22.x on macos-14
Check failure on line 126 in tests/spec/unit/run.spec.js GitHub Actions / NodeJS 20.x on ubuntu-latest
|
||
|
||
return run.run({ }).then(() => { | ||
expect(run.checkDeviceConnected).toHaveBeenCalled(); | ||
expect(build.run).toHaveBeenCalledWith(jasmine.objectContaining({ device: true })); | ||
}); | ||
}); | ||
|
||
it('should try to run on a device if --device is specified', () => { | ||
return run.run({ device: true }).then(() => { | ||
expect(run.checkDeviceConnected).toHaveBeenCalled(); | ||
expect(build.run).toHaveBeenCalledWith(jasmine.objectContaining({ device: true })); | ||
}); | ||
}); | ||
|
||
it('should not run a build if --noBuild is passed', () => { | ||
return run.run({ emulator: true, nobuild: true }).then(() => { | ||
expect(build.run).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('should try to launch the macOS Catalyst app bundle', () => { | ||
return run.run({ device: true, target: 'mac', release: true }).then(() => { | ||
expect(run.deployToMac).toHaveBeenCalledWith(path.join(testProjectPath, 'build', 'Release-maccatalyst', 'ProjectName.app')); | ||
}); | ||
}); | ||
}); | ||
}); |