Skip to content

Commit 992adbd

Browse files
author
Yosif Yosifov
committed
Add tests for issue #2697
1 parent 7be0a81 commit 992adbd

File tree

1 file changed

+55
-4
lines changed

1 file changed

+55
-4
lines changed

test/platform-service.ts

+55-4
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ describe('Platform Service Tests', () => {
340340
});
341341

342342
function prepareDirStructure() {
343-
let tempFolder = temp.mkdirSync("prepare platform");
343+
let tempFolder = temp.mkdirSync("prepare_platform");
344344

345345
let appFolderPath = path.join(tempFolder, "app");
346346
fs.createDirectory(appFolderPath);
@@ -378,13 +378,13 @@ describe('Platform Service Tests', () => {
378378
interpolateData: (projectRoot: string) => Promise.resolve(),
379379
afterCreateProject: (projectRoot: string): any => null,
380380
getAppResourcesDestinationDirectoryPath: (projectData: IProjectData, frameworkVersion?: string) : string => {
381-
if (platform === "ios") {
381+
if (platform.toLowerCase() === "ios") {
382382
let dirPath = path.join(testDirData.tempFolder, projectData.projectName,
383383
"Resources");
384384
fs.ensureDirectoryExists(dirPath);
385385
return dirPath;
386386
} else {
387-
let dirPath = path.join(testDirData.tempFolder, "src", "main", "res");
387+
let dirPath = path.join(testDirData.tempFolder, projectData.projectName, "src", "main", "res");
388388
fs.ensureDirectoryExists(dirPath);
389389
return dirPath;
390390
}
@@ -471,10 +471,21 @@ describe('Platform Service Tests', () => {
471471

472472
function assertFileContent(createdItems: CreatedItems, expectedFileContent: string, fileName: string) {
473473
let destinationFilePath = path.join(createdItems.testDirData.appDestFolderPath, "app", fileName);
474+
474475
let actual = fs.readFile(destinationFilePath);
475476
assert.equal(actual, expectedFileContent);
476477
}
477478

479+
function assertFilesExistance(createdItems: CreatedItems, present: boolean, fileNames: string[]) {
480+
_.each(fileNames, (fileName) => assertFileExistance(createdItems, present, fileName));
481+
}
482+
483+
function assertFileExistance(createdItems: CreatedItems, present: boolean, fileName: string) {
484+
let destinationFilePath = path.join(createdItems.testDirData.appDestFolderPath, "app", fileName);
485+
let fileExists = fs.exists(destinationFilePath);
486+
assert.equal(fileExists, present);
487+
}
488+
478489
it("should process only files in app folder when preparing for iOS platform", async () => {
479490
await testPreparePlatform("iOS");
480491
});
@@ -499,18 +510,58 @@ describe('Platform Service Tests', () => {
499510

500511
await execPreparePlatform("iOS", createdItems.testDirData);
501512

513+
// assert the updated file have been copied to the destination
502514
assertFileContent(createdItems, expectedFileContent, "test1.js");
515+
516+
// assert the platform specific files for Android are not copied.
517+
assertFilesExistance(createdItems, false, ["test1.ios.js", "test2.android.js", "test2.js"]);
518+
assertFilesExistance(createdItems, true, ["test1.js", "test2-android-js", "test1-ios-js"]);
519+
assertFileContent(createdItems, "test-image", "Resources/icon.png");
503520
});
504521

505-
it("should sync only changed files, without special folders (Android)", async () => {
522+
it("should sync only changed files, without special folders (Android) #2697", async () => {
506523
let createdItems = await testPreparePlatform("Android");
507524

508525
const expectedFileContent = "updated-content-android";
509526
updateFile(createdItems.files, "test2.android.js", expectedFileContent);
510527

511528
await execPreparePlatform("Android", createdItems.testDirData);
512529

530+
// assert the updated file have been copied to the destination
513531
assertFileContent(createdItems, expectedFileContent, "test2.js");
532+
533+
// assert the platform specific files for iOS are not copied.
534+
assertFilesExistance(createdItems, false, ["test1.android.js", "test2.ios.js", "test1.js"]);
535+
assertFilesExistance(createdItems, true, ["test2.js", "test2-android-js", "test1-ios-js"]);
536+
assertFileContent(createdItems, "test-image", "src/main/res/Resources/icon.png");
537+
});
538+
539+
it("Ensure, App_Resources are not copied in the appDest and left there (iOS) #2697", async () => {
540+
let createdItems = await testPreparePlatform("iOS");
541+
542+
const expectedFileContent = "updated-content-ios";
543+
updateFile(createdItems.files, "test1.ios.js", expectedFileContent);
544+
545+
await execPreparePlatform("iOS", createdItems.testDirData);
546+
547+
// assert the App_Resources are not left copied in the destination App Folder
548+
let appResourcesPath = path.join(createdItems.testDirData.appDestFolderPath, "app/App_Resources");
549+
let dirExists = fs.exists(appResourcesPath);
550+
assert.equal(dirExists, false);
551+
});
552+
553+
it("Ensure, App_Resources are not copied in the appDest and left there (Android) #2697", async () => {
554+
let createdItems = await testPreparePlatform("Android");
555+
556+
const expectedFileContent = "updated-content-android";
557+
updateFile(createdItems.files, "test2.android.js", expectedFileContent);
558+
559+
await execPreparePlatform("Android", createdItems.testDirData);
560+
561+
// assert the App_Resources are not left copied in the destination App Folder
562+
let appResourcesPath = path.join(createdItems.testDirData.appDestFolderPath, "app/App_Resources");
563+
let dirExists = fs.exists(appResourcesPath);
564+
assert.equal(dirExists, false);
514565
});
515566

516567
it("invalid xml is caught", async () => {

0 commit comments

Comments
 (0)