Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let Jasmine handle async test results #705

Merged
merged 1 commit into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions tests/spec/component/versions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,35 @@ var versions = rewire('../../../bin/templates/scripts/cordova/lib/versions');
if (process.platform === 'darwin') {
describe('versions', function () {
describe('get_tool_version method', () => {
it('should not have found tool by name.', (done) => {
versions.get_tool_version('unknown')
.then(() => done.fail('expected promise rejection'))
.catch((error) => {
expect(error).toContain('is not valid tool name');
done();
});
it('should not have found tool by name.', () => {
return versions.get_tool_version('unknown').then(
() => fail('expected promise rejection'),
error => expect(error).toContain('is not valid tool name')
);
});

it('should find xcodebuild version.', (done) => {
versions.get_tool_version('xcodebuild').then((version) => {
it('should find xcodebuild version.', () => {
return versions.get_tool_version('xcodebuild').then((version) => {
expect(version).not.toBe(undefined);
done();
}).catch(() => done.fail('expected promise resolution'));
});
});

it('should find ios-sim version.', (done) => {
versions.get_tool_version('ios-sim').then((version) => {
it('should find ios-sim version.', () => {
return versions.get_tool_version('ios-sim').then((version) => {
expect(version).not.toBe(undefined);
done();
}).catch(() => done.fail('expected promise resolution'));
});
});

it('should find ios-deploy version.', (done) => {
versions.get_tool_version('ios-deploy').then((version) => {
it('should find ios-deploy version.', () => {
return versions.get_tool_version('ios-deploy').then((version) => {
expect(version).not.toBe(undefined);
done();
}).catch(() => done.fail('expected promise resolution'));
});
});

it('should find pod version.', (done) => {
versions.get_tool_version('pod').then((version) => {
it('should find pod version.', () => {
return versions.get_tool_version('pod').then((version) => {
expect(version).not.toBe(undefined);
done();
}).catch(() => done.fail('expected promise resolution'));
});
});
});
});
Expand Down
159 changes: 57 additions & 102 deletions tests/spec/unit/Api.spec.js

Large diffs are not rendered by default.

12 changes: 3 additions & 9 deletions tests/spec/unit/Plugman/pluginHandler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,18 +344,14 @@ describe('ios plugin handler', function () {
});
});

it('Test 028 : of two plugins should apply xcode file changes from both', function (done) {
it('Test 028 : of two plugins should apply xcode file changes from both', function () {
var api = new Api('ios', temp, new EventEmitter());
var fail = jasmine.createSpy('fail');

api.addPlugin(dummyPluginInfo)
return api.addPlugin(dummyPluginInfo)
.then(function () {
return api.addPlugin(weblessPluginInfo);
})
.fail(fail)
.done(function () {
expect(fail).not.toHaveBeenCalled();

.then(function () {
var xcode = projectFile.parse({
root: temp,
pbxproj: path.join(temp, 'SampleApp.xcodeproj/project.pbxproj')
Expand All @@ -374,8 +370,6 @@ describe('ios plugin handler', function () {
expect(xcode.hasFile(slashJoin('org.test.plugins.weblessplugin', 'WeblessPluginCommand.h'))).toEqual(jasmine.any(Object));
expect(xcode.hasFile(slashJoin('org.test.plugins.weblessplugin', 'WeblessPluginCommand.m'))).toEqual(jasmine.any(Object));
expect(xcode.hasFile('usr/lib/libsqlite3.dylib')).toEqual(jasmine.any(Object));

done();
});
});
});
Expand Down
65 changes: 22 additions & 43 deletions tests/spec/unit/build.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('build', function () {
var getXcodeBuildArgs = build.__get__('getXcodeBuildArgs');
build.__set__('__dirname', path.join('/test', 'dir'));

it('should generate appropriate args if a single buildFlag is passed in', function (done) {
it('should generate appropriate args if a single buildFlag is passed in', function () {
var isDevice = true;
var buildFlags = '';

Expand All @@ -59,10 +59,9 @@ describe('build', function () {
'SHARED_PRECOMPS_DIR=' + path.join(testProjectPath, 'build', 'sharedpch')
]);
expect(args.length).toEqual(13);
done();
});

it('should generate appropriate args if buildFlags are passed in', function (done) {
it('should generate appropriate args if buildFlags are passed in', function () {
var isDevice = true;
var buildFlags = [
'-workspace TestWorkspaceFlag',
Expand Down Expand Up @@ -91,10 +90,9 @@ describe('build', function () {
'SHARED_PRECOMPS_DIR=TestSharedPrecompsDirFlag'
]);
expect(args.length).toEqual(13);
done();
});

it('should generate appropriate args for device', function (done) {
it('should generate appropriate args for device', function () {
var isDevice = true;
var args = getXcodeBuildArgs('TestProjectName', testProjectPath, 'TestConfiguration', isDevice, null);
expect(args).toEqual([
Expand All @@ -113,10 +111,9 @@ describe('build', function () {
'SHARED_PRECOMPS_DIR=' + path.join(testProjectPath, 'build', 'sharedpch')
]);
expect(args.length).toEqual(13);
done();
});

it('should generate appropriate args for simulator', function (done) {
it('should generate appropriate args for simulator', function () {
var isDevice = false;
var args = getXcodeBuildArgs('TestProjectName', testProjectPath, 'TestConfiguration', isDevice, null, 'iPhone 5s');
expect(args).toEqual([
Expand All @@ -135,10 +132,9 @@ describe('build', function () {
'SHARED_PRECOMPS_DIR=' + path.join(testProjectPath, 'build', 'sharedpch')
]);
expect(args.length).toEqual(13);
done();
});

it('should add matched flags that are not overriding for device', function (done) {
it('should add matched flags that are not overriding for device', function () {
var isDevice = true;
var buildFlags = '-sdk TestSdkFlag';

Expand All @@ -161,10 +157,9 @@ describe('build', function () {
'TestSdkFlag'
]);
expect(args.length).toEqual(15);
done();
});

it('should add matched flags that are not overriding for simulator', function (done) {
it('should add matched flags that are not overriding for simulator', function () {
var isDevice = false;
var buildFlags = '-archivePath TestArchivePathFlag';

Expand All @@ -187,10 +182,9 @@ describe('build', function () {
'TestArchivePathFlag'
]);
expect(args.length).toEqual(15);
done();
});

it('should generate appropriate args for automatic provisioning', function (done) {
it('should generate appropriate args for automatic provisioning', function () {
var isDevice = true;
var args = getXcodeBuildArgs('TestProjectName', testProjectPath, 'TestConfiguration', isDevice, null, null, true);
expect(args).toEqual([
Expand All @@ -210,15 +204,14 @@ describe('build', function () {
'SHARED_PRECOMPS_DIR=' + path.join(testProjectPath, 'build', 'sharedpch')
]);
expect(args.length).toEqual(14);
done();
});
});

describe('getXcodeArchiveArgs method', function () {

var getXcodeArchiveArgs = build.__get__('getXcodeArchiveArgs');

it('should generate the appropriate arguments', function (done) {
it('should generate the appropriate arguments', function () {
var archiveArgs = getXcodeArchiveArgs('TestProjectName', testProjectPath, '/test/output/path', '/test/export/options/path');
expect(archiveArgs[0]).toEqual('-exportArchive');
expect(archiveArgs[1]).toEqual('-archivePath');
Expand All @@ -228,10 +221,9 @@ describe('build', function () {
expect(archiveArgs[5]).toEqual('-exportPath');
expect(archiveArgs[6]).toEqual('/test/output/path');
expect(archiveArgs.length).toEqual(7);
done();
});

it('should generate the appropriate arguments for automatic provisioning', function (done) {
it('should generate the appropriate arguments for automatic provisioning', function () {
var archiveArgs = getXcodeArchiveArgs('TestProjectName', testProjectPath, '/test/output/path', '/test/export/options/path', true);
expect(archiveArgs[0]).toEqual('-exportArchive');
expect(archiveArgs[1]).toEqual('-archivePath');
Expand All @@ -242,102 +234,90 @@ describe('build', function () {
expect(archiveArgs[6]).toEqual('/test/output/path');
expect(archiveArgs[7]).toEqual('-allowProvisioningUpdates');
expect(archiveArgs.length).toEqual(8);
done();
});
});

describe('parseBuildFlag method', function () {

var parseBuildFlag = build.__get__('parseBuildFlag');

it('should detect a workspace change', function (done) {
it('should detect a workspace change', function () {
var buildFlag = '-workspace MyTestWorkspace';
var args = { 'otherFlags': [] };
parseBuildFlag(buildFlag, args);
expect(args.workspace).toEqual('MyTestWorkspace');
expect(args.otherFlags.length).toEqual(0);
done();
});
it('should detect a scheme change', function (done) {
it('should detect a scheme change', function () {
var buildFlag = '-scheme MyTestScheme';
var args = { 'otherFlags': [] };
parseBuildFlag(buildFlag, args);
expect(args.scheme).toEqual('MyTestScheme');
expect(args.otherFlags.length).toEqual(0);
done();
});
it('should detect a configuration change', function (done) {
it('should detect a configuration change', function () {
var buildFlag = '-configuration MyTestConfiguration';
var args = { 'otherFlags': [] };
parseBuildFlag(buildFlag, args);
expect(args.configuration).toEqual('MyTestConfiguration');
expect(args.otherFlags.length).toEqual(0);
done();
});
it('should detect an sdk change', function (done) {
it('should detect an sdk change', function () {
var buildFlag = '-sdk NotARealSDK';
var args = { 'otherFlags': [] };
parseBuildFlag(buildFlag, args);
expect(args.sdk).toEqual('NotARealSDK');
expect(args.otherFlags.length).toEqual(0);
done();
});
it('should detect a destination change', function (done) {
it('should detect a destination change', function () {
var buildFlag = '-destination MyTestDestination';
var args = { 'otherFlags': [] };
parseBuildFlag(buildFlag, args);
expect(args.destination).toEqual('MyTestDestination');
expect(args.otherFlags.length).toEqual(0);
done();
});
it('should detect an archivePath change', function (done) {
it('should detect an archivePath change', function () {
var buildFlag = '-archivePath MyTestArchivePath';
var args = { 'otherFlags': [] };
parseBuildFlag(buildFlag, args);
expect(args.archivePath).toEqual('MyTestArchivePath');
expect(args.otherFlags.length).toEqual(0);
done();
});
it('should detect a configuration_build_dir change', function (done) {
it('should detect a configuration_build_dir change', function () {
var buildFlag = 'CONFIGURATION_BUILD_DIR=/path/to/fake/config/build/dir';
var args = { 'otherFlags': [] };
parseBuildFlag(buildFlag, args);
expect(args.configuration_build_dir).toEqual('CONFIGURATION_BUILD_DIR=/path/to/fake/config/build/dir');
expect(args.otherFlags.length).toEqual(0);
done();
});
it('should detect a shared_precomps_dir change', function (done) {
it('should detect a shared_precomps_dir change', function () {
var buildFlag = 'SHARED_PRECOMPS_DIR=/path/to/fake/shared/precomps/dir';
var args = { 'otherFlags': [] };
parseBuildFlag(buildFlag, args);
expect(args.shared_precomps_dir).toEqual('SHARED_PRECOMPS_DIR=/path/to/fake/shared/precomps/dir');
expect(args.otherFlags.length).toEqual(0);
done();
});
it('should parse arbitrary build settings', function (done) {
it('should parse arbitrary build settings', function () {
var buildFlag = 'MY_ARBITRARY_BUILD_SETTING=ValueOfArbitraryBuildSetting';
var args = { 'otherFlags': [] };
parseBuildFlag(buildFlag, args);
expect(args.otherFlags[0]).toEqual('MY_ARBITRARY_BUILD_SETTING=ValueOfArbitraryBuildSetting');
expect(args.otherFlags.length).toEqual(1);
done();
});
it('should parse userdefaults', function (done) {
it('should parse userdefaults', function () {
var buildFlag = '-myuserdefault=TestUserDefaultValue';
var args = { 'otherFlags': [] };
parseBuildFlag(buildFlag, args);
expect(args.otherFlags[0]).toEqual('-myuserdefault=TestUserDefaultValue');
expect(args.otherFlags.length).toEqual(1);
done();
});
it('should parse settings with a space', function (done) {
it('should parse settings with a space', function () {
var buildFlag = '-anotherxcodebuildsetting withASpace';
var args = { 'otherFlags': [] };
parseBuildFlag(buildFlag, args);
expect(args.otherFlags[0]).toEqual('-anotherxcodebuildsetting');
expect(args.otherFlags[1]).toEqual('withASpace');
expect(args.otherFlags.length).toEqual(2);
done();
});
});

Expand Down Expand Up @@ -395,7 +375,7 @@ describe('build', function () {
});

describe('getDefaultSimulatorTarget method', () => {
it('should find iPhone X as the default simulator target.', (done) => {
it('should find iPhone X as the default simulator target.', () => {
const mockedEmulators = [{
name: 'iPhone 7',
identifier: 'com.apple.CoreSimulator.SimDeviceType.iPhone-7',
Expand All @@ -421,13 +401,12 @@ describe('build', function () {

const getDefaultSimulatorTarget = build.__get__('getDefaultSimulatorTarget');

getDefaultSimulatorTarget().then((actual) => {
return getDefaultSimulatorTarget().then(actual => {
expect(actual).toEqual({
name: 'iPhone X',
identifier: 'com.apple.CoreSimulator.SimDeviceType.iPhone-X',
simIdentifier: 'iPhone-X'
});
done();
});
});
});
Expand Down
14 changes: 5 additions & 9 deletions tests/spec/unit/lib/run.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,11 @@ if (process.platform === 'darwin') {
expect(run.listEmulators).toHaveBeenCalled();
});
});
it('should delegate to to both listEmulators and listDevices methods if neither `options.device` nor `options.emulator` are specified', function (done) {
run.run({ list: true })
.then(function () {
expect(run.listDevices).toHaveBeenCalled();
expect(run.listEmulators).toHaveBeenCalled();
}).fail(function (err) {
fail('run fail handler unexpectedly invoked');
console.error(err);
}).done(done);
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();
});
});
});
});
Expand Down
Loading