UNPKG

mobile-cli-lib

Version:
108 lines (107 loc) 6.68 kB
"use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; var yok_1 = require("../../yok"); var project_files_provider_base_1 = require("../../services/project-files-provider-base"); var chai_1 = require("chai"); var path = require("path"); var ProjectFilesProvider = (function (_super) { __extends(ProjectFilesProvider, _super); function ProjectFilesProvider($mobileHelper, $options) { _super.call(this, $mobileHelper, $options); } ProjectFilesProvider.prototype.isFileExcluded = function (filePath) { throw new Error("Testing ProjectFilesProviderBase should not test abstract member isFileExcluded."); }; ProjectFilesProvider.prototype.mapFilePath = function (filePath, platform) { throw new Error("Testing ProjectFilesProviderBase should not test abstract member mapFilePath."); }; return ProjectFilesProvider; }(project_files_provider_base_1.ProjectFilesProviderBase)); function createTestInjector() { var testInjector = new yok_1.Yok(); testInjector.register("mobileHelper", { platformNames: ["Android", "iOS"] }); testInjector.register("options", { release: false }); return testInjector; } describe("ProjectFilesProviderBase", function () { var testInjector, projectFilesProviderBase, expectedFilePath = path.join("/test", "filePath.ts"); beforeEach(function () { testInjector = createTestInjector(); projectFilesProviderBase = testInjector.resolve(ProjectFilesProvider); }); describe("getPreparedFilePath", function () { it("returns correct path, when fileName does not contain platforms", function () { var filePath = "/test/filePath.ts", preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath); chai_1.assert.deepEqual(preparedPath, expectedFilePath); }); it("returns correct path, when fileName contains android platform", function () { var filePath = "/test/filePath.android.ts", preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath); chai_1.assert.deepEqual(preparedPath, expectedFilePath); }); it("returns correct path, when fileName contains ios platform", function () { var filePath = "/test/filePath.iOS.ts", preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath); chai_1.assert.deepEqual(preparedPath, expectedFilePath); }); it("returns correct path, when fileName contains platform (case insensitive test)", function () { var filePath = "/test/filePath.AnDroId.ts", preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath); chai_1.assert.deepEqual(preparedPath, expectedFilePath); }); it("returns correct path, when fileName contains debug configuration", function () { var filePath = "/test/filePath.debug.ts", preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath); chai_1.assert.deepEqual(preparedPath, expectedFilePath); }); it("returns correct path, when fileName contains debug configuration (case insensitive test)", function () { var filePath = "/test/filePath.DebUG.ts", preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath); chai_1.assert.deepEqual(preparedPath, expectedFilePath); }); it("returns correct path, when fileName contains release configuration", function () { var filePath = "/test/filePath.release.ts", preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath); chai_1.assert.deepEqual(preparedPath, expectedFilePath); }); }); describe("getProjectFileInfo", function () { var getExpectedProjectFileInfo = function (filePath, shouldIncludeFile) { return { filePath: filePath, onDeviceFileName: path.basename(expectedFilePath), shouldIncludeFile: shouldIncludeFile }; }; it("process file without platforms in the name", function () { var filePath = "/test/filePath.ts", projectFileInfo = projectFilesProviderBase.getProjectFileInfo(filePath, ""); chai_1.assert.deepEqual(projectFileInfo, getExpectedProjectFileInfo(filePath, true)); }); it("process file with android platform in the name", function () { var filePath = "/test/filePath.android.ts", projectFileInfo = projectFilesProviderBase.getProjectFileInfo(filePath, "android"); chai_1.assert.deepEqual(projectFileInfo, getExpectedProjectFileInfo(filePath, true)); }); it("process file with android platform in the name (case insensitive test)", function () { var filePath = "/test/filePath.AndRoID.ts", projectFileInfo = projectFilesProviderBase.getProjectFileInfo(filePath, "android"); chai_1.assert.deepEqual(projectFileInfo, getExpectedProjectFileInfo(filePath, true)); }); it("process file with iOS platform in the name", function () { var filePath = "/test/filePath.ios.ts", projectFileInfo = projectFilesProviderBase.getProjectFileInfo(filePath, "android"); chai_1.assert.deepEqual(projectFileInfo, getExpectedProjectFileInfo(filePath, false)); }); it("process file with debug configuration in the name", function () { var filePath = "/test/filePath.debug.ts", projectFileInfo = projectFilesProviderBase.getProjectFileInfo(filePath, "android"); chai_1.assert.deepEqual(projectFileInfo, getExpectedProjectFileInfo(filePath, true)); }); it("process file with release configuration in the name", function () { var filePath = "/test/filePath.release.ts", projectFileInfo = projectFilesProviderBase.getProjectFileInfo(filePath, "android"); chai_1.assert.deepEqual(projectFileInfo, getExpectedProjectFileInfo(filePath, false)); }); it("process file with release configuration in the name, shouldIncludeFile must be true when options.release is true", function () { var filePath = "/test/filePath.release.ts"; testInjector.resolve("options").release = true; var projectFileInfo = projectFilesProviderBase.getProjectFileInfo(filePath, "android", { configuration: "release" }); chai_1.assert.deepEqual(projectFileInfo, getExpectedProjectFileInfo(filePath, true)); }); }); });