|
| 1 | +/// <reference path=".d.ts" /> |
| 2 | +"use strict"; |
| 3 | + |
| 4 | +import { Yok } from "../lib/common/yok"; |
| 5 | +import { ProjectFilesProvider } from "../lib/providers/project-files-provider"; |
| 6 | +import { assert } from "chai"; |
| 7 | +import * as path from "path"; |
| 8 | +import Future = require("fibers/future"); |
| 9 | + |
| 10 | +let projectDir = "projectDir", |
| 11 | + appDestinationDirectoryPath = "appDestinationDirectoryPath", |
| 12 | + appResourcesDestinationDirectoryPath = "appResourcesDestinationDirectoryPath", |
| 13 | + appSourceDir = path.join(projectDir, "app"); |
| 14 | + |
| 15 | +function createTestInjector(): IInjector { |
| 16 | + let testInjector = new Yok(); |
| 17 | + testInjector.register("mobileHelper", { |
| 18 | + platformNames: ["Android", "iOS"] |
| 19 | + }); |
| 20 | + |
| 21 | + testInjector.register("platformsData", { |
| 22 | + getPlatformData: (platform: string) => { |
| 23 | + return { |
| 24 | + appDestinationDirectoryPath: appDestinationDirectoryPath, |
| 25 | + normalizedPlatformName: platform.toLowerCase(), |
| 26 | + platformProjectService: { |
| 27 | + getAppResourcesDestinationDirectoryPath: () => Future.fromResult(appResourcesDestinationDirectoryPath) |
| 28 | + } |
| 29 | + }; |
| 30 | + }, |
| 31 | + }); |
| 32 | + |
| 33 | + testInjector.register("projectData", { |
| 34 | + projectDir: projectDir |
| 35 | + }); |
| 36 | + |
| 37 | + testInjector.register("options", { release: false }); |
| 38 | + |
| 39 | + return testInjector; |
| 40 | +} |
| 41 | + |
| 42 | +describe("project-files-provider", () => { |
| 43 | + let testInjector: IInjector, |
| 44 | + projectFilesProvider: IProjectFilesProvider; |
| 45 | + |
| 46 | + beforeEach(() => { |
| 47 | + testInjector = createTestInjector(); |
| 48 | + projectFilesProvider = testInjector.resolve(ProjectFilesProvider); |
| 49 | + }); |
| 50 | + |
| 51 | + describe("isFileExcluded", () => { |
| 52 | + it("returns true for .ts files", () => { |
| 53 | + assert.isTrue(projectFilesProvider.isFileExcluded("test.ts")); |
| 54 | + }); |
| 55 | + |
| 56 | + it("returns false for .js files", () => { |
| 57 | + assert.isFalse(projectFilesProvider.isFileExcluded("test.js")); |
| 58 | + }); |
| 59 | + }); |
| 60 | + |
| 61 | + describe("mapFilePath", () => { |
| 62 | + it("returns file path from prepared project when path from app dir is passed", () => { |
| 63 | + let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "test.js"), "android"); |
| 64 | + assert.deepEqual(mappedFilePath, path.join(appDestinationDirectoryPath, "app", "test.js")); |
| 65 | + }); |
| 66 | + |
| 67 | + it("returns file path from prepared project when path from app/App_Resources/platform dir is passed", () => { |
| 68 | + let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "App_Resources", "android", "test.js"), "android"); |
| 69 | + assert.deepEqual(mappedFilePath, path.join(appResourcesDestinationDirectoryPath, "test.js")); |
| 70 | + }); |
| 71 | + |
| 72 | + it("returns null when path from app/App_Resources/android dir is passed and iOS platform is specified", () => { |
| 73 | + let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "App_Resources", "android", "test.js"), "iOS"); |
| 74 | + assert.deepEqual(mappedFilePath, null); |
| 75 | + }); |
| 76 | + |
| 77 | + it("returns null when path from app/App_Resources/ dir (not platform specific) is passed", () => { |
| 78 | + let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "App_Resources", "test.js"), "android"); |
| 79 | + assert.deepEqual(mappedFilePath, null); |
| 80 | + }); |
| 81 | + |
| 82 | + it("returns file path from prepared project when path from app dir is passed and it contains platform in its name", () => { |
| 83 | + let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "test.android.js"), "android"); |
| 84 | + assert.deepEqual(mappedFilePath, path.join(appDestinationDirectoryPath, "app", "test.js")); |
| 85 | + }); |
| 86 | + |
| 87 | + it("returns file path from prepared project when path from app dir is passed and it contains configuration in its name", () => { |
| 88 | + let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "test.debug.js"), "android"); |
| 89 | + assert.deepEqual(mappedFilePath, path.join(appDestinationDirectoryPath, "app", "test.js")); |
| 90 | + }); |
| 91 | + }); |
| 92 | +}); |
0 commit comments