/
module.sh
121 lines (83 loc) · 2.51 KB
/
module.sh
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
#!/usr/bin/env bash
SRC=$(cd $(dirname "$0"); pwd)
source "${SRC}/../include.sh"
echo -e "\033[1mRunning tests:\033[0m"
cd $file_path
#
# Re init module system
#
rm -rf ~/.pm2/node_modules
$pm2 kill
#
#
#
$pm2 unset pm2-probe
$pm2 set 'pm2-probe:config1xxx' true
$pm2 install pm2-probe
spec "Should install a module"
should 'should app be online' 'online' 1
$pm2 install pm2-probe
spec "Should update a module"
should 'should app be online' 'online' 1
ls ~/.pm2/modules/pm2-probe
spec "Module should be installed"
# Default configuration variable in package.json (under "config" attribute)
should 'should have default config variable via package.json' "var2: false" 4
#
# Should configuration variable be present two times
# one time in the raw env, and a second time prefixed with the module name
#
exists '1# should have config variable' "config1xxx: 'true'" 6
#
# Change variable value
#
$pm2 set 'pm2-probe:config1xxx' false
sleep 1
exists '2# should have config variable' "config1xxx: 'false'" 4
$pm2 update
spec "Should update successfully"
should 'and module still online' 'online' 1
$pm2 kill
spec "Should kill pm2"
$pm2 list
spec "Should resurrect pm2"
should 'and module still online' 'online' 1
$pm2 stop pm2-probe
should 'should module status not be modified' 'online' 1
$pm2 delete all
should 'should module status not be modified' 'online' 1
$pm2 delete pm2-probe
should 'should module status not be modified' 'online' 1
$pm2 stop all
should 'should module status not be modified' 'online' 1
$pm2 stop pm2-probe
should 'should module status not be modified' 'online' 1
$pm2 uninstall pm2-probe
spec "Should uninstall a module"
should 'should module not be online' 'online' 0
ls ~/.pm2/modules/pm2-probe
ispec "Module should be deleted"
$pm2 update
should 'should module not be online' 'online' 0
#
# Module test
#
cd module-fixture
$pm2 kill
# Unset all possible variables for module
$pm2 unset example-module
# Install local module in development mode
$pm2 install .
sleep 0.5
spec 'Should have installed module'
# # Override environment variable
# $pm2 set example-module:var2 true
# sleep 0.5
# should 'should module been restarted after setting variable' 'restart_time: 1' 1
# # 4 occurences because of a restart
# should 'should have config variable modified' "var2: 'true'" 4
# $pm2 set example-module:newvar true
# sleep 0.5
# should 'should module been restarted after setting variable' 'restart_time: 2' 1
# # 4 occurences because of a restart
# should 'should have config variable modified' "newvar: 'true'" 4