-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathnativescript-cli-lib.ts
84 lines (75 loc) · 3.23 KB
/
nativescript-cli-lib.ts
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
import { assert } from "chai";
import * as fs from "fs";
import * as path from "path";
import * as childProcess from "child_process";
describe("nativescript-cli-lib", () => {
it("is main entry of the package", () => {
const packageJsonContent = fs.readFileSync(path.join(__dirname, "..", "package.json")).toString();
const jsonContent = JSON.parse(packageJsonContent);
const expectedEntryPoint = "./lib/nativescript-cli-lib.js";
assert.deepEqual(jsonContent.main, expectedEntryPoint);
});
const publicApi: any = {
settingsService: ["setSettings"],
deviceEmitter: null,
projectService: ["createProject", "isValidNativeScriptProject"],
projectDataService: [
"getProjectData",
"getProjectDataFromContent",
"getNsConfigDefaultContent",
"getAssetsStructure",
"getIOSAssetsStructure",
"getAndroidAssetsStructure"
],
constants: ["CONFIG_NS_APP_RESOURCES_ENTRY", "CONFIG_NS_APP_ENTRY", "CONFIG_NS_FILE_NAME"],
localBuildService: ["build"],
deviceLogProvider: null,
packageManager: ["install", "uninstall", "view", "search"],
extensibilityService: ["loadExtensions", "loadExtension", "getInstalledExtensions", "installExtension", "uninstallExtension"],
liveSyncService: ["liveSync", "stopLiveSync", "enableDebugging", "disableDebugging", "attachDebugger"],
debugService: ["debug"],
analyticsSettingsService: ["getClientId"],
devicesService: [
"addDeviceDiscovery",
"deployOnDevices",
"getDebuggableApps",
"getDebuggableViews",
"getDevices",
"getInstalledApplications",
"initialize",
"isAppInstalledOnDevices",
"mapAbstractToTcpPort",
"setLogLevel"
],
assetsGenerationService: [
"generateIcons",
"generateSplashScreens",
],
androidProcessService: [
"getAppProcessId"
],
sysInfo: [
"getSupportedNodeVersionRange",
"getSystemWarnings"
]
};
const pathToEntryPoint = path.join(__dirname, "..", "lib", "nativescript-cli-lib.js").replace(/\\/g, "\\\\");
_.each(publicApi, (methods: string[], moduleName: string) => {
it(`resolves publicly available module - ${moduleName}${methods && methods.length ? " and its publicly available methods: " + methods.join(", ") : ""}`, () => {
// HACK: If we try to require the entry point directly, the below code will fail as mocha requires all test files before starting the tests.
// When the files are required, $injector.register adds each dependency to $injector's cache.
// For example $injector.register("errors", Errors) will add the errors module with its resolver (Errors) to $injector's cache.
// Calling $injector.require("errors", <path to errors file>), that's executed in our bootstrap, will fail, as the module errors is already in the cache.
// In order to workaround this problem, start new process and assert there. This way all files will not be required in it and $injector.require(...) will work correctly.
let testMethod = `"${process.execPath}" -e "` +
"var assert = require('chai').assert;" +
`var result = require('${pathToEntryPoint}');` +
`assert.ok(result.${moduleName});`;
_.each(methods, method => {
testMethod += `assert.ok(result.${moduleName}.${method});`;
});
testMethod += '"'; // Really important - close the " of node -e ""
childProcess.execSync(testMethod);
});
});
});