Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lib/common/test/unit-tests/file-system.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Yok } from "../../yok";
import { mkdtempSync } from "fs";
import { tmpdir } from "os";
import * as path from "path";
import * as temp from "temp";
import * as hostInfoLib from "../../host-info";
import { assert, use } from "chai";
import "chai-as-promised";
Expand Down Expand Up @@ -28,7 +29,6 @@ function isOsCaseSensitive(testInjector: IInjector): boolean {
const hostInfo = testInjector.resolve("hostInfo");
return hostInfo.isLinux;
}
temp.track();

function createWriteJsonTestCases(): {
exists: boolean;
Expand Down Expand Up @@ -125,7 +125,7 @@ describe("FileSystem", () => {

beforeEach(() => {
testInjector = createTestInjector();
tempDir = temp.mkdirSync("projectToUnzip");
tempDir = mkdtempSync(path.join(tmpdir(), "projectToUnzip-"));
fs = testInjector.resolve("fs");
file = path.join(tempDir, unzippedFileName);
fs.writeFile(file, msg);
Expand Down Expand Up @@ -188,7 +188,7 @@ describe("FileSystem", () => {
const commandUnzipFailedMessage = "Command unzip failed with exit code 9";
it("is case sensitive when options is not defined", async () => {
const testInjector = createTestInjector();
const tempDir = temp.mkdirSync("projectToUnzip");
const tempDir = mkdtempSync(path.join(tmpdir(), "projectToUnzip-"));
const fs: IFileSystem = testInjector.resolve("fs");
if (isOsCaseSensitive(testInjector)) {
await assert.isRejected(
Expand All @@ -202,7 +202,7 @@ describe("FileSystem", () => {

it("is case sensitive when caseSensitive option is not defined", async () => {
const testInjector = createTestInjector();
const tempDir = temp.mkdirSync("projectToUnzip");
const tempDir = mkdtempSync(path.join(tmpdir(), "projectToUnzip-"));
const fs: IFileSystem = testInjector.resolve("fs");
if (isOsCaseSensitive(testInjector)) {
await assert.isRejected(
Expand All @@ -216,7 +216,7 @@ describe("FileSystem", () => {

it("is case sensitive when caseSensitive option is true", async () => {
const testInjector = createTestInjector();
const tempDir = temp.mkdirSync("projectToUnzip");
const tempDir = mkdtempSync(path.join(tmpdir(), "projectToUnzip-"));
const fs: IFileSystem = testInjector.resolve("fs");
if (isOsCaseSensitive(testInjector)) {
await assert.isRejected(
Expand All @@ -233,7 +233,7 @@ describe("FileSystem", () => {

it("is case insensitive when caseSensitive option is false", async () => {
const testInjector = createTestInjector();
const tempDir = temp.mkdirSync("projectToUnzip");
const tempDir = mkdtempSync(path.join(tmpdir(), "projectToUnzip-"));
const fs: IFileSystem = testInjector.resolve("fs");
const file = path.join(tempDir, unzippedFileName);
await fs.unzip(
Expand All @@ -251,7 +251,7 @@ describe("FileSystem", () => {
describe("renameIfExists", () => {
it("returns true when file is renamed", () => {
const testInjector = createTestInjector();
const tempDir = temp.mkdirSync("renameIfExists");
const tempDir = mkdtempSync(path.join(tmpdir(), "renameIfExists-"));
const testFileName = path.join(tempDir, "testRenameIfExistsMethod");
const newFileName = path.join(tempDir, "newfilename");

Expand Down Expand Up @@ -287,7 +287,7 @@ describe("FileSystem", () => {

beforeEach(() => {
testInjector = createTestInjector();
tempDir = temp.mkdirSync("copyFile");
tempDir = mkdtempSync(path.join(tmpdir(), "copyFile-"));
testFileName = path.join(tempDir, "testCopyFile");
newFileName = path.join(tempDir, "newfilename");

Expand Down
78 changes: 41 additions & 37 deletions lib/common/test/unit-tests/mobile/project-files-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import * as path from "path";
import { Yok } from "../../../yok";
import { ProjectFilesProviderBase } from "../../../services/project-files-provider-base";

import * as temp from "temp";
import { mkdtempSync } from "fs";
import { tmpdir } from "os";
import { LiveSyncPaths } from "../../../constants";
import { TempServiceStub } from "../../../../../test/stubs";
import { IInjector } from "../../../definitions/yok";
import { IProjectFilesManager } from "../../../declarations";
temp.track();

const testedApplicationIdentifier = "com.telerik.myApp";
const iOSDeviceProjectRootPath = "/Documents/AppBuilder/LiveSync/app";
Expand All @@ -44,7 +44,7 @@ function createTestInjector(): IInjector {
testInjector.register("hostInfo", HostInfo);
testInjector.register(
"localToDevicePathDataFactory",
LocalToDevicePathDataFactory
LocalToDevicePathDataFactory,
);
testInjector.register("mobileHelper", MobileHelper);
testInjector.register("projectFilesProvider", ProjectFilesProviderBase);
Expand All @@ -61,12 +61,14 @@ function createTestInjector(): IInjector {

async function createFiles(
testInjector: IInjector,
filesToCreate: string[]
filesToCreate: string[],
): Promise<string> {
const directoryPath = temp.mkdirSync("Project Files Manager Tests");
const directoryPath = mkdtempSync(
path.join(tmpdir(), "Project Files Manager Tests-"),
);

_.each(filesToCreate, (file) =>
createFile(testInjector, file, "", directoryPath)
createFile(testInjector, file, "", directoryPath),
);

return directoryPath;
Expand All @@ -76,11 +78,11 @@ function createFile(
testInjector: IInjector,
fileToCreate: string,
fileContent: string,
directoryPath?: string
directoryPath?: string,
): string {
const fs = testInjector.resolve("fs");
directoryPath = !directoryPath
? temp.mkdirSync("Project Files Manager Tests")
? mkdtempSync(path.join(tmpdir(), "Project Files Manager Tests-"))
: directoryPath;

fs.writeFile(path.join(directoryPath, fileToCreate), fileContent);
Expand All @@ -100,50 +102,52 @@ describe("Project Files Manager Tests", () => {

it("maps non-platform specific files to device file paths for ios platform", async () => {
const files = ["~/TestApp/app/test.js", "~/TestApp/app/myfile.js"];
const localToDevicePaths = await projectFilesManager.createLocalToDevicePaths(
iOSDeviceAppData,
"~/TestApp/app",
files,
[]
);
const localToDevicePaths =
await projectFilesManager.createLocalToDevicePaths(
iOSDeviceAppData,
"~/TestApp/app",
files,
[],
);

_.each(localToDevicePaths, (localToDevicePathData, index) => {
assert.equal(files[index], localToDevicePathData.getLocalPath());
assert.equal(
mobileHelper.buildDevicePath(
iOSDeviceProjectRootPath,
path.basename(files[index])
path.basename(files[index]),
),
localToDevicePathData.getDevicePath()
localToDevicePathData.getDevicePath(),
);
assert.equal(
path.basename(files[index]),
localToDevicePathData.getRelativeToProjectBasePath()
localToDevicePathData.getRelativeToProjectBasePath(),
);
});
});

it("maps non-platform specific files to device file paths for android platform", async () => {
const files = ["~/TestApp/app/test.js", "~/TestApp/app/myfile.js"];
const localToDevicePaths = await projectFilesManager.createLocalToDevicePaths(
androidDeviceAppData,
"~/TestApp/app",
files,
[]
);
const localToDevicePaths =
await projectFilesManager.createLocalToDevicePaths(
androidDeviceAppData,
"~/TestApp/app",
files,
[],
);

_.each(localToDevicePaths, (localToDevicePathData, index) => {
assert.equal(files[index], localToDevicePathData.getLocalPath());
assert.equal(
mobileHelper.buildDevicePath(
androidDeviceProjectRootPath,
path.basename(files[index])
path.basename(files[index]),
),
localToDevicePathData.getDevicePath()
localToDevicePathData.getDevicePath(),
);
assert.equal(
path.basename(files[index]),
localToDevicePathData.getRelativeToProjectBasePath()
localToDevicePathData.getRelativeToProjectBasePath(),
);
});
});
Expand All @@ -155,18 +159,18 @@ describe("Project Files Manager Tests", () => {
iOSDeviceAppData,
"~/TestApp/app",
[filePath],
[]
[],
)
)[0];

assert.equal(filePath, localToDevicePathData.getLocalPath());
assert.equal(
mobileHelper.buildDevicePath(iOSDeviceProjectRootPath, "test.js"),
localToDevicePathData.getDevicePath()
localToDevicePathData.getDevicePath(),
);
assert.equal(
"test.ios.js",
localToDevicePathData.getRelativeToProjectBasePath()
localToDevicePathData.getRelativeToProjectBasePath(),
);
});

Expand All @@ -177,18 +181,18 @@ describe("Project Files Manager Tests", () => {
androidDeviceAppData,
"~/TestApp/app",
[filePath],
[]
[],
)
)[0];

assert.equal(filePath, localToDevicePathData.getLocalPath());
assert.equal(
mobileHelper.buildDevicePath(androidDeviceProjectRootPath, "test.js"),
localToDevicePathData.getDevicePath()
localToDevicePathData.getDevicePath(),
);
assert.equal(
"test.android.js",
localToDevicePathData.getRelativeToProjectBasePath()
localToDevicePathData.getRelativeToProjectBasePath(),
);
});

Expand All @@ -199,7 +203,7 @@ describe("Project Files Manager Tests", () => {
projectFilesManager.processPlatformSpecificFiles(
directoryPath,
"android",
{}
{},
);

const fs = testInjector.resolve("fs");
Expand Down Expand Up @@ -228,7 +232,7 @@ describe("Project Files Manager Tests", () => {
testInjector,
"test.release.x",
releaseFileContent,
directoryPath
directoryPath,
);

projectFilesManager.processPlatformSpecificFiles(directoryPath, "android", {
Expand All @@ -241,7 +245,7 @@ describe("Project Files Manager Tests", () => {
assert.isFalse(fs.exists(path.join(directoryPath, "test.release.x")));
assert.isTrue(
fs.readFile(path.join(directoryPath, "test.x")).toString() ===
releaseFileContent
releaseFileContent,
);
});

Expand All @@ -253,7 +257,7 @@ describe("Project Files Manager Tests", () => {
projectFilesManager.processPlatformSpecificFiles(
directoryPath,
"android",
{}
{},
);

const fs = testInjector.resolve("fs");
Expand All @@ -262,7 +266,7 @@ describe("Project Files Manager Tests", () => {
assert.isFalse(fs.exists(path.join(directoryPath, "test.release.x")));
assert.isTrue(
fs.readFile(path.join(directoryPath, "test.x")).toString() ===
debugFileContent
debugFileContent,
);
});

Expand Down
Loading
Loading