From d06d591012be2b3aa368c7aca7887329dda7bc73 Mon Sep 17 00:00:00 2001 From: Yosif Yosifov Date: Mon, 10 Apr 2017 15:01:26 +0300 Subject: [PATCH 01/16] Setup Project Changes Service test suite --- test/base-service-test.ts | 12 +++++ test/project-changes-service.ts | 83 +++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 test/base-service-test.ts create mode 100644 test/project-changes-service.ts diff --git a/test/base-service-test.ts b/test/base-service-test.ts new file mode 100644 index 0000000000..b59f3882f6 --- /dev/null +++ b/test/base-service-test.ts @@ -0,0 +1,12 @@ +import * as yok from "../lib/common/yok"; + +export abstract class BaseServiceTest { + protected injector: IInjector; + constructor() { + this.injector = new yok.Yok(); + + this.initInjector(); + } + + abstract initInjector(): void; +} \ No newline at end of file diff --git a/test/project-changes-service.ts b/test/project-changes-service.ts new file mode 100644 index 0000000000..5326089609 --- /dev/null +++ b/test/project-changes-service.ts @@ -0,0 +1,83 @@ +import * as path from "path"; +import { BaseServiceTest } from "./base-service-test"; +import temp = require("temp"); +import { assert } from "chai"; +import { PlatformsData } from "../lib/platforms-data"; +import { ProjectChangesService } from "../lib/services/project-changes-service"; +import * as Constants from "../lib/constants"; + +// start tracking temporary folders/files +temp.track(); + +class ProjectChangesServiceTest extends BaseServiceTest { + public projectDir: string; + + constructor() { + super(); + } + + initInjector(): void { + this.projectDir = temp.mkdirSync("projectDir"); + this.injector.register("projectData", { + projectDir: this.projectDir + }); + + this.injector.register("platformsData", PlatformsData); + this.injector.register("androidProjectService", {}); + this.injector.register("iOSProjectService", {}); + + this.injector.register("fs", {}); + this.injector.register("devicePlatformsConstants", {}); + this.injector.register("devicePlatformsConstants", {}); + this.injector.register("projectChangesService", ProjectChangesService); + + } + + get projectChangesService(): IProjectChangesService { + return this.injector.resolve("projectChangesService"); + } + + get projectData(): IProjectData { + return this.injector.resolve("projectData"); + } + + get platformsData(): any { + return this.injector.resolve("platformsData"); + } +} + +describe.only("Project Changes Service Tests", () => { + let serviceTest: ProjectChangesServiceTest; + beforeEach(() => { + serviceTest = new ProjectChangesServiceTest(); + }); + + describe("Get Prepare Info File Path", () => { + beforeEach(() => { + const platformsDir = path.join( + serviceTest.projectDir, + Constants.PLATFORMS_DIR_NAME + ); + + serviceTest.platformsData.getPlatformData = + (platform: string) => { + return { + projectRoot: path.join(platformsDir, platform) + }; + }; + }); + + it("Gets the correct Prepare Info path for ios/android", () => {; + for(let os of ["ios", "android"]) { + let actualPrepareInfoPath = serviceTest.projectChangesService + .getPrepareInfoFilePath(os, this.projectData); + + const expectedPrepareInfoPath = path.join(serviceTest.projectDir, + Constants.PLATFORMS_DIR_NAME, + os, + ".nsprepareinfo"); + assert.equal(actualPrepareInfoPath, expectedPrepareInfoPath); + } + }); + }); +}); \ No newline at end of file From 23b3b7b80f7ec9507ad24ef35be53f995b4440ef Mon Sep 17 00:00:00 2001 From: Yosif Yosifov Date: Mon, 10 Apr 2017 16:37:11 +0300 Subject: [PATCH 02/16] Add tests for GetPrepareInfo from ProjectChangesService --- test/base-service-test.ts | 18 ++-- test/project-changes-service.ts | 169 +++++++++++++++++++------------- 2 files changed, 112 insertions(+), 75 deletions(-) diff --git a/test/base-service-test.ts b/test/base-service-test.ts index b59f3882f6..5cff01b74e 100644 --- a/test/base-service-test.ts +++ b/test/base-service-test.ts @@ -1,12 +1,16 @@ import * as yok from "../lib/common/yok"; export abstract class BaseServiceTest { - protected injector: IInjector; - constructor() { - this.injector = new yok.Yok(); + protected injector: IInjector; + constructor() { + this.injector = new yok.Yok(); - this.initInjector(); - } + this.initInjector(); + } - abstract initInjector(): void; -} \ No newline at end of file + abstract initInjector(): void; + + resolve(name: string, ctorArguments?: IDictionary): any { + return this.injector.resolve(name); + } +} diff --git a/test/project-changes-service.ts b/test/project-changes-service.ts index 5326089609..fd084167ff 100644 --- a/test/project-changes-service.ts +++ b/test/project-changes-service.ts @@ -5,79 +5,112 @@ import { assert } from "chai"; import { PlatformsData } from "../lib/platforms-data"; import { ProjectChangesService } from "../lib/services/project-changes-service"; import * as Constants from "../lib/constants"; +import { FileSystem } from "../lib/common/file-system"; // start tracking temporary folders/files temp.track(); class ProjectChangesServiceTest extends BaseServiceTest { - public projectDir: string; - - constructor() { - super(); - } - - initInjector(): void { - this.projectDir = temp.mkdirSync("projectDir"); - this.injector.register("projectData", { - projectDir: this.projectDir - }); - - this.injector.register("platformsData", PlatformsData); - this.injector.register("androidProjectService", {}); - this.injector.register("iOSProjectService", {}); - - this.injector.register("fs", {}); - this.injector.register("devicePlatformsConstants", {}); - this.injector.register("devicePlatformsConstants", {}); - this.injector.register("projectChangesService", ProjectChangesService); - - } - - get projectChangesService(): IProjectChangesService { - return this.injector.resolve("projectChangesService"); - } - - get projectData(): IProjectData { - return this.injector.resolve("projectData"); - } - - get platformsData(): any { - return this.injector.resolve("platformsData"); - } + public projectDir: string; + + constructor() { + super(); + } + + initInjector(): void { + this.projectDir = temp.mkdirSync("projectDir"); + this.injector.register("projectData", { + projectDir: this.projectDir + }); + + this.injector.register("platformsData", PlatformsData); + this.injector.register("androidProjectService", {}); + this.injector.register("iOSProjectService", {}); + + this.injector.register("fs", FileSystem); + this.injector.register("devicePlatformsConstants", {}); + this.injector.register("devicePlatformsConstants", {}); + this.injector.register("projectChangesService", ProjectChangesService); + + } + + get projectChangesService(): IProjectChangesService { + return this.injector.resolve("projectChangesService"); + } + + get projectData(): IProjectData { + return this.injector.resolve("projectData"); + } + + get platformsData(): any { + return this.injector.resolve("platformsData"); + } } describe.only("Project Changes Service Tests", () => { - let serviceTest: ProjectChangesServiceTest; - beforeEach(() => { - serviceTest = new ProjectChangesServiceTest(); - }); - - describe("Get Prepare Info File Path", () => { - beforeEach(() => { - const platformsDir = path.join( - serviceTest.projectDir, - Constants.PLATFORMS_DIR_NAME - ); - - serviceTest.platformsData.getPlatformData = - (platform: string) => { - return { - projectRoot: path.join(platformsDir, platform) - }; - }; - }); - - it("Gets the correct Prepare Info path for ios/android", () => {; - for(let os of ["ios", "android"]) { - let actualPrepareInfoPath = serviceTest.projectChangesService - .getPrepareInfoFilePath(os, this.projectData); - - const expectedPrepareInfoPath = path.join(serviceTest.projectDir, - Constants.PLATFORMS_DIR_NAME, - os, - ".nsprepareinfo"); - assert.equal(actualPrepareInfoPath, expectedPrepareInfoPath); - } - }); - }); -}); \ No newline at end of file + let serviceTest: ProjectChangesServiceTest; + beforeEach(() => { + serviceTest = new ProjectChangesServiceTest(); + + const platformsDir = path.join( + serviceTest.projectDir, + Constants.PLATFORMS_DIR_NAME + ); + + serviceTest.platformsData.getPlatformData = + (platform: string) => { + return { + projectRoot: path.join(platformsDir, platform) + }; + }; + }); + + describe("Get Prepare Info File Path", () => { + it("Gets the correct Prepare Info path for ios/android", () => { + for (let platform of ["ios", "android"]) { + let actualPrepareInfoPath = serviceTest.projectChangesService + .getPrepareInfoFilePath(platform, this.projectData); + + const expectedPrepareInfoPath = path.join(serviceTest.projectDir, + Constants.PLATFORMS_DIR_NAME, + platform, + ".nsprepareinfo"); + assert.equal(actualPrepareInfoPath, expectedPrepareInfoPath); + } + }); + }); + + describe("Get Prepare Info", () => { + it("Returns empty if file path doesn't exists", () => { + for (let platform of ["ios", "android"]) { + let projectInfo = serviceTest.projectChangesService.getPrepareInfo(platform, this.projectData); + + assert.isNull(projectInfo); + } + }); + + it("Reads the Prepare Info correctly", () => { + const fs: FileSystem = serviceTest.resolve("fs"); + for (let platform of ["ios", "android"]) { + // arrange + const prepareInfoPath = path.join(serviceTest.projectDir, Constants.PLATFORMS_DIR_NAME, + platform, ".nsprepareinfo"); + const expectedPrepareInfo = { + time: new Date().toString(), + bundle: true, + release: false, + changesRequireBuild: true, + changesRequireBuildTime: new Date().toString(), + iOSProvisioningProfileUUID: "provisioning_profile_test" + }; + fs.writeJson(prepareInfoPath, expectedPrepareInfo); + + // act + let actualPrepareInfo = serviceTest.projectChangesService.getPrepareInfo(platform, this.projectData); + + // assert + assert.deepEqual(actualPrepareInfo, expectedPrepareInfo); + } + }); + }); +}); From 6c1317b6c00cea77c5e62509ab6e1cac47ed4380 Mon Sep 17 00:00:00 2001 From: Yosif Yosifov Date: Tue, 11 Apr 2017 14:50:41 +0300 Subject: [PATCH 03/16] Add test to verify changes on a sync file has been applied. --- test/platform-service.ts | 130 +++++++++++++++++++++++++++----- test/project-changes-service.ts | 2 +- 2 files changed, 111 insertions(+), 21 deletions(-) diff --git a/test/platform-service.ts b/test/platform-service.ts index 7d7216d184..5e46b5832e 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -89,6 +89,39 @@ function createTestInjector() { return testInjector; } +class CreatedItems { + files: string[]; + + resources: { + ios: string[], + android: string[] + }; + + testDirData: { + tempFolder: string, + appFolderPath: string, + app1FolderPath: string, + appDestFolderPath: string, + appResourcesFolderPath: string + }; + + constructor() { + this.files = []; + this.resources = { + ios: [], + android: [] + }; + + this.testDirData = { + tempFolder: "", + appFolderPath: "", + app1FolderPath: "", + appDestFolderPath: "", + appResourcesFolderPath: "" + }; + } +} + describe('Platform Service Tests', () => { let platformService: IPlatformService, testInjector: IInjector; beforeEach(() => { @@ -312,6 +345,9 @@ describe('Platform Service Tests', () => { let appFolderPath = path.join(tempFolder, "app"); fs.createDirectory(appFolderPath); + let nodeModulesPath = path.join(tempFolder, "node_modules"); + fs.createDirectory(nodeModulesPath); + let testsFolderPath = path.join(appFolderPath, "tests"); fs.createDirectory(testsFolderPath); @@ -324,23 +360,8 @@ describe('Platform Service Tests', () => { return { tempFolder, appFolderPath, app1FolderPath, appDestFolderPath, appResourcesFolderPath }; } - async function testPreparePlatform(platformToTest: string, release?: boolean) { - let testDirData = prepareDirStructure(); - - // Add platform specific files to app and app1 folders - let platformSpecificFiles = [ - "test1.ios.js", "test1-ios-js", "test2.android.js", "test2-android-js" - ]; - - let destinationDirectories = [testDirData.appFolderPath, testDirData.app1FolderPath]; - - _.each(destinationDirectories, directoryPath => { - _.each(platformSpecificFiles, filePath => { - let fileFullPath = path.join(directoryPath, filePath); - fs.writeFile(fileFullPath, "testData"); - }); - }); - + async function execPreparePlatform(platformToTest: string, testDirData: any, + release?: boolean) { let platformsData = testInjector.resolve("platformsData"); platformsData.platformsNames = ["ios", "android"]; platformsData.getPlatformData = (platform: string) => { @@ -348,6 +369,7 @@ describe('Platform Service Tests', () => { appDestinationDirectoryPath: testDirData.appDestFolderPath, appResourcesDestinationDirectoryPath: testDirData.appResourcesFolderPath, normalizedPlatformName: platformToTest, + configurationFileName: platformToTest === "ios" ? "Info.plist" : "AndroidManifest.xml", projectRoot: testDirData.tempFolder, platformProjectService: { prepareProject: (): any => null, @@ -355,21 +377,71 @@ describe('Platform Service Tests', () => { createProject: (projectRoot: string, frameworkDir: string) => Promise.resolve(), interpolateData: (projectRoot: string) => Promise.resolve(), afterCreateProject: (projectRoot: string): any => null, - getAppResourcesDestinationDirectoryPath: () => "", + getAppResourcesDestinationDirectoryPath: (projectData: IProjectData, frameworkVersion?: string) : string => { + if (platform === "ios") { + let dirPath = path.join(testDirData.tempFolder, projectData.projectName, + "Resources"); + fs.ensureDirectoryExists(dirPath); + return dirPath; + } else { + let dirPath = path.join(testDirData.tempFolder, "src", "main", "res"); + fs.ensureDirectoryExists(dirPath); + return dirPath; + } + }, processConfigurationFilesFromAppResources: () => Promise.resolve(), ensureConfigurationFileInAppResources: (): any => null, interpolateConfigurationFile: (): void => undefined, - isPlatformPrepared: (projectRoot: string) => false + isPlatformPrepared: (projectRoot: string) => false, + prepareAppResources: (appResourcesDirectoryPath: string, projectData: IProjectData): void => undefined } }; }; let projectData = testInjector.resolve("projectData"); projectData.projectDir = testDirData.tempFolder; + projectData.appDirectoryPath = testDirData.appFolderPath; + projectData.appResourcesDirectoryPath = path.join(testDirData.appFolderPath, "App_Resources"); + projectData.projectName = "app"; platformService = testInjector.resolve("platformService"); const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: false, release: release }; await platformService.preparePlatform(platformToTest, appFilesUpdaterOptions, "", projectData, { provision: null, sdk: null }); + } + + async function testPreparePlatform(platformToTest: string, release?: boolean): Promise { + let testDirData = prepareDirStructure(); + let created: CreatedItems = new CreatedItems(); + created.testDirData = testDirData; + + // Add platform specific files to app and app1 folders + let platformSpecificFiles = [ + "test1.ios.js", "test1-ios-js", "test2.android.js", "test2-android-js" + ]; + + let destinationDirectories = [testDirData.appFolderPath, testDirData.app1FolderPath]; + + _.each(destinationDirectories, directoryPath => { + _.each(platformSpecificFiles, filePath => { + let fileFullPath = path.join(directoryPath, filePath); + fs.writeFile(fileFullPath, "testData"); + + created.files.push(fileFullPath); + }); + }); + + // Add App_Resources file to app and app1 folders + _.each(destinationDirectories, directoryPath => { + let iosIconFullPath = path.join(directoryPath, "App_Resources/iOS/icon.png"); + fs.writeFile(iosIconFullPath, "test-image"); + created.resources.ios.push(iosIconFullPath); + + let androidFullPath = path.join(directoryPath, "App_Resources/Android/icon.png"); + fs.writeFile(androidFullPath, "test-image"); + created.resources.android.push(androidFullPath); + }); + + await execPreparePlatform(platformToTest, testDirData, release); let test1FileName = platformToTest.toLowerCase() === "ios" ? "test1.js" : "test2.js"; let test2FileName = platformToTest.toLowerCase() === "ios" ? "test2.js" : "test1.js"; @@ -388,6 +460,8 @@ describe('Platform Service Tests', () => { // Asserts that the files in tests folder aren't copied assert.isFalse(fs.exists(path.join(testDirData.appDestFolderPath, "tests")), "Asserts that the files in tests folder aren't copied"); } + + return created; } it("should process only files in app folder when preparing for iOS platform", async () => { @@ -406,6 +480,21 @@ describe('Platform Service Tests', () => { await testPreparePlatform("Android", true); }); + it("should sync only changed files, without special folders", async () => { + let createdItems = await testPreparePlatform("ios"); + + // update one file. + const expected = "updated-data-ios"; + let test1Js = _.find(createdItems.files, (f) => f.indexOf('test1.ios.js') !== -1); + fs.writeFile(test1Js, expected); + + await execPreparePlatform("ios", createdItems.testDirData); + + let destinationTest1Js = path.join(createdItems.testDirData.appDestFolderPath, "app", "test1.js"); + let actual = fs.readFile(destinationTest1Js); + assert.equal(actual, expected); + }); + it("invalid xml is caught", async () => { require("colors"); let testDirData = prepareDirStructure(); @@ -433,7 +522,8 @@ describe('Platform Service Tests', () => { ensureConfigurationFileInAppResources: (): any => null, interpolateConfigurationFile: (): void => undefined, isPlatformPrepared: (projectRoot: string) => false - } + }, + frameworkPackageName: "tns-ios" }; }; diff --git a/test/project-changes-service.ts b/test/project-changes-service.ts index fd084167ff..ccd3d9b177 100644 --- a/test/project-changes-service.ts +++ b/test/project-changes-service.ts @@ -47,7 +47,7 @@ class ProjectChangesServiceTest extends BaseServiceTest { } } -describe.only("Project Changes Service Tests", () => { +describe("Project Changes Service Tests", () => { let serviceTest: ProjectChangesServiceTest; beforeEach(() => { serviceTest = new ProjectChangesServiceTest(); From a4907f60f96630d7cb88d9802746e45ac6bf20e9 Mon Sep 17 00:00:00 2001 From: Yosif Yosifov Date: Tue, 11 Apr 2017 15:34:02 +0300 Subject: [PATCH 04/16] Make ios/android lower case folder names, as it seems like in Linux the case-sensitivity plays a role --- test/platform-service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/platform-service.ts b/test/platform-service.ts index 5e46b5832e..bb7256bd89 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -432,11 +432,11 @@ describe('Platform Service Tests', () => { // Add App_Resources file to app and app1 folders _.each(destinationDirectories, directoryPath => { - let iosIconFullPath = path.join(directoryPath, "App_Resources/iOS/icon.png"); + let iosIconFullPath = path.join(directoryPath, "App_Resources/ios/icon.png"); fs.writeFile(iosIconFullPath, "test-image"); created.resources.ios.push(iosIconFullPath); - let androidFullPath = path.join(directoryPath, "App_Resources/Android/icon.png"); + let androidFullPath = path.join(directoryPath, "App_Resources/android/icon.png"); fs.writeFile(androidFullPath, "test-image"); created.resources.android.push(androidFullPath); }); From 37b474e51cf5a0fe3d8ce859816e1f0ffe515a0f Mon Sep 17 00:00:00 2001 From: Yosif Yosifov Date: Tue, 11 Apr 2017 15:45:08 +0300 Subject: [PATCH 05/16] Fix platform names casing --- test/platform-service.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/platform-service.ts b/test/platform-service.ts index bb7256bd89..aa385fb654 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -432,11 +432,11 @@ describe('Platform Service Tests', () => { // Add App_Resources file to app and app1 folders _.each(destinationDirectories, directoryPath => { - let iosIconFullPath = path.join(directoryPath, "App_Resources/ios/icon.png"); + let iosIconFullPath = path.join(directoryPath, "App_Resources/iOS/icon.png"); fs.writeFile(iosIconFullPath, "test-image"); created.resources.ios.push(iosIconFullPath); - let androidFullPath = path.join(directoryPath, "App_Resources/android/icon.png"); + let androidFullPath = path.join(directoryPath, "App_Resources/Android/icon.png"); fs.writeFile(androidFullPath, "test-image"); created.resources.android.push(androidFullPath); }); @@ -481,14 +481,14 @@ describe('Platform Service Tests', () => { }); it("should sync only changed files, without special folders", async () => { - let createdItems = await testPreparePlatform("ios"); + let createdItems = await testPreparePlatform("iOS"); // update one file. const expected = "updated-data-ios"; let test1Js = _.find(createdItems.files, (f) => f.indexOf('test1.ios.js') !== -1); fs.writeFile(test1Js, expected); - await execPreparePlatform("ios", createdItems.testDirData); + await execPreparePlatform("iOS", createdItems.testDirData); let destinationTest1Js = path.join(createdItems.testDirData.appDestFolderPath, "app", "test1.js"); let actual = fs.readFile(destinationTest1Js); From e4ba4c01936fa2168bc96aa267226aba534d360d Mon Sep 17 00:00:00 2001 From: Yosif Yosifov Date: Tue, 11 Apr 2017 16:45:29 +0300 Subject: [PATCH 06/16] Clone the test for Android for file changes --- test/platform-service.ts | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/test/platform-service.ts b/test/platform-service.ts index aa385fb654..604827d265 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -464,6 +464,17 @@ describe('Platform Service Tests', () => { return created; } + function updateFile(files: string[], fileName: string, content: string) { + let fileToUpdate = _.find(files, (f) => f.indexOf(fileName) !== -1); + fs.writeFile(fileToUpdate, content); + } + + function assertFileContent(createdItems: CreatedItems, expectedFileContent: string, fileName: string) { + let destinationFilePath = path.join(createdItems.testDirData.appDestFolderPath, "app", fileName); + let actual = fs.readFile(destinationFilePath); + assert.equal(actual, expectedFileContent); + } + it("should process only files in app folder when preparing for iOS platform", async () => { await testPreparePlatform("iOS"); }); @@ -480,19 +491,26 @@ describe('Platform Service Tests', () => { await testPreparePlatform("Android", true); }); - it("should sync only changed files, without special folders", async () => { + it("should sync only changed files, without special folders (iOS)", async () => { let createdItems = await testPreparePlatform("iOS"); - // update one file. - const expected = "updated-data-ios"; - let test1Js = _.find(createdItems.files, (f) => f.indexOf('test1.ios.js') !== -1); - fs.writeFile(test1Js, expected); + const expectedFileContent = "updated-content-ios"; + updateFile(createdItems.files, "test1.ios.js", expectedFileContent); await execPreparePlatform("iOS", createdItems.testDirData); - let destinationTest1Js = path.join(createdItems.testDirData.appDestFolderPath, "app", "test1.js"); - let actual = fs.readFile(destinationTest1Js); - assert.equal(actual, expected); + assertFileContent(createdItems, expectedFileContent, "test1.js"); + }); + + it("should sync only changed files, without special folders (Android)", async () => { + let createdItems = await testPreparePlatform("Android"); + + const expectedFileContent = "updated-content-android"; + updateFile(createdItems.files, "test2.android.js", expectedFileContent); + + await execPreparePlatform("Android", createdItems.testDirData); + + assertFileContent(createdItems, expectedFileContent, "test2.js"); }); it("invalid xml is caught", async () => { From 7be0a81f3ba4f7d25f8958355e541c134ec68547 Mon Sep 17 00:00:00 2001 From: Yosif Yosifov Date: Tue, 11 Apr 2017 16:49:53 +0300 Subject: [PATCH 07/16] fix lint errors --- test/platform-service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/platform-service.ts b/test/platform-service.ts index 604827d265..1145b7d8f1 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -495,7 +495,7 @@ describe('Platform Service Tests', () => { let createdItems = await testPreparePlatform("iOS"); const expectedFileContent = "updated-content-ios"; - updateFile(createdItems.files, "test1.ios.js", expectedFileContent); + updateFile(createdItems.files, "test1.ios.js", expectedFileContent); await execPreparePlatform("iOS", createdItems.testDirData); @@ -506,7 +506,7 @@ describe('Platform Service Tests', () => { let createdItems = await testPreparePlatform("Android"); const expectedFileContent = "updated-content-android"; - updateFile(createdItems.files, "test2.android.js", expectedFileContent); + updateFile(createdItems.files, "test2.android.js", expectedFileContent); await execPreparePlatform("Android", createdItems.testDirData); From 992adbd70d29757e46d48e88fecb415cf79d9e8b Mon Sep 17 00:00:00 2001 From: Yosif Yosifov Date: Tue, 11 Apr 2017 17:51:22 +0300 Subject: [PATCH 08/16] Add tests for issue #2697 --- test/platform-service.ts | 59 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/test/platform-service.ts b/test/platform-service.ts index 1145b7d8f1..95a83ca55e 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -340,7 +340,7 @@ describe('Platform Service Tests', () => { }); function prepareDirStructure() { - let tempFolder = temp.mkdirSync("prepare platform"); + let tempFolder = temp.mkdirSync("prepare_platform"); let appFolderPath = path.join(tempFolder, "app"); fs.createDirectory(appFolderPath); @@ -378,13 +378,13 @@ describe('Platform Service Tests', () => { interpolateData: (projectRoot: string) => Promise.resolve(), afterCreateProject: (projectRoot: string): any => null, getAppResourcesDestinationDirectoryPath: (projectData: IProjectData, frameworkVersion?: string) : string => { - if (platform === "ios") { + if (platform.toLowerCase() === "ios") { let dirPath = path.join(testDirData.tempFolder, projectData.projectName, "Resources"); fs.ensureDirectoryExists(dirPath); return dirPath; } else { - let dirPath = path.join(testDirData.tempFolder, "src", "main", "res"); + let dirPath = path.join(testDirData.tempFolder, projectData.projectName, "src", "main", "res"); fs.ensureDirectoryExists(dirPath); return dirPath; } @@ -471,10 +471,21 @@ describe('Platform Service Tests', () => { function assertFileContent(createdItems: CreatedItems, expectedFileContent: string, fileName: string) { let destinationFilePath = path.join(createdItems.testDirData.appDestFolderPath, "app", fileName); + let actual = fs.readFile(destinationFilePath); assert.equal(actual, expectedFileContent); } + function assertFilesExistance(createdItems: CreatedItems, present: boolean, fileNames: string[]) { + _.each(fileNames, (fileName) => assertFileExistance(createdItems, present, fileName)); + } + + function assertFileExistance(createdItems: CreatedItems, present: boolean, fileName: string) { + let destinationFilePath = path.join(createdItems.testDirData.appDestFolderPath, "app", fileName); + let fileExists = fs.exists(destinationFilePath); + assert.equal(fileExists, present); + } + it("should process only files in app folder when preparing for iOS platform", async () => { await testPreparePlatform("iOS"); }); @@ -499,10 +510,16 @@ describe('Platform Service Tests', () => { await execPreparePlatform("iOS", createdItems.testDirData); + // assert the updated file have been copied to the destination assertFileContent(createdItems, expectedFileContent, "test1.js"); + + // assert the platform specific files for Android are not copied. + assertFilesExistance(createdItems, false, ["test1.ios.js", "test2.android.js", "test2.js"]); + assertFilesExistance(createdItems, true, ["test1.js", "test2-android-js", "test1-ios-js"]); + assertFileContent(createdItems, "test-image", "Resources/icon.png"); }); - it("should sync only changed files, without special folders (Android)", async () => { + it("should sync only changed files, without special folders (Android) #2697", async () => { let createdItems = await testPreparePlatform("Android"); const expectedFileContent = "updated-content-android"; @@ -510,7 +527,41 @@ describe('Platform Service Tests', () => { await execPreparePlatform("Android", createdItems.testDirData); + // assert the updated file have been copied to the destination assertFileContent(createdItems, expectedFileContent, "test2.js"); + + // assert the platform specific files for iOS are not copied. + assertFilesExistance(createdItems, false, ["test1.android.js", "test2.ios.js", "test1.js"]); + assertFilesExistance(createdItems, true, ["test2.js", "test2-android-js", "test1-ios-js"]); + assertFileContent(createdItems, "test-image", "src/main/res/Resources/icon.png"); + }); + + it("Ensure, App_Resources are not copied in the appDest and left there (iOS) #2697", async () => { + let createdItems = await testPreparePlatform("iOS"); + + const expectedFileContent = "updated-content-ios"; + updateFile(createdItems.files, "test1.ios.js", expectedFileContent); + + await execPreparePlatform("iOS", createdItems.testDirData); + + // assert the App_Resources are not left copied in the destination App Folder + let appResourcesPath = path.join(createdItems.testDirData.appDestFolderPath, "app/App_Resources"); + let dirExists = fs.exists(appResourcesPath); + assert.equal(dirExists, false); + }); + + it("Ensure, App_Resources are not copied in the appDest and left there (Android) #2697", async () => { + let createdItems = await testPreparePlatform("Android"); + + const expectedFileContent = "updated-content-android"; + updateFile(createdItems.files, "test2.android.js", expectedFileContent); + + await execPreparePlatform("Android", createdItems.testDirData); + + // assert the App_Resources are not left copied in the destination App Folder + let appResourcesPath = path.join(createdItems.testDirData.appDestFolderPath, "app/App_Resources"); + let dirExists = fs.exists(appResourcesPath); + assert.equal(dirExists, false); }); it("invalid xml is caught", async () => { From ab14c109f3b749643e99fb702de40413bdf38cf9 Mon Sep 17 00:00:00 2001 From: Yosif Yosifov Date: Tue, 11 Apr 2017 18:46:58 +0300 Subject: [PATCH 09/16] Adding Tests to verify that the App_Resources have been reloaded --- test/platform-service.ts | 94 ++++++++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 24 deletions(-) diff --git a/test/platform-service.ts b/test/platform-service.ts index 95a83ca55e..8727ee7ed1 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -379,12 +379,11 @@ describe('Platform Service Tests', () => { afterCreateProject: (projectRoot: string): any => null, getAppResourcesDestinationDirectoryPath: (projectData: IProjectData, frameworkVersion?: string) : string => { if (platform.toLowerCase() === "ios") { - let dirPath = path.join(testDirData.tempFolder, projectData.projectName, - "Resources"); + let dirPath = path.join(testDirData.appDestFolderPath, "Resources"); fs.ensureDirectoryExists(dirPath); return dirPath; } else { - let dirPath = path.join(testDirData.tempFolder, projectData.projectName, "src", "main", "res"); + let dirPath = path.join(testDirData.appDestFolderPath, "src", "main", "res"); fs.ensureDirectoryExists(dirPath); return dirPath; } @@ -469,23 +468,36 @@ describe('Platform Service Tests', () => { fs.writeFile(fileToUpdate, content); } - function assertFileContent(createdItems: CreatedItems, expectedFileContent: string, fileName: string) { - let destinationFilePath = path.join(createdItems.testDirData.appDestFolderPath, "app", fileName); + function assertAppFileContent(appDestFolderPath: string, expectedFileContent: string, fileName: string) { + let destinationFilePath = path.join(appDestFolderPath, "app", fileName); - let actual = fs.readFile(destinationFilePath); + let actual = fs.readFile(destinationFilePath).toString(); assert.equal(actual, expectedFileContent); } - function assertFilesExistance(createdItems: CreatedItems, present: boolean, fileNames: string[]) { - _.each(fileNames, (fileName) => assertFileExistance(createdItems, present, fileName)); + function assertFileContent(appDestFolderPath: string, expectedFileContent: string, fileName: string) { + let destinationFilePath = path.join(appDestFolderPath, fileName); + + let actual = fs.readFile(destinationFilePath).toString(); + assert.equal(actual, expectedFileContent); + } + + function assertFilesExistance(appDestFolderPath: string, present: boolean, fileNames: string[]) { + _.each(fileNames, (fileName) => assertFileExistance(appDestFolderPath, present, fileName)); } - function assertFileExistance(createdItems: CreatedItems, present: boolean, fileName: string) { - let destinationFilePath = path.join(createdItems.testDirData.appDestFolderPath, "app", fileName); + function assertFileExistance(appDestFolderPath: string, present: boolean, fileName: string) { + let destinationFilePath = path.join(appDestFolderPath, "app", fileName); let fileExists = fs.exists(destinationFilePath); assert.equal(fileExists, present); } + function assertAppResourcesAreRemovedFromAppDest(appDestFolderPath: string) { + let appResourcesPath = path.join(appDestFolderPath, "app/App_Resources"); + let dirExists = fs.exists(appResourcesPath); + assert.equal(dirExists, false); + } + it("should process only files in app folder when preparing for iOS platform", async () => { await testPreparePlatform("iOS"); }); @@ -511,12 +523,14 @@ describe('Platform Service Tests', () => { await execPreparePlatform("iOS", createdItems.testDirData); // assert the updated file have been copied to the destination - assertFileContent(createdItems, expectedFileContent, "test1.js"); + let appDestFolderPath = createdItems.testDirData.appDestFolderPath; + assertAppFileContent(appDestFolderPath, expectedFileContent, "test1.js"); // assert the platform specific files for Android are not copied. - assertFilesExistance(createdItems, false, ["test1.ios.js", "test2.android.js", "test2.js"]); - assertFilesExistance(createdItems, true, ["test1.js", "test2-android-js", "test1-ios-js"]); - assertFileContent(createdItems, "test-image", "Resources/icon.png"); + assertFilesExistance(appDestFolderPath, false, ["test1.ios.js", "test2.android.js", "test2.js"]); + assertFilesExistance(appDestFolderPath, true, ["test1.js", "test2-android-js", "test1-ios-js"]); + assertFileContent(appDestFolderPath, "test-image", "Resources/icon.png"); + assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); }); it("should sync only changed files, without special folders (Android) #2697", async () => { @@ -528,12 +542,14 @@ describe('Platform Service Tests', () => { await execPreparePlatform("Android", createdItems.testDirData); // assert the updated file have been copied to the destination - assertFileContent(createdItems, expectedFileContent, "test2.js"); + let appDestFolderPath = createdItems.testDirData.appDestFolderPath; + assertAppFileContent(appDestFolderPath, expectedFileContent, "test2.js"); // assert the platform specific files for iOS are not copied. - assertFilesExistance(createdItems, false, ["test1.android.js", "test2.ios.js", "test1.js"]); - assertFilesExistance(createdItems, true, ["test2.js", "test2-android-js", "test1-ios-js"]); - assertFileContent(createdItems, "test-image", "src/main/res/Resources/icon.png"); + assertFilesExistance(appDestFolderPath, false, ["test1.android.js", "test2.ios.js", "test1.js"]); + assertFilesExistance(appDestFolderPath, true, ["test2.js", "test2-android-js", "test1-ios-js"]); + assertFileContent(appDestFolderPath, "test-image", "src/main/res/icon.png"); + assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); }); it("Ensure, App_Resources are not copied in the appDest and left there (iOS) #2697", async () => { @@ -545,9 +561,7 @@ describe('Platform Service Tests', () => { await execPreparePlatform("iOS", createdItems.testDirData); // assert the App_Resources are not left copied in the destination App Folder - let appResourcesPath = path.join(createdItems.testDirData.appDestFolderPath, "app/App_Resources"); - let dirExists = fs.exists(appResourcesPath); - assert.equal(dirExists, false); + assertAppResourcesAreRemovedFromAppDest(createdItems.testDirData.appDestFolderPath); }); it("Ensure, App_Resources are not copied in the appDest and left there (Android) #2697", async () => { @@ -559,9 +573,41 @@ describe('Platform Service Tests', () => { await execPreparePlatform("Android", createdItems.testDirData); // assert the App_Resources are not left copied in the destination App Folder - let appResourcesPath = path.join(createdItems.testDirData.appDestFolderPath, "app/App_Resources"); - let dirExists = fs.exists(appResourcesPath); - assert.equal(dirExists, false); + assertAppResourcesAreRemovedFromAppDest(createdItems.testDirData.appDestFolderPath); + }); + + it("Ensure, App_Resources get reloaded, after change in the app folder (iOS) #2560", async () => { + let createdItems = await testPreparePlatform("iOS"); + + const expectedFileContent = "updated-icon-content"; + let iconPngPath = path.join(createdItems.testDirData.appFolderPath, "App_Resources/iOS/icon.png"); + fs.writeFile(iconPngPath, expectedFileContent); + + await execPreparePlatform("iOS", createdItems.testDirData); + + // assert the App_Resources are not left copied in the destination App Folder + let appDestFolderPath = createdItems.testDirData.appDestFolderPath; + assertFilesExistance(appDestFolderPath, false, ["test1.ios.js", "test2.android.js", "test2.js"]); + assertFilesExistance(appDestFolderPath, true, ["test1.js", "test2-android-js", "test1-ios-js"]); + assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); + assertFileContent(appDestFolderPath, expectedFileContent, "Resources/icon.png"); + }); + + it("Ensure, App_Resources get reloaded, after change in the app folder (Android) #2560", async () => { + let createdItems = await testPreparePlatform("Android"); + + const expectedFileContent = "updated-icon-content"; + let iconPngPath = path.join(createdItems.testDirData.appFolderPath, "App_Resources/Android/icon.png"); + fs.writeFile(iconPngPath, expectedFileContent); + + await execPreparePlatform("Android", createdItems.testDirData); + + // assert the App_Resources are not left copied in the destination App Folder + let appDestFolderPath = createdItems.testDirData.appDestFolderPath; + assertFilesExistance(appDestFolderPath, false, ["test1.android.js", "test2.ios.js", "test1.js"]); + assertFilesExistance(appDestFolderPath, true, ["test2.js", "test2-android-js", "test1-ios-js"]); + assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); + assertFileContent(appDestFolderPath, expectedFileContent, "src/main/res/icon.png"); }); it("invalid xml is caught", async () => { From edd0378a5b143730bb6f95153f0ff1452060f739 Mon Sep 17 00:00:00 2001 From: Yosif Yosifov Date: Wed, 12 Apr 2017 10:49:04 +0300 Subject: [PATCH 10/16] Adding tests for new/deleted platform/common files --- test/platform-service.ts | 156 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 155 insertions(+), 1 deletion(-) diff --git a/test/platform-service.ts b/test/platform-service.ts index 8727ee7ed1..792ce0d8f1 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -415,7 +415,8 @@ describe('Platform Service Tests', () => { // Add platform specific files to app and app1 folders let platformSpecificFiles = [ - "test1.ios.js", "test1-ios-js", "test2.android.js", "test2-android-js" + "test1.ios.js", "test1-ios-js", "test2.android.js", "test2-android-js", + "main.js" ]; let destinationDirectories = [testDirData.appFolderPath, testDirData.app1FolderPath]; @@ -610,6 +611,159 @@ describe('Platform Service Tests', () => { assertFileContent(appDestFolderPath, expectedFileContent, "src/main/res/icon.png"); }); + it("should sync new platform specific files (iOS)", async () => { + let createdItems = await testPreparePlatform("iOS"); + + // create a new platform-specific file - test3.ios.js + const expectedFileContent = "new-content-ios"; + fs.writeFile(path.join(createdItems.testDirData.appFolderPath, "test3.ios.js"), expectedFileContent); + + await execPreparePlatform("iOS", createdItems.testDirData); + + // assert the updated file have been copied to the destination + let appDestFolderPath = createdItems.testDirData.appDestFolderPath; + assertAppFileContent(appDestFolderPath, expectedFileContent, "test3.js"); + + // assert the platform specific files for Android are not copied. + assertFilesExistance(appDestFolderPath, false, ["test1.ios.js", "test2.android.js", "test2.js"]); + assertFilesExistance(appDestFolderPath, true, ["test1.js", "test2-android-js", "test1-ios-js"]); + assertFileContent(appDestFolderPath, "test-image", "Resources/icon.png"); + assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); + }); + + it("should sync new platform specific files (Android)", async () => { + let createdItems = await testPreparePlatform("Android"); + + // create a new platform-specific file - test3.ios.js + const expectedFileContent = "new-content-android"; + fs.writeFile(path.join(createdItems.testDirData.appFolderPath, "test3.android.js"), expectedFileContent); + + await execPreparePlatform("Android", createdItems.testDirData); + + // assert the updated file have been copied to the destination + let appDestFolderPath = createdItems.testDirData.appDestFolderPath; + assertAppFileContent(appDestFolderPath, expectedFileContent, "test3.js"); + + // assert the platform specific files for iOS are not copied. + assertFilesExistance(appDestFolderPath, false, ["test1.android.js", "test2.ios.js", "test1.js"]); + assertFilesExistance(appDestFolderPath, true, ["test2.js", "test2-android-js", "test1-ios-js"]); + assertFileContent(appDestFolderPath, "test-image", "src/main/res/icon.png"); + assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); + }); + + it("should sync new common files (iOS)", async () => { + let createdItems = await testPreparePlatform("iOS"); + + // create a new platform-specific file - test3.ios.js + const expectedFileContent = "new-content-ios"; + fs.writeFile(path.join(createdItems.testDirData.appFolderPath, "test3.js"), expectedFileContent); + + await execPreparePlatform("iOS", createdItems.testDirData); + + // assert the updated file have been copied to the destination + let appDestFolderPath = createdItems.testDirData.appDestFolderPath; + assertAppFileContent(appDestFolderPath, expectedFileContent, "test3.js"); + + // assert the platform specific files for Android are not copied. + assertFilesExistance(appDestFolderPath, false, ["test1.ios.js", "test2.android.js", "test2.js"]); + assertFilesExistance(appDestFolderPath, true, ["test1.js", "test2-android-js", "test1-ios-js"]); + assertFileContent(appDestFolderPath, "test-image", "Resources/icon.png"); + assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); + }); + + it("should sync new common files (Android)", async () => { + let createdItems = await testPreparePlatform("Android"); + + // create a new platform-specific file - test3.ios.js + const expectedFileContent = "new-content-android"; + fs.writeFile(path.join(createdItems.testDirData.appFolderPath, "test3.js"), expectedFileContent); + + await execPreparePlatform("Android", createdItems.testDirData); + + // assert the updated file have been copied to the destination + let appDestFolderPath = createdItems.testDirData.appDestFolderPath; + assertAppFileContent(appDestFolderPath, expectedFileContent, "test3.js"); + + // assert the platform specific files for iOS are not copied. + assertFilesExistance(appDestFolderPath, false, ["test1.android.js", "test2.ios.js", "test1.js"]); + assertFilesExistance(appDestFolderPath, true, ["test2.js", "test2-android-js", "test1-ios-js"]); + assertFileContent(appDestFolderPath, "test-image", "src/main/res/icon.png"); + assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); + }); + + it("should sync deleted common file (iOS)", async () => { + let createdItems = await testPreparePlatform("iOS"); + + // delete the common - main.js file + fs.deleteFile(path.join(createdItems.testDirData.appFolderPath, "main.js")); + + await execPreparePlatform("iOS", createdItems.testDirData); + + // assert the updated file have been copied to the destination + let appDestFolderPath = createdItems.testDirData.appDestFolderPath; + assertFileExistance(appDestFolderPath, false, "main.js"); + + // assert the platform specific files for Android are not copied. + assertFilesExistance(appDestFolderPath, false, ["test1.ios.js", "test2.android.js", "test2.js"]); + assertFilesExistance(appDestFolderPath, true, ["test1.js", "test2-android-js", "test1-ios-js"]); + assertFileContent(appDestFolderPath, "test-image", "Resources/icon.png"); + assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); + }); + + it("should sync deleted common file (Android)", async () => { + let createdItems = await testPreparePlatform("Android"); + + // delete the common - main.js file + fs.deleteFile(path.join(createdItems.testDirData.appFolderPath, "main.js")); + await execPreparePlatform("Android", createdItems.testDirData); + + // assert the updated file have been copied to the destination + let appDestFolderPath = createdItems.testDirData.appDestFolderPath; + assertFileExistance(appDestFolderPath, false, "main.js"); + + // assert the platform specific files for iOS are not copied. + assertFilesExistance(appDestFolderPath, false, ["test1.android.js", "test2.ios.js", "test1.js"]); + assertFilesExistance(appDestFolderPath, true, ["test2.js", "test2-android-js", "test1-ios-js"]); + assertFileContent(appDestFolderPath, "test-image", "src/main/res/icon.png"); + assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); + }); + + it("should sync deleted platform specific file (iOS)", async () => { + let createdItems = await testPreparePlatform("iOS"); + + // delete the common - main.js file + fs.deleteFile(path.join(createdItems.testDirData.appFolderPath, "test1.ios.js")); + + await execPreparePlatform("iOS", createdItems.testDirData); + + // assert the updated file have been copied to the destination + let appDestFolderPath = createdItems.testDirData.appDestFolderPath; + assertFileExistance(appDestFolderPath, false, "test1.js"); + // assert the platform specific files for Android are not copied. + assertFilesExistance(appDestFolderPath, false, ["test1.ios.js", "test2.android.js", "test2.js"]); + assertFilesExistance(appDestFolderPath, true, ["test2-android-js", "test1-ios-js"]); + assertFileContent(appDestFolderPath, "test-image", "Resources/icon.png"); + assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); + }); + + it("should sync deleted platform specific file (Android)", async () => { + let createdItems = await testPreparePlatform("Android"); + + // delete the common - main.js file + fs.deleteFile(path.join(createdItems.testDirData.appFolderPath, "test2.android.js")); + await execPreparePlatform("Android", createdItems.testDirData); + + // assert the updated file have been copied to the destination + let appDestFolderPath = createdItems.testDirData.appDestFolderPath; + assertFileExistance(appDestFolderPath, false, "test2.js"); + + // assert the platform specific files for iOS are not copied. + assertFilesExistance(appDestFolderPath, false, ["test1.android.js", "test2.ios.js", "test1.js"]); + assertFilesExistance(appDestFolderPath, true, ["test2-android-js", "test1-ios-js"]); + assertFileContent(appDestFolderPath, "test-image", "src/main/res/icon.png"); + assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); + }); + it("invalid xml is caught", async () => { require("colors"); let testDirData = prepareDirStructure(); From a6e74963baa8e946cc41e4f03a697dd27cf78fc4 Mon Sep 17 00:00:00 2001 From: Yosif Yosifov Date: Wed, 12 Apr 2017 14:29:31 +0300 Subject: [PATCH 11/16] Refactor the changes tests and add some more tests --- test/platform-service.ts | 520 ++++++++++++++++++++++----------------- 1 file changed, 292 insertions(+), 228 deletions(-) diff --git a/test/platform-service.ts b/test/platform-service.ts index 792ce0d8f1..0136771880 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -89,7 +89,7 @@ function createTestInjector() { return testInjector; } -class CreatedItems { +class CreatedTestData { files: string[]; resources: { @@ -122,6 +122,26 @@ class CreatedItems { } } +class DestinationFolderVerifier { + static verify(data: any, fs: IFileSystem) { + _.forOwn(data, (folder, folderRoot) => { + _.each(folder.filesWithContent || [], (file) => { + const filePath = path.join(folderRoot, file.name); + assert.isTrue(fs.exists(filePath)); + assert.equal(fs.readFile(filePath).toString(), file.content); + }); + + _.each(folder.missingFiles || [], (file) => { + assert.isFalse(fs.exists(path.join(folderRoot, file))); + }); + + _.each(folder.presentFiles || [], (file) => { + assert.isTrue(fs.exists(path.join(folderRoot, file))); + }); + }); + } +} + describe('Platform Service Tests', () => { let platformService: IPlatformService, testInjector: IInjector; beforeEach(() => { @@ -330,7 +350,7 @@ describe('Platform Service Tests', () => { }); }); - describe("prepare platform unit tests", () => { + describe.only("prepare platform unit tests", () => { let fs: IFileSystem; beforeEach(() => { @@ -377,7 +397,7 @@ describe('Platform Service Tests', () => { createProject: (projectRoot: string, frameworkDir: string) => Promise.resolve(), interpolateData: (projectRoot: string) => Promise.resolve(), afterCreateProject: (projectRoot: string): any => null, - getAppResourcesDestinationDirectoryPath: (projectData: IProjectData, frameworkVersion?: string) : string => { + getAppResourcesDestinationDirectoryPath: (projectData: IProjectData, frameworkVersion?: string): string => { if (platform.toLowerCase() === "ios") { let dirPath = path.join(testDirData.appDestFolderPath, "Resources"); fs.ensureDirectoryExists(dirPath); @@ -408,9 +428,9 @@ describe('Platform Service Tests', () => { await platformService.preparePlatform(platformToTest, appFilesUpdaterOptions, "", projectData, { provision: null, sdk: null }); } - async function testPreparePlatform(platformToTest: string, release?: boolean): Promise { + async function testPreparePlatform(platformToTest: string, release?: boolean): Promise { let testDirData = prepareDirStructure(); - let created: CreatedItems = new CreatedItems(); + let created: CreatedTestData = new CreatedTestData(); created.testDirData = testDirData; // Add platform specific files to app and app1 folders @@ -469,36 +489,6 @@ describe('Platform Service Tests', () => { fs.writeFile(fileToUpdate, content); } - function assertAppFileContent(appDestFolderPath: string, expectedFileContent: string, fileName: string) { - let destinationFilePath = path.join(appDestFolderPath, "app", fileName); - - let actual = fs.readFile(destinationFilePath).toString(); - assert.equal(actual, expectedFileContent); - } - - function assertFileContent(appDestFolderPath: string, expectedFileContent: string, fileName: string) { - let destinationFilePath = path.join(appDestFolderPath, fileName); - - let actual = fs.readFile(destinationFilePath).toString(); - assert.equal(actual, expectedFileContent); - } - - function assertFilesExistance(appDestFolderPath: string, present: boolean, fileNames: string[]) { - _.each(fileNames, (fileName) => assertFileExistance(appDestFolderPath, present, fileName)); - } - - function assertFileExistance(appDestFolderPath: string, present: boolean, fileName: string) { - let destinationFilePath = path.join(appDestFolderPath, "app", fileName); - let fileExists = fs.exists(destinationFilePath); - assert.equal(fileExists, present); - } - - function assertAppResourcesAreRemovedFromAppDest(appDestFolderPath: string) { - let appResourcesPath = path.join(appDestFolderPath, "app/App_Resources"); - let dirExists = fs.exists(appResourcesPath); - assert.equal(dirExists, false); - } - it("should process only files in app folder when preparing for iOS platform", async () => { await testPreparePlatform("iOS"); }); @@ -515,253 +505,327 @@ describe('Platform Service Tests', () => { await testPreparePlatform("Android", true); }); - it("should sync only changed files, without special folders (iOS)", async () => { - let createdItems = await testPreparePlatform("iOS"); + function getDefaultFolderVerificationData(platform: string, appDestFolderPath: string) { + let data: any = {}; + if (platform.toLowerCase() === "ios") { + data[path.join(appDestFolderPath, "app")] = { + missingFiles: ["test1.ios.js", "test2.android.js", "test2.js", "App_Resources"], + presentFiles: ["test1.js", "test2-android-js", "test1-ios-js", "main.js"] + }; - const expectedFileContent = "updated-content-ios"; - updateFile(createdItems.files, "test1.ios.js", expectedFileContent); + data[appDestFolderPath] = { + filesWithContent: [ + { + name: "Resources/icon.png", + content: "test-image" + } + ] + }; + } else { + data[path.join(appDestFolderPath, "app")] = { + missingFiles: ["test1.android.js", "test2.ios.js", "test1.js"], + presentFiles: ["test2.js", "test2-android-js", "test1-ios-js"] + }; - await execPreparePlatform("iOS", createdItems.testDirData); + data[appDestFolderPath] = { + filesWithContent: [ + { + name: "src/main/res/icon.png", + content: "test-image" + } + ] + }; + } - // assert the updated file have been copied to the destination - let appDestFolderPath = createdItems.testDirData.appDestFolderPath; - assertAppFileContent(appDestFolderPath, expectedFileContent, "test1.js"); + return data; + } - // assert the platform specific files for Android are not copied. - assertFilesExistance(appDestFolderPath, false, ["test1.ios.js", "test2.android.js", "test2.js"]); - assertFilesExistance(appDestFolderPath, true, ["test1.js", "test2-android-js", "test1-ios-js"]); - assertFileContent(appDestFolderPath, "test-image", "Resources/icon.png"); - assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); - }); + function mergeModifications(def: any, mod: any) { + // custom merge to reflect changes + let merged: any = _.cloneDeep(def); + _.forOwn(mod, (modFolder, folderRoot) => { + // whole folder not present in Default + if (!def.hasOwnProperty(folderRoot)) { + merged[folderRoot] = _.cloneDeep(modFolder[folderRoot]); + } else { + let defFolder = def[folderRoot]; + merged[folderRoot].filesWithContent = _.merge(defFolder.filesWithContent || [], modFolder.filesWithContent || []); + merged[folderRoot].missingFiles = (defFolder.missingFiles || []).concat(modFolder.missingFiles || []); + merged[folderRoot].presentFiles = (defFolder.presentFiles || []).concat(modFolder.presentFiles || []); + + // remove the missingFiles from the presentFiles if they were initially there + if (modFolder.missingFiles) { + merged[folderRoot].presentFiles = _.difference(defFolder.presentFiles, modFolder.missingFiles); + } - it("should sync only changed files, without special folders (Android) #2697", async () => { - let createdItems = await testPreparePlatform("Android"); + // remove the presentFiles from the missingFiles if they were initially there. + if (modFolder.presentFiles) { + merged[folderRoot].missingFiles = _.difference(defFolder.presentFiles, modFolder.presentFiles); + } + } + }); - const expectedFileContent = "updated-content-android"; - updateFile(createdItems.files, "test2.android.js", expectedFileContent); + return merged; + } - await execPreparePlatform("Android", createdItems.testDirData); + // Executes a changes test case: + // 1. Executes Prepare Platform for the Platform + // 2. Applies some changes to the App. Persists the expected Modifications + // 3. Executes again Prepare Platform for the Platform + // 4. Gets the Default Destination App Structure and merges it with the Modifications + // 5. Asserts the Destination App matches our expectations + async function testChangesApplied(platform: string, applyChangesFn: (createdTestData: CreatedTestData) => any) { + let createdTestData = await testPreparePlatform(platform); - // assert the updated file have been copied to the destination - let appDestFolderPath = createdItems.testDirData.appDestFolderPath; - assertAppFileContent(appDestFolderPath, expectedFileContent, "test2.js"); + let modifications = applyChangesFn(createdTestData); - // assert the platform specific files for iOS are not copied. - assertFilesExistance(appDestFolderPath, false, ["test1.android.js", "test2.ios.js", "test1.js"]); - assertFilesExistance(appDestFolderPath, true, ["test2.js", "test2-android-js", "test1-ios-js"]); - assertFileContent(appDestFolderPath, "test-image", "src/main/res/icon.png"); - assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); - }); + await execPreparePlatform(platform, createdTestData.testDirData); - it("Ensure, App_Resources are not copied in the appDest and left there (iOS) #2697", async () => { - let createdItems = await testPreparePlatform("iOS"); + let defaultStructure = getDefaultFolderVerificationData(platform, createdTestData.testDirData.appDestFolderPath); - const expectedFileContent = "updated-content-ios"; - updateFile(createdItems.files, "test1.ios.js", expectedFileContent); + let merged = mergeModifications(defaultStructure, modifications); - await execPreparePlatform("iOS", createdItems.testDirData); + DestinationFolderVerifier.verify(merged, fs); + } - // assert the App_Resources are not left copied in the destination App Folder - assertAppResourcesAreRemovedFromAppDest(createdItems.testDirData.appDestFolderPath); + it("should sync only changed files, without special folders (iOS)", async () => { + let applyChangesFn = (createdTestData: CreatedTestData) => { + // apply changes + const expectedFileContent = "updated-content-ios"; + updateFile(createdTestData.files, "test1.ios.js", expectedFileContent); + + // construct the folder modifications data + let modifications: any = {}; + modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { + filesWithContent: [ + { + name: "test1.js", + content: expectedFileContent + } + ] + }; + return modifications; + }; + await testChangesApplied("iOS", applyChangesFn); }); - it("Ensure, App_Resources are not copied in the appDest and left there (Android) #2697", async () => { - let createdItems = await testPreparePlatform("Android"); - - const expectedFileContent = "updated-content-android"; - updateFile(createdItems.files, "test2.android.js", expectedFileContent); - - await execPreparePlatform("Android", createdItems.testDirData); - - // assert the App_Resources are not left copied in the destination App Folder - assertAppResourcesAreRemovedFromAppDest(createdItems.testDirData.appDestFolderPath); + it("should sync only changed files, without special folders (Android) #2697", async () => { + let applyChangesFn = (createdTestData: CreatedTestData) => { + // apply changes + const expectedFileContent = "updated-content-android"; + updateFile(createdTestData.files, "test2.android.js", expectedFileContent); + + // construct the folder modifications data + let modifications: any = {}; + modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { + filesWithContent: [ + { + name: "test2.js", + content: expectedFileContent + } + ] + }; + return modifications; + }; + await testChangesApplied("Android", applyChangesFn); }); it("Ensure, App_Resources get reloaded, after change in the app folder (iOS) #2560", async () => { - let createdItems = await testPreparePlatform("iOS"); - - const expectedFileContent = "updated-icon-content"; - let iconPngPath = path.join(createdItems.testDirData.appFolderPath, "App_Resources/iOS/icon.png"); - fs.writeFile(iconPngPath, expectedFileContent); - - await execPreparePlatform("iOS", createdItems.testDirData); + let applyChangesFn = (createdTestData: CreatedTestData) => { + // apply changes + const expectedFileContent = "updated-icon-content"; + let iconPngPath = path.join(createdTestData.testDirData.appFolderPath, "App_Resources/iOS/icon.png"); + fs.writeFile(iconPngPath, expectedFileContent); + + // construct the folder modifications data + let modifications: any = {}; + modifications[createdTestData.testDirData.appDestFolderPath] = { + filesWithContent: [ + { + name: "Resources/icon.png", + content: expectedFileContent + } + ] + }; - // assert the App_Resources are not left copied in the destination App Folder - let appDestFolderPath = createdItems.testDirData.appDestFolderPath; - assertFilesExistance(appDestFolderPath, false, ["test1.ios.js", "test2.android.js", "test2.js"]); - assertFilesExistance(appDestFolderPath, true, ["test1.js", "test2-android-js", "test1-ios-js"]); - assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); - assertFileContent(appDestFolderPath, expectedFileContent, "Resources/icon.png"); + return modifications; + }; + await testChangesApplied("iOS", applyChangesFn); }); it("Ensure, App_Resources get reloaded, after change in the app folder (Android) #2560", async () => { - let createdItems = await testPreparePlatform("Android"); - - const expectedFileContent = "updated-icon-content"; - let iconPngPath = path.join(createdItems.testDirData.appFolderPath, "App_Resources/Android/icon.png"); - fs.writeFile(iconPngPath, expectedFileContent); - - await execPreparePlatform("Android", createdItems.testDirData); + let applyChangesFn = (createdTestData: CreatedTestData) => { + // apply changes + const expectedFileContent = "updated-icon-content"; + let iconPngPath = path.join(createdTestData.testDirData.appFolderPath, "App_Resources/Android/icon.png"); + fs.writeFile(iconPngPath, expectedFileContent); + + // construct the folder modifications data + let modifications: any = {}; + modifications[createdTestData.testDirData.appDestFolderPath] = { + filesWithContent: [ + { + name: "src/main/res/icon.png", + content: expectedFileContent + } + ] + }; - // assert the App_Resources are not left copied in the destination App Folder - let appDestFolderPath = createdItems.testDirData.appDestFolderPath; - assertFilesExistance(appDestFolderPath, false, ["test1.android.js", "test2.ios.js", "test1.js"]); - assertFilesExistance(appDestFolderPath, true, ["test2.js", "test2-android-js", "test1-ios-js"]); - assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); - assertFileContent(appDestFolderPath, expectedFileContent, "src/main/res/icon.png"); + return modifications; + }; + await testChangesApplied("Android", applyChangesFn); }); it("should sync new platform specific files (iOS)", async () => { - let createdItems = await testPreparePlatform("iOS"); - - // create a new platform-specific file - test3.ios.js - const expectedFileContent = "new-content-ios"; - fs.writeFile(path.join(createdItems.testDirData.appFolderPath, "test3.ios.js"), expectedFileContent); - - await execPreparePlatform("iOS", createdItems.testDirData); - - // assert the updated file have been copied to the destination - let appDestFolderPath = createdItems.testDirData.appDestFolderPath; - assertAppFileContent(appDestFolderPath, expectedFileContent, "test3.js"); + let applyChangesFn = (createdTestData: CreatedTestData) => { + // apply changes + const expectedFileContent = "new-content-ios"; + fs.writeFile(path.join(createdTestData.testDirData.appFolderPath, "test3.ios.js"), expectedFileContent); + + // construct the folder modifications data + let modifications: any = {}; + modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { + filesWithContent: [ + { + name: "test3.js", + content: expectedFileContent + } + ] + }; - // assert the platform specific files for Android are not copied. - assertFilesExistance(appDestFolderPath, false, ["test1.ios.js", "test2.android.js", "test2.js"]); - assertFilesExistance(appDestFolderPath, true, ["test1.js", "test2-android-js", "test1-ios-js"]); - assertFileContent(appDestFolderPath, "test-image", "Resources/icon.png"); - assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); + return modifications; + }; + await testChangesApplied("iOS", applyChangesFn); }); it("should sync new platform specific files (Android)", async () => { - let createdItems = await testPreparePlatform("Android"); - - // create a new platform-specific file - test3.ios.js - const expectedFileContent = "new-content-android"; - fs.writeFile(path.join(createdItems.testDirData.appFolderPath, "test3.android.js"), expectedFileContent); - - await execPreparePlatform("Android", createdItems.testDirData); - - // assert the updated file have been copied to the destination - let appDestFolderPath = createdItems.testDirData.appDestFolderPath; - assertAppFileContent(appDestFolderPath, expectedFileContent, "test3.js"); + let applyChangesFn = (createdTestData: CreatedTestData) => { + // apply changes + const expectedFileContent = "new-content-android"; + fs.writeFile(path.join(createdTestData.testDirData.appFolderPath, "test3.android.js"), expectedFileContent); + + // construct the folder modifications data + let modifications: any = {}; + modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { + filesWithContent: [ + { + name: "test3.js", + content: expectedFileContent + } + ] + }; - // assert the platform specific files for iOS are not copied. - assertFilesExistance(appDestFolderPath, false, ["test1.android.js", "test2.ios.js", "test1.js"]); - assertFilesExistance(appDestFolderPath, true, ["test2.js", "test2-android-js", "test1-ios-js"]); - assertFileContent(appDestFolderPath, "test-image", "src/main/res/icon.png"); - assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); + return modifications; + }; + await testChangesApplied("Android", applyChangesFn); }); it("should sync new common files (iOS)", async () => { - let createdItems = await testPreparePlatform("iOS"); - - // create a new platform-specific file - test3.ios.js - const expectedFileContent = "new-content-ios"; - fs.writeFile(path.join(createdItems.testDirData.appFolderPath, "test3.js"), expectedFileContent); - - await execPreparePlatform("iOS", createdItems.testDirData); - - // assert the updated file have been copied to the destination - let appDestFolderPath = createdItems.testDirData.appDestFolderPath; - assertAppFileContent(appDestFolderPath, expectedFileContent, "test3.js"); + let applyChangesFn = (createdTestData: CreatedTestData) => { + // apply changes + const expectedFileContent = "new-content-ios"; + fs.writeFile(path.join(createdTestData.testDirData.appFolderPath, "test3.js"), expectedFileContent); + + // construct the folder modifications data + let modifications: any = {}; + modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { + filesWithContent: [ + { + name: "test3.js", + content: expectedFileContent + } + ] + }; - // assert the platform specific files for Android are not copied. - assertFilesExistance(appDestFolderPath, false, ["test1.ios.js", "test2.android.js", "test2.js"]); - assertFilesExistance(appDestFolderPath, true, ["test1.js", "test2-android-js", "test1-ios-js"]); - assertFileContent(appDestFolderPath, "test-image", "Resources/icon.png"); - assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); + return modifications; + }; + await testChangesApplied("iOS", applyChangesFn); }); - it("should sync new common files (Android)", async () => { - let createdItems = await testPreparePlatform("Android"); - - // create a new platform-specific file - test3.ios.js - const expectedFileContent = "new-content-android"; - fs.writeFile(path.join(createdItems.testDirData.appFolderPath, "test3.js"), expectedFileContent); - - await execPreparePlatform("Android", createdItems.testDirData); - - // assert the updated file have been copied to the destination - let appDestFolderPath = createdItems.testDirData.appDestFolderPath; - assertAppFileContent(appDestFolderPath, expectedFileContent, "test3.js"); + it("should sync new common file (Android)", async () => { + let applyChangesFn = (createdTestData: CreatedTestData) => { + // apply changes + const expectedFileContent = "new-content-android"; + fs.writeFile(path.join(createdTestData.testDirData.appFolderPath, "test3.js"), expectedFileContent); + + // construct the folder modifications data + let modifications: any = {}; + modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { + filesWithContent: [ + { + name: "test3.js", + content: expectedFileContent + } + ] + }; - // assert the platform specific files for iOS are not copied. - assertFilesExistance(appDestFolderPath, false, ["test1.android.js", "test2.ios.js", "test1.js"]); - assertFilesExistance(appDestFolderPath, true, ["test2.js", "test2-android-js", "test1-ios-js"]); - assertFileContent(appDestFolderPath, "test-image", "src/main/res/icon.png"); - assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); + return modifications; + }; + await testChangesApplied("Android", applyChangesFn); }); it("should sync deleted common file (iOS)", async () => { - let createdItems = await testPreparePlatform("iOS"); - - // delete the common - main.js file - fs.deleteFile(path.join(createdItems.testDirData.appFolderPath, "main.js")); - - await execPreparePlatform("iOS", createdItems.testDirData); - - // assert the updated file have been copied to the destination - let appDestFolderPath = createdItems.testDirData.appDestFolderPath; - assertFileExistance(appDestFolderPath, false, "main.js"); + let applyChangesFn = (createdTestData: CreatedTestData) => { + // apply changes + fs.deleteFile(path.join(createdTestData.testDirData.appFolderPath, "main.js")); + + // construct the folder modifications data + let modifications: any = {}; + modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { + missingFiles: [ "main.js" ] + }; - // assert the platform specific files for Android are not copied. - assertFilesExistance(appDestFolderPath, false, ["test1.ios.js", "test2.android.js", "test2.js"]); - assertFilesExistance(appDestFolderPath, true, ["test1.js", "test2-android-js", "test1-ios-js"]); - assertFileContent(appDestFolderPath, "test-image", "Resources/icon.png"); - assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); + return modifications; + }; + await testChangesApplied("iOS", applyChangesFn); }); it("should sync deleted common file (Android)", async () => { - let createdItems = await testPreparePlatform("Android"); - - // delete the common - main.js file - fs.deleteFile(path.join(createdItems.testDirData.appFolderPath, "main.js")); - await execPreparePlatform("Android", createdItems.testDirData); - - // assert the updated file have been copied to the destination - let appDestFolderPath = createdItems.testDirData.appDestFolderPath; - assertFileExistance(appDestFolderPath, false, "main.js"); + let applyChangesFn = (createdTestData: CreatedTestData) => { + // apply changes + fs.deleteFile(path.join(createdTestData.testDirData.appFolderPath, "main.js")); + + // construct the folder modifications data + let modifications: any = {}; + modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { + missingFiles: [ "main.js" ] + }; - // assert the platform specific files for iOS are not copied. - assertFilesExistance(appDestFolderPath, false, ["test1.android.js", "test2.ios.js", "test1.js"]); - assertFilesExistance(appDestFolderPath, true, ["test2.js", "test2-android-js", "test1-ios-js"]); - assertFileContent(appDestFolderPath, "test-image", "src/main/res/icon.png"); - assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); + return modifications; + }; + await testChangesApplied("Android", applyChangesFn); }); it("should sync deleted platform specific file (iOS)", async () => { - let createdItems = await testPreparePlatform("iOS"); - - // delete the common - main.js file - fs.deleteFile(path.join(createdItems.testDirData.appFolderPath, "test1.ios.js")); - - await execPreparePlatform("iOS", createdItems.testDirData); + let applyChangesFn = (createdTestData: CreatedTestData) => { + // apply changes + fs.deleteFile(path.join(createdTestData.testDirData.appFolderPath, "test1.ios.js")); + + // construct the folder modifications data + let modifications: any = {}; + modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { + missingFiles: [ "test1.js" ] + }; - // assert the updated file have been copied to the destination - let appDestFolderPath = createdItems.testDirData.appDestFolderPath; - assertFileExistance(appDestFolderPath, false, "test1.js"); - // assert the platform specific files for Android are not copied. - assertFilesExistance(appDestFolderPath, false, ["test1.ios.js", "test2.android.js", "test2.js"]); - assertFilesExistance(appDestFolderPath, true, ["test2-android-js", "test1-ios-js"]); - assertFileContent(appDestFolderPath, "test-image", "Resources/icon.png"); - assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); + return modifications; + }; + await testChangesApplied("iOS", applyChangesFn); }); it("should sync deleted platform specific file (Android)", async () => { - let createdItems = await testPreparePlatform("Android"); - - // delete the common - main.js file - fs.deleteFile(path.join(createdItems.testDirData.appFolderPath, "test2.android.js")); - await execPreparePlatform("Android", createdItems.testDirData); - - // assert the updated file have been copied to the destination - let appDestFolderPath = createdItems.testDirData.appDestFolderPath; - assertFileExistance(appDestFolderPath, false, "test2.js"); + let applyChangesFn = (createdTestData: CreatedTestData) => { + // apply changes + fs.deleteFile(path.join(createdTestData.testDirData.appFolderPath, "test2.android.js")); + + // construct the folder modifications data + let modifications: any = {}; + modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { + missingFiles: [ "test2.js" ] + }; - // assert the platform specific files for iOS are not copied. - assertFilesExistance(appDestFolderPath, false, ["test1.android.js", "test2.ios.js", "test1.js"]); - assertFilesExistance(appDestFolderPath, true, ["test2-android-js", "test1-ios-js"]); - assertFileContent(appDestFolderPath, "test-image", "src/main/res/icon.png"); - assertAppResourcesAreRemovedFromAppDest(appDestFolderPath); + return modifications; + }; + await testChangesApplied("Android", applyChangesFn); }); it("invalid xml is caught", async () => { From 0d86b87e3cbb32bb6487c5af9acd06e5196d1bb4 Mon Sep 17 00:00:00 2001 From: Yosif Yosifov Date: Wed, 12 Apr 2017 14:38:24 +0300 Subject: [PATCH 12/16] Improve assertions to include message what was wrong with the directory structure --- test/platform-service.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/platform-service.ts b/test/platform-service.ts index 0136771880..cabc468000 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -127,16 +127,16 @@ class DestinationFolderVerifier { _.forOwn(data, (folder, folderRoot) => { _.each(folder.filesWithContent || [], (file) => { const filePath = path.join(folderRoot, file.name); - assert.isTrue(fs.exists(filePath)); - assert.equal(fs.readFile(filePath).toString(), file.content); + assert.isTrue(fs.exists(filePath), `Expected file {filePath} to be present.`); + assert.equal(fs.readFile(filePath).toString(), file.content, `File content for {filePath} doesn't match.`); }); _.each(folder.missingFiles || [], (file) => { - assert.isFalse(fs.exists(path.join(folderRoot, file))); + assert.isFalse(fs.exists(path.join(folderRoot, file)), `Expected file {file} to be missing.`); }); _.each(folder.presentFiles || [], (file) => { - assert.isTrue(fs.exists(path.join(folderRoot, file))); + assert.isTrue(fs.exists(path.join(folderRoot, file)), `Expected file {file} to be present.`); }); }); } From 0dfc713a2373fa3c041938d00c05633f702985ef Mon Sep 17 00:00:00 2001 From: Yosif Yosifov Date: Wed, 12 Apr 2017 14:44:07 +0300 Subject: [PATCH 13/16] Minor messages improvement --- test/platform-service.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/platform-service.ts b/test/platform-service.ts index cabc468000..7b61b452f1 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -127,16 +127,16 @@ class DestinationFolderVerifier { _.forOwn(data, (folder, folderRoot) => { _.each(folder.filesWithContent || [], (file) => { const filePath = path.join(folderRoot, file.name); - assert.isTrue(fs.exists(filePath), `Expected file {filePath} to be present.`); - assert.equal(fs.readFile(filePath).toString(), file.content, `File content for {filePath} doesn't match.`); + assert.isTrue(fs.exists(filePath), `Expected file ${filePath} to be present.`); + assert.equal(fs.readFile(filePath).toString(), file.content, `File content for ${filePath} doesn't match.`); }); _.each(folder.missingFiles || [], (file) => { - assert.isFalse(fs.exists(path.join(folderRoot, file)), `Expected file {file} to be missing.`); + assert.isFalse(fs.exists(path.join(folderRoot, file)), `Expected file ${file} to be missing.`); }); _.each(folder.presentFiles || [], (file) => { - assert.isTrue(fs.exists(path.join(folderRoot, file)), `Expected file {file} to be present.`); + assert.isTrue(fs.exists(path.join(folderRoot, file)), `Expected file ${file} to be present.`); }); }); } From 3d473312aeaed8f998aea22e52bb4f397bcd9ad9 Mon Sep 17 00:00:00 2001 From: Yosif Yosifov Date: Wed, 12 Apr 2017 16:37:31 +0300 Subject: [PATCH 14/16] remove delete file tests - seems we do not support this currently. --- test/platform-service.ts | 66 +--------------------------------------- 1 file changed, 1 insertion(+), 65 deletions(-) diff --git a/test/platform-service.ts b/test/platform-service.ts index 7b61b452f1..6c05943fe6 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -350,7 +350,7 @@ describe('Platform Service Tests', () => { }); }); - describe.only("prepare platform unit tests", () => { + describe("prepare platform unit tests", () => { let fs: IFileSystem; beforeEach(() => { @@ -764,70 +764,6 @@ describe('Platform Service Tests', () => { await testChangesApplied("Android", applyChangesFn); }); - it("should sync deleted common file (iOS)", async () => { - let applyChangesFn = (createdTestData: CreatedTestData) => { - // apply changes - fs.deleteFile(path.join(createdTestData.testDirData.appFolderPath, "main.js")); - - // construct the folder modifications data - let modifications: any = {}; - modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { - missingFiles: [ "main.js" ] - }; - - return modifications; - }; - await testChangesApplied("iOS", applyChangesFn); - }); - - it("should sync deleted common file (Android)", async () => { - let applyChangesFn = (createdTestData: CreatedTestData) => { - // apply changes - fs.deleteFile(path.join(createdTestData.testDirData.appFolderPath, "main.js")); - - // construct the folder modifications data - let modifications: any = {}; - modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { - missingFiles: [ "main.js" ] - }; - - return modifications; - }; - await testChangesApplied("Android", applyChangesFn); - }); - - it("should sync deleted platform specific file (iOS)", async () => { - let applyChangesFn = (createdTestData: CreatedTestData) => { - // apply changes - fs.deleteFile(path.join(createdTestData.testDirData.appFolderPath, "test1.ios.js")); - - // construct the folder modifications data - let modifications: any = {}; - modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { - missingFiles: [ "test1.js" ] - }; - - return modifications; - }; - await testChangesApplied("iOS", applyChangesFn); - }); - - it("should sync deleted platform specific file (Android)", async () => { - let applyChangesFn = (createdTestData: CreatedTestData) => { - // apply changes - fs.deleteFile(path.join(createdTestData.testDirData.appFolderPath, "test2.android.js")); - - // construct the folder modifications data - let modifications: any = {}; - modifications[path.join(createdTestData.testDirData.appDestFolderPath, "app")] = { - missingFiles: [ "test2.js" ] - }; - - return modifications; - }; - await testChangesApplied("Android", applyChangesFn); - }); - it("invalid xml is caught", async () => { require("colors"); let testDirData = prepareDirStructure(); From 79dfe7be2177a15e19a9a58e2a85917be1093e07 Mon Sep 17 00:00:00 2001 From: Yosif Yosifov Date: Wed, 12 Apr 2017 17:48:50 +0300 Subject: [PATCH 15/16] Adding tests to verify new files in App_Resources are detected and copied to destination. --- test/platform-service.ts | 52 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/test/platform-service.ts b/test/platform-service.ts index 6c05943fe6..c3514204c7 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -142,7 +142,7 @@ class DestinationFolderVerifier { } } -describe('Platform Service Tests', () => { +describe.only('Platform Service Tests', () => { let platformService: IPlatformService, testInjector: IInjector; beforeEach(() => { testInjector = createTestInjector(); @@ -630,7 +630,7 @@ describe('Platform Service Tests', () => { await testChangesApplied("Android", applyChangesFn); }); - it("Ensure, App_Resources get reloaded, after change in the app folder (iOS) #2560", async () => { + it("Ensure App_Resources get reloaded after change in the app folder (iOS) #2560", async () => { let applyChangesFn = (createdTestData: CreatedTestData) => { // apply changes const expectedFileContent = "updated-icon-content"; @@ -653,7 +653,7 @@ describe('Platform Service Tests', () => { await testChangesApplied("iOS", applyChangesFn); }); - it("Ensure, App_Resources get reloaded, after change in the app folder (Android) #2560", async () => { + it("Ensure App_Resources get reloaded after change in the app folder (Android) #2560", async () => { let applyChangesFn = (createdTestData: CreatedTestData) => { // apply changes const expectedFileContent = "updated-icon-content"; @@ -676,6 +676,52 @@ describe('Platform Service Tests', () => { await testChangesApplied("Android", applyChangesFn); }); + it("Ensure App_Resources get reloaded after a new file appears in the app folder (iOS) #2560", async () => { + let applyChangesFn = (createdTestData: CreatedTestData) => { + // apply changes + const expectedFileContent = "new-file-content"; + let iconPngPath = path.join(createdTestData.testDirData.appFolderPath, "App_Resources/iOS/new-file.png"); + fs.writeFile(iconPngPath, expectedFileContent); + + // construct the folder modifications data + let modifications: any = {}; + modifications[createdTestData.testDirData.appDestFolderPath] = { + filesWithContent: [ + { + name: "Resources/new-file.png", + content: expectedFileContent + } + ] + }; + + return modifications; + }; + await testChangesApplied("iOS", applyChangesFn); + }); + + it("Ensure App_Resources get reloaded after a new file appears in the app folder (Android) #2560", async () => { + let applyChangesFn = (createdTestData: CreatedTestData) => { + // apply changes + const expectedFileContent = "new-file-content"; + let iconPngPath = path.join(createdTestData.testDirData.appFolderPath, "App_Resources/Android/new-file.png"); + fs.writeFile(iconPngPath, expectedFileContent); + + // construct the folder modifications data + let modifications: any = {}; + modifications[createdTestData.testDirData.appDestFolderPath] = { + filesWithContent: [ + { + name: "src/main/res/new-file.png", + content: expectedFileContent + } + ] + }; + + return modifications; + }; + await testChangesApplied("Android", applyChangesFn); + }); + it("should sync new platform specific files (iOS)", async () => { let applyChangesFn = (createdTestData: CreatedTestData) => { // apply changes From 02309eef984612f4a2d3751567a510fed4123500 Mon Sep 17 00:00:00 2001 From: Yosif Yosifov Date: Thu, 13 Apr 2017 14:17:34 +0300 Subject: [PATCH 16/16] Remove .only() which was used only for debugging purposes on the Travis CI --- test/platform-service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/platform-service.ts b/test/platform-service.ts index c3514204c7..532b277f00 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -142,7 +142,7 @@ class DestinationFolderVerifier { } } -describe.only('Platform Service Tests', () => { +describe('Platform Service Tests', () => { let platformService: IPlatformService, testInjector: IInjector; beforeEach(() => { testInjector = createTestInjector();