-
-
Notifications
You must be signed in to change notification settings - Fork 197
fix(assets-generation): Do not fail in case some App_Resources are missing #3557
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,9 @@ import { Yok } from "../../lib/common/yok"; | |
import { assert } from "chai"; | ||
import { ProjectDataService } from "../../lib/services/project-data-service"; | ||
import { LoggerStub } from "../stubs"; | ||
import { NATIVESCRIPT_PROPS_INTERNAL_DELIMITER } from '../../lib/constants'; | ||
import { NATIVESCRIPT_PROPS_INTERNAL_DELIMITER, PACKAGE_JSON_FILE_NAME, AssetConstants } from '../../lib/constants'; | ||
import { DevicePlatformsConstants } from "../../lib/common/mobile/device-platforms-constants"; | ||
import { basename } from "path"; | ||
|
||
const CLIENT_NAME_KEY_IN_PROJECT_FILE = "nativescript"; | ||
|
||
|
@@ -53,19 +54,38 @@ const createTestInjector = (readTextData?: string): IInjector => { | |
|
||
readText: (filename: string, encoding?: IReadFileOptions | string): string => { | ||
return readTextData; | ||
} | ||
}, | ||
|
||
exists: (filePath: string): boolean => basename(filePath) === PACKAGE_JSON_FILE_NAME, | ||
|
||
readJson: (filePath: string): any => null, | ||
|
||
enumerateFilesInDirectorySync: (directoryPath: string, | ||
filterCallback?: (_file: string, _stat: IFsStats) => boolean, | ||
opts?: { enumerateDirectories?: boolean, includeEmptyDirectories?: boolean }, | ||
foundFiles?: string[]): string[] => [] | ||
}); | ||
|
||
testInjector.register("logger", LoggerStub); | ||
|
||
testInjector.register("projectDataService", ProjectDataService); | ||
|
||
testInjector.register("androidResourcesMigrationService", {}); | ||
testInjector.register("androidResourcesMigrationService", { | ||
hasMigrated: (appResourcesDir: string): boolean => true | ||
}); | ||
|
||
testInjector.register("devicePlatformsConstants", DevicePlatformsConstants); | ||
|
||
testInjector.register("injector", testInjector); | ||
|
||
testInjector.register("errors", {}); | ||
|
||
testInjector.register("projectHelper", { | ||
sanitizeName: (appName: string): string => appName | ||
}); | ||
|
||
testInjector.register("options", {}); | ||
|
||
return testInjector; | ||
}; | ||
|
||
|
@@ -244,4 +264,39 @@ describe("projectDataService", () => { | |
assert.deepEqual(dataPassedToWriteJson, { dependencies: {} }); | ||
}); | ||
}); | ||
|
||
describe("getAssetsStructure", () => { | ||
it("does not fail when App_Resources/Android and App_Resources/iOS do not exist", async () => { | ||
const defaultEmptyData: any = {}; | ||
defaultEmptyData[CLIENT_NAME_KEY_IN_PROJECT_FILE] = {}; | ||
const testInjector = createTestInjector(JSON.stringify(defaultEmptyData)); | ||
const fs = testInjector.resolve<IFileSystem>("fs"); | ||
fs.readJson = (filePath: string): any => { | ||
if (basename(filePath) === AssetConstants.imageDefinitionsFileName) { | ||
return { android: {}, ios: {} }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The file is part of CLI resources, so in case it does not exist, something terrible happened 😸 |
||
} | ||
|
||
throw new Error(`Unable to read file ${filePath}`); | ||
}; | ||
|
||
const projectDataService = testInjector.resolve<IProjectDataService>("projectDataService"); | ||
const assetStructure = await projectDataService.getAssetsStructure({ projectDir: "." }); | ||
const emptyAssetStructure: IAssetGroup = { | ||
icons: { | ||
images: [] | ||
}, | ||
splashBackgrounds: { | ||
images: [] | ||
}, | ||
splashCenterImages: { | ||
images: [] | ||
}, | ||
splashImages: { | ||
images: [] | ||
} | ||
}; | ||
|
||
assert.deepEqual(assetStructure, { ios: emptyAssetStructure, android: _.merge(_.cloneDeep(emptyAssetStructure), { splashImages: null }) }); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will happen in case when
pathToContentJson
exists but the file is not a valid json? I'm expecting to throw an error in this case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I prefer to throw the error in this case as it is not expected to have a non-json file here.