Skip to content

Commit 2d62804

Browse files
KristianDDKristian D. Dimitrov
authored and
Kristian D. Dimitrov
committed
Fix ui tests for platform service and safeguard missing id.
1 parent 2162950 commit 2d62804

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

lib/project-data.ts

+27-6
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ export class ProjectData implements IProjectData {
3232
public projectFilePath: string;
3333
public projectIdentifiers: IProjectIdentifier;
3434
get projectId(): string {
35-
this.$logger.warnWithLabel("This propery is depricated. Please use projectData.projectIdentifiers[platform].");
35+
this.warnProjectId();
3636
return this.projectIdentifiers.ios;
3737
}
3838
set projectId(identifier: string) {
39-
this.$logger.warnWithLabel("This propery is depricated. Please use projectData.projectIdentifiers[platform].");
39+
this.warnProjectId();
4040
this.projectIdentifiers.ios = identifier;
4141
this.projectIdentifiers.android = identifier;
4242
}
@@ -56,6 +56,7 @@ export class ProjectData implements IProjectData {
5656

5757
public initializeProjectData(projectDir?: string): void {
5858
projectDir = projectDir || this.$projectHelper.projectDir;
59+
5960
// If no project found, projectDir should be null
6061
if (projectDir) {
6162
const projectFilePath = path.join(projectDir, this.$staticConfig.PROJECT_FILE_NAME);
@@ -79,10 +80,7 @@ export class ProjectData implements IProjectData {
7980
this.projectFilePath = projectFilePath;
8081
this.appDirectoryPath = path.join(projectDir, constants.APP_FOLDER_NAME);
8182
this.appResourcesDirectoryPath = path.join(projectDir, constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME);
82-
this.projectIdentifiers = {
83-
android: data.id.android || data.id,
84-
ios: data.id.ios || data.id
85-
};
83+
this.projectIdentifiers = this.getProjectIdentifiers(data.id);
8684
this.dependencies = fileContent.dependencies;
8785
this.devDependencies = fileContent.devDependencies;
8886
this.projectType = this.getProjectType();
@@ -99,6 +97,25 @@ export class ProjectData implements IProjectData {
9997
this.$errors.fail("No project found at or above '%s' and neither was a --path specified.", projectDir || this.$options.path || currentDir);
10098
}
10199

100+
private getProjectIdentifiers(data :any): IProjectIdentifier {
101+
let identifier: IProjectIdentifier;
102+
data = data || "";
103+
104+
if(typeof data === "string") {
105+
identifier = {
106+
android: data,
107+
ios: data
108+
};
109+
} else {
110+
identifier = {
111+
android: data.android || "",
112+
ios: data.ios || ""
113+
};
114+
}
115+
116+
return identifier;
117+
}
118+
102119
private getProjectType(): string {
103120
let detectedProjectType = _.find(ProjectData.PROJECT_TYPES, (projectType) => projectType.isDefaultProjectType).type;
104121

@@ -113,5 +130,9 @@ export class ProjectData implements IProjectData {
113130

114131
return detectedProjectType;
115132
}
133+
134+
private warnProjectId(): void {
135+
this.$logger.warnWithLabel("IProjectData.projectId is depricated. Please use IProjectData.projectIdentifiers[platform].");
136+
}
116137
}
117138
$injector.register("projectData", ProjectData);

lib/services/project-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class ProjectService implements IProjectService {
8080
public isValidNativeScriptProject(pathToProject?: string): boolean {
8181
try {
8282
this.$projectData.initializeProjectData(pathToProject);
83-
return !!this.$projectData.projectDir && !!this.$projectData.projectIdentifiers;
83+
return !!this.$projectData.projectDir && !!(this.$projectData.projectIdentifiers.ios && this.$projectData.projectIdentifiers.android);
8484
} catch (e) {
8585
return false;
8686
}

test/platform-service.ts

+1
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ describe('Platform Service Tests', () => {
367367
testInjector = createTestInjector();
368368
testInjector.register("fs", fsLib.FileSystem);
369369
fs = testInjector.resolve("fs");
370+
testInjector.resolve("projectData").initializeProjectData();
370371
});
371372

372373
function prepareDirStructure() {

0 commit comments

Comments
 (0)