Skip to content

Commit f0c58f5

Browse files
committed
chore(ci): Add unit tests for run and Catalyst stuff
1 parent ca5bd0c commit f0c58f5

File tree

5 files changed

+232
-137
lines changed

5 files changed

+232
-137
lines changed

lib/run.js

+20-8
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports.run = function (runOptions) {
4848
return Promise.resolve()
4949
.then(() => {
5050
if (!runOptions.emulator && !useCatalyst) {
51-
return require('./listDevices').run().then(devices => {
51+
return module.exports.execListDevices().then(devices => {
5252
if (devices.length > 0) {
5353
useDevice = true;
5454

@@ -84,13 +84,12 @@ module.exports.run = function (runOptions) {
8484
.then(() => {
8585
// Uncompress IPA (zip file)
8686
const appFileInflated = path.join(buildOutputDir, 'Payload', `${projectName}.app`);
87-
const appFile = path.join(buildOutputDir, `${projectName}.app`);
8887
const payloadFolder = path.join(buildOutputDir, 'Payload');
8988

9089
// delete the existing platform/ios/build/device/appname.app
91-
fs.rmSync(appFile, { recursive: true, force: true });
90+
fs.rmSync(appPath, { recursive: true, force: true });
9291
// move the platform/ios/build/device/Payload/appname.app to parent
93-
fs.renameSync(appFileInflated, appFile);
92+
fs.renameSync(appFileInflated, appPath);
9493
// delete the platform/ios/build/device/Payload folder
9594
fs.rmSync(payloadFolder, { recursive: true, force: true });
9695

@@ -106,6 +105,7 @@ module.exports.run = function (runOptions) {
106105
return module.exports.deployToDevice(appPath, runOptions.target, extraArgs);
107106
},
108107
// if device connection check failed use emulator then
108+
// This might fail due to being the wrong type of app bundle
109109
() => module.exports.deployToSim(appPath, runOptions.target)
110110
);
111111
} else if (useCatalyst) {
@@ -127,6 +127,8 @@ module.exports.deployToSim = deployToSim;
127127
module.exports.startSim = startSim;
128128
module.exports.listDevices = listDevices;
129129
module.exports.listEmulators = listEmulators;
130+
module.exports.execListDevices = execListDevices;
131+
module.exports.execListEmulatorTargets = execListEmulatorTargets;
130132

131133
/**
132134
* Filters the args array and removes supported args for the 'run' command.
@@ -195,13 +197,13 @@ async function deployToSim (appPath, target) {
195197

196198
if (!target) {
197199
// Select target device for emulator (preferring iPhone Emulators)
198-
const emulators = await require('./listEmulatorImages').run();
200+
const emulators = await module.exports.execListEmulatorTargets();
199201
const iPhoneEmus = emulators.filter(emulator => emulator.startsWith('iPhone'));
200202
target = iPhoneEmus.concat(emulators)[0];
201203
events.emit('log', `No target specified for emulator. Deploying to "${target}" simulator.`);
202204
}
203205

204-
return startSim(appPath, target);
206+
return module.exports.startSim(appPath, target);
205207
}
206208

207209
function startSim (appPath, target) {
@@ -230,8 +232,18 @@ function startSim (appPath, target) {
230232
return subprocess;
231233
}
232234

235+
/* istanbul ignore next */
236+
function execListDevices () {
237+
return require('./listDevices').run();
238+
}
239+
240+
/* istanbul ignore next */
241+
function execListEmulatorTargets () {
242+
return require('./listEmulatorTargets').run();
243+
}
244+
233245
function listDevices () {
234-
return require('./listDevices').run()
246+
return module.exports.execListDevices()
235247
.then(devices => {
236248
events.emit('log', 'Available iOS Devices:');
237249
devices.forEach(device => {
@@ -241,7 +253,7 @@ function listDevices () {
241253
}
242254

243255
function listEmulators () {
244-
return require('./listEmulatorImages').run()
256+
return module.exports.execListEmulatorTargets()
245257
.then(emulators => {
246258
events.emit('log', 'Available iOS Simulators:');
247259
emulators.forEach(emulator => {

tests/spec/unit/build.spec.js

+27-19
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,27 @@ describe('build', () => {
225225
]);
226226
expect(args.length).toEqual(18);
227227
});
228+
229+
it('should generate appropriate args for Catalyst macOS builds', () => {
230+
const buildOpts = {
231+
catalyst: true
232+
};
233+
234+
const args = getXcodeBuildArgs('TestProjectName', testProjectPath, 'TestConfiguration', '', buildOpts);
235+
expect(args).toEqual([
236+
'-workspace',
237+
'TestProjectName.xcworkspace',
238+
'-scheme',
239+
'TestProjectName',
240+
'-configuration',
241+
'TestConfiguration',
242+
'-destination',
243+
'generic/platform=macOS,variant=Mac Catalyst',
244+
'build',
245+
`SYMROOT=${path.join(testProjectPath, 'build')}`
246+
]);
247+
expect(args.length).toEqual(10);
248+
});
228249
});
229250

230251
describe('getXcodeArchiveArgs method', () => {
@@ -353,35 +374,22 @@ describe('build', () => {
353374
});
354375

355376
describe('run method', () => {
356-
beforeEach(() => {
357-
spyOn(Promise, 'reject');
358-
});
359-
360377
it('should not accept debug and release options together', () => {
361-
build.run({
362-
debug: true,
363-
release: true
364-
});
365-
366-
expect(Promise.reject).toHaveBeenCalledWith(new CordovaError('Cannot specify "debug" and "release" options together.'));
378+
return expectAsync(build.run({ debug: true, release: true }))
379+
.toBeRejectedWithError(CordovaError, 'Cannot specify "debug" and "release" options together.');
367380
});
368381

369382
it('should not accept device and emulator options together', () => {
370-
build.run({
371-
device: true,
372-
emulator: true
373-
});
374-
375-
expect(Promise.reject).toHaveBeenCalledWith(new CordovaError('Cannot specify "device" and "emulator" options together.'));
383+
return expectAsync(build.run({ device: true, emulator: true }))
384+
.toBeRejectedWithError(CordovaError, 'Cannot specify "device" and "emulator" options together.');
376385
});
377386

378387
it('should reject when build config file missing', () => {
379388
spyOn(fs, 'existsSync').and.returnValue(false);
380-
381389
const buildConfig = './some/config/path';
382-
build.run({ buildConfig: './some/config/path' });
383390

384-
expect(Promise.reject).toHaveBeenCalledWith(new CordovaError(`Build config file does not exist: ${buildConfig}`));
391+
return expectAsync(build.run({ buildConfig: './some/config/path' }))
392+
.toBeRejectedWithError(CordovaError, `Build config file does not exist: ${buildConfig}`);
385393
});
386394
});
387395

tests/spec/unit/lib/run.spec.js

-74
This file was deleted.

tests/spec/unit/prepare.spec.js

+36-36
Original file line numberDiff line numberDiff line change
@@ -710,33 +710,33 @@ describe('prepare', () => {
710710
fs.cpSync(path.join(FIXTURES, 'icon-support', 'res'), path.join(iosProject, 'res'), { recursive: true });
711711

712712
// copy icons and update Contents.json
713-
updateIcons(project, p.locations);
714-
715-
// now, clean the images
716-
const updatePaths = spyOn(FileUpdater, 'updatePaths');
717-
718-
return cleanIcons(iosProject, project.projectConfig, p.locations)
719-
.then(() => {
720-
expect(updatePaths).toHaveBeenCalledWith({
721-
[path.join(iconsDir, 'icon.png')]: null,
722-
[path.join(iconsDir, 'watchos.png')]: null,
723-
[path.join(iconsDir, 'icon-20@2x.png')]: null,
724-
[path.join(iconsDir, 'icon-20@3x.png')]: null,
725-
[path.join(iconsDir, 'icon-29@2x.png')]: null,
726-
[path.join(iconsDir, 'icon-29@3x.png')]: null,
727-
[path.join(iconsDir, 'icon-38@2x.png')]: null,
728-
[path.join(iconsDir, 'icon-38@3x.png')]: null,
729-
[path.join(iconsDir, 'icon-40@2x.png')]: null,
730-
[path.join(iconsDir, 'icon-40@3x.png')]: null,
731-
[path.join(iconsDir, 'icon-60@2x.png')]: null,
732-
[path.join(iconsDir, 'icon-60@3x.png')]: null,
733-
[path.join(iconsDir, 'icon-64@2x.png')]: null,
734-
[path.join(iconsDir, 'icon-64@3x.png')]: null,
735-
[path.join(iconsDir, 'icon-68@2x.png')]: null,
736-
[path.join(iconsDir, 'icon-76@2x.png')]: null,
737-
[path.join(iconsDir, 'icon-83.5@2x.png')]: null
738-
}, { rootDir: iosProject, all: true }, logFileOp);
739-
});
713+
return updateIcons(project, p.locations).then(() => {
714+
// now, clean the images
715+
const updatePaths = spyOn(FileUpdater, 'updatePaths');
716+
717+
return cleanIcons(iosProject, project.projectConfig, p.locations)
718+
.then(() => {
719+
expect(updatePaths).toHaveBeenCalledWith({
720+
[path.join(iconsDir, 'icon.png')]: null,
721+
[path.join(iconsDir, 'watchos.png')]: null,
722+
[path.join(iconsDir, 'icon-20@2x.png')]: null,
723+
[path.join(iconsDir, 'icon-20@3x.png')]: null,
724+
[path.join(iconsDir, 'icon-29@2x.png')]: null,
725+
[path.join(iconsDir, 'icon-29@3x.png')]: null,
726+
[path.join(iconsDir, 'icon-38@2x.png')]: null,
727+
[path.join(iconsDir, 'icon-38@3x.png')]: null,
728+
[path.join(iconsDir, 'icon-40@2x.png')]: null,
729+
[path.join(iconsDir, 'icon-40@3x.png')]: null,
730+
[path.join(iconsDir, 'icon-60@2x.png')]: null,
731+
[path.join(iconsDir, 'icon-60@3x.png')]: null,
732+
[path.join(iconsDir, 'icon-64@2x.png')]: null,
733+
[path.join(iconsDir, 'icon-64@3x.png')]: null,
734+
[path.join(iconsDir, 'icon-68@2x.png')]: null,
735+
[path.join(iconsDir, 'icon-76@2x.png')]: null,
736+
[path.join(iconsDir, 'icon-83.5@2x.png')]: null
737+
}, { rootDir: iosProject, all: true }, logFileOp);
738+
});
739+
});
740740
});
741741

742742
it('should have no effect if no icons are specified', () => {
@@ -751,15 +751,15 @@ describe('prepare', () => {
751751
fs.cpSync(path.join(FIXTURES, 'icon-support', 'res'), path.join(iosProject, 'res'), { recursive: true });
752752

753753
// copy icons and update Contents.json
754-
updateIcons(project, p.locations);
755-
756-
// now, clean the images
757-
const updatePaths = spyOn(FileUpdater, 'updatePaths');
758-
759-
return cleanIcons(iosProject, project.projectConfig, p.locations)
760-
.then(() => {
761-
expect(updatePaths).not.toHaveBeenCalled();
762-
});
754+
return updateIcons(project, p.locations).then(() => {
755+
// now, clean the images
756+
const updatePaths = spyOn(FileUpdater, 'updatePaths');
757+
758+
return cleanIcons(iosProject, project.projectConfig, p.locations)
759+
.then(() => {
760+
expect(updatePaths).not.toHaveBeenCalled();
761+
});
762+
});
763763
});
764764
});
765765
});

0 commit comments

Comments
 (0)