2016-02-19 02:27:40 +08:00
|
|
|
/**
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2018-06-18 14:15:24 +08:00
|
|
|
const rewire = require('rewire');
|
2020-07-04 00:54:24 +08:00
|
|
|
const builders = require('../../bin/templates/cordova/lib/builders/builders');
|
2018-06-18 14:15:24 +08:00
|
|
|
|
|
|
|
describe('run', () => {
|
|
|
|
let run;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
run = rewire('../../bin/templates/cordova/lib/run');
|
2021-04-09 14:37:56 +08:00
|
|
|
run.__set__({
|
|
|
|
events: jasmine.createSpyObj('eventsSpy', ['emit'])
|
|
|
|
});
|
2018-06-18 14:15:24 +08:00
|
|
|
});
|
|
|
|
|
2021-04-09 14:37:56 +08:00
|
|
|
describe('buildTargetSpec', () => {
|
2018-06-18 14:15:24 +08:00
|
|
|
it('Test#001 : should select correct target based on the run opts', () => {
|
2021-04-09 14:37:56 +08:00
|
|
|
const buildTargetSpec = run.__get__('buildTargetSpec');
|
|
|
|
|
|
|
|
expect(buildTargetSpec({ target: 'emu' })).toEqual({ id: 'emu' });
|
|
|
|
expect(buildTargetSpec({ device: true })).toEqual({ type: 'device' });
|
|
|
|
expect(buildTargetSpec({ emulator: true })).toEqual({ type: 'emulator' });
|
|
|
|
expect(buildTargetSpec({})).toEqual({});
|
2017-06-14 02:42:20 +08:00
|
|
|
});
|
2016-02-19 02:27:40 +08:00
|
|
|
});
|
2018-06-18 14:15:24 +08:00
|
|
|
|
|
|
|
describe('run method', () => {
|
2021-04-09 14:37:56 +08:00
|
|
|
let targetSpyObj, emulatorSpyObj, resolvedTarget;
|
2018-06-18 14:15:24 +08:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-04-09 14:37:56 +08:00
|
|
|
resolvedTarget = { id: 'dev1', type: 'device', arch: 'atari' };
|
2018-06-18 14:15:24 +08:00
|
|
|
|
2021-04-09 14:37:56 +08:00
|
|
|
targetSpyObj = jasmine.createSpyObj('deviceSpy', ['resolve', 'install']);
|
|
|
|
targetSpyObj.resolve.and.resolveTo(resolvedTarget);
|
2020-11-21 05:12:18 +08:00
|
|
|
targetSpyObj.install.and.resolveTo();
|
|
|
|
|
2021-04-09 14:37:56 +08:00
|
|
|
emulatorSpyObj = jasmine.createSpyObj('emulatorSpy', ['wait_for_boot']);
|
|
|
|
emulatorSpyObj.wait_for_boot.and.resolveTo();
|
|
|
|
|
2018-06-18 14:15:24 +08:00
|
|
|
run.__set__({
|
2020-11-21 05:12:18 +08:00
|
|
|
target: targetSpyObj,
|
2021-04-09 14:37:56 +08:00
|
|
|
emulator: emulatorSpyObj
|
2018-06-18 14:15:24 +08:00
|
|
|
});
|
2020-07-04 00:54:24 +08:00
|
|
|
|
|
|
|
// run needs `this` to behave like an Api instance
|
|
|
|
run.run = run.run.bind({
|
|
|
|
_builder: builders.getBuilder('FakeRootPath')
|
|
|
|
});
|
2018-06-18 14:15:24 +08:00
|
|
|
});
|
|
|
|
|
2021-04-09 14:37:56 +08:00
|
|
|
it('should install on target after build', () => {
|
2018-06-18 14:15:24 +08:00
|
|
|
return run.run().then(() => {
|
2021-04-09 14:37:56 +08:00
|
|
|
expect(targetSpyObj.install).toHaveBeenCalledWith(
|
|
|
|
resolvedTarget,
|
|
|
|
{ apkPaths: [], buildType: 'debug' }
|
|
|
|
);
|
2018-06-18 14:15:24 +08:00
|
|
|
});
|
|
|
|
});
|
2019-08-09 00:53:10 +08:00
|
|
|
|
|
|
|
it('should fail with the error message if --packageType=bundle setting is used', () => {
|
2021-04-09 14:37:56 +08:00
|
|
|
targetSpyObj.resolve.and.resolveTo(resolvedTarget);
|
|
|
|
return expectAsync(run.run({ argv: ['--packageType=bundle'] }))
|
|
|
|
.toBeRejectedWith(jasmine.stringMatching(/Package type "bundle" is not supported/));
|
2019-08-09 00:53:10 +08:00
|
|
|
});
|
2018-06-18 14:15:24 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('help', () => {
|
|
|
|
it('should print out usage and help', () => {
|
2019-07-17 06:18:12 +08:00
|
|
|
spyOn(console, 'log');
|
2019-07-17 09:01:56 +08:00
|
|
|
spyOn(process, 'exit');
|
2018-06-18 14:15:24 +08:00
|
|
|
|
|
|
|
run.help();
|
2019-07-17 06:18:12 +08:00
|
|
|
expect(console.log).toHaveBeenCalledWith(jasmine.stringMatching(/^Usage:/));
|
2018-06-18 14:15:24 +08:00
|
|
|
});
|
|
|
|
});
|
2016-02-19 02:27:40 +08:00
|
|
|
});
|