-
-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathproject-files-provider.ts
More file actions
142 lines (126 loc) · 4.31 KB
/
project-files-provider.ts
File metadata and controls
142 lines (126 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { Yok } from "../lib/common/yok";
import { ProjectFilesProvider } from "../lib/providers/project-files-provider";
import * as stubs from "./stubs";
import { assert } from "chai";
import * as path from "path";
import { IProjectData } from "../lib/definitions/project";
import { IInjector } from "../lib/common/definitions/yok";
import { IProjectFilesProvider } from "../lib/common/declarations";
const projectDir = "projectDir",
appDestinationDirectoryPath = "appDestinationDirectoryPath",
appResourcesDestinationDirectoryPath = "appResourcesDestinationDirectoryPath",
appSourceDir = path.join(projectDir, "app");
function createTestInjector(): IInjector {
const testInjector = new Yok();
testInjector.register("mobileHelper", {
platformNames: ["Android", "iOS"],
});
testInjector.register("projectData", stubs.ProjectDataStub);
testInjector.register("platformsDataService", {
getPlatformData: (platform: string) => {
return {
appDestinationDirectoryPath: appDestinationDirectoryPath,
normalizedPlatformName: platform.toLowerCase(),
platformProjectService: {
getAppResourcesDestinationDirectoryPath: () =>
appResourcesDestinationDirectoryPath,
},
};
},
});
testInjector.register("options", {
release: false,
hostProjectModuleName: "app",
});
return testInjector;
}
describe("project-files-provider", () => {
let testInjector: IInjector;
let projectFilesProvider: IProjectFilesProvider;
let projectData: IProjectData;
beforeEach(() => {
testInjector = createTestInjector();
projectData = testInjector.resolve("projectData");
projectData.projectDir = projectDir;
projectData.appDirectoryPath = projectData.getAppDirectoryPath();
projectData.appResourcesDirectoryPath =
projectData.getAppResourcesDirectoryPath();
projectFilesProvider = testInjector.resolve(ProjectFilesProvider);
});
describe("isFileExcluded", () => {
it("returns true for .ts files", () => {
assert.isTrue(projectFilesProvider.isFileExcluded("test.ts"));
});
it("returns false for .js files", () => {
assert.isFalse(projectFilesProvider.isFileExcluded("test.js"));
});
});
describe("mapFilePath", () => {
it("returns file path from prepared project when path from app dir is passed", () => {
const mappedFilePath = projectFilesProvider.mapFilePath(
path.join(appSourceDir, "test.js"),
"android",
projectData,
{}
);
assert.deepStrictEqual(
mappedFilePath,
path.join(appDestinationDirectoryPath, "app", "test.js")
);
});
it("returns file path from prepared project when path from app/App_Resources/platform dir is passed", () => {
const mappedFilePath = projectFilesProvider.mapFilePath(
path.join(appSourceDir, "App_Resources", "android", "test.js"),
"android",
projectData,
{}
);
assert.deepStrictEqual(
mappedFilePath,
path.join(appResourcesDestinationDirectoryPath, "test.js")
);
});
it("returns null when path from app/App_Resources/android dir is passed and iOS platform is specified", () => {
const mappedFilePath = projectFilesProvider.mapFilePath(
path.join(appSourceDir, "App_Resources", "android", "test.js"),
"iOS",
projectData,
{}
);
assert.deepStrictEqual(mappedFilePath, null);
});
it("returns null when path from app/App_Resources/ dir (not platform specific) is passed", () => {
const mappedFilePath = projectFilesProvider.mapFilePath(
path.join(appSourceDir, "App_Resources", "test.js"),
"android",
projectData,
{}
);
assert.deepStrictEqual(mappedFilePath, null);
});
it("returns file path from prepared project when path from app dir is passed and it contains platform in its name", () => {
const mappedFilePath = projectFilesProvider.mapFilePath(
path.join(appSourceDir, "test.android.js"),
"android",
projectData,
{}
);
assert.deepStrictEqual(
mappedFilePath,
path.join(appDestinationDirectoryPath, "app", "test.js")
);
});
it("returns file path from prepared project when path from app dir is passed and it contains configuration in its name", () => {
const mappedFilePath = projectFilesProvider.mapFilePath(
path.join(appSourceDir, "test.debug.js"),
"android",
projectData,
{}
);
assert.deepStrictEqual(
mappedFilePath,
path.join(appDestinationDirectoryPath, "app", "test.js")
);
});
});
});