-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathpost-install.ts
75 lines (63 loc) · 2.21 KB
/
post-install.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
import { assert } from "chai";
// Use require instead of import in order to replace the `spawn` method of child_process
const childProcess = require("child_process");
const helpers = require("../lib/common/helpers");
import { SpawnOptions, ChildProcess } from "child_process";
import * as path from "path";
import { POST_INSTALL_COMMAND_NAME } from "../lib/constants";
describe("postinstall.js", () => {
let isSpawnCalled = false;
let argsPassedToSpawn: string[] = [];
const originalSpawn = childProcess.spawn;
const originalIsInstallingNativeScriptGlobally =
helpers.isInstallingNativeScriptGlobally;
beforeEach(() => {
isSpawnCalled = false;
argsPassedToSpawn = [];
childProcess.spawn = (
command: string,
args?: string[],
options?: SpawnOptions
): ChildProcess => {
isSpawnCalled = true;
argsPassedToSpawn = args;
return null;
};
});
afterEach(() => {
childProcess.spawn = originalSpawn;
helpers.isInstallingNativeScriptGlobally = originalIsInstallingNativeScriptGlobally;
});
it("calls post-install-cli command of CLI when it is global installation", () => {
helpers.isInstallingNativeScriptGlobally = () => true;
require(path.join(__dirname, "..", "postinstall"));
assert.isTrue(
isSpawnCalled,
"child_process.spawn must be called from postinstall.js"
);
const expectedPathToCliExecutable = path.join(
__dirname,
"..",
"bin",
"tns"
);
assert.isTrue(
argsPassedToSpawn.indexOf(expectedPathToCliExecutable) !== -1,
`The spawned args must contain path to TNS.
Expected path is: ${expectedPathToCliExecutable}, current args are: ${argsPassedToSpawn}.`
);
assert.isTrue(
argsPassedToSpawn.indexOf(POST_INSTALL_COMMAND_NAME) !== -1,
`The spawned args must contain the name of the post-install command.
Expected path is: ${expectedPathToCliExecutable}, current args are: ${argsPassedToSpawn}.`
);
});
it("does not call post-install-cli command of CLI when it is not global install", () => {
helpers.isInstallingNativeScriptGlobally = () => false;
require(path.join(__dirname, "..", "postinstall"));
assert.isFalse(
isSpawnCalled,
"child_process.spawn must NOT be called from postinstall.js when CLI is not installed globally"
);
});
});