forked from JanDeDobbeleer/oh-my-posh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegment_node_test.go
executable file
·115 lines (104 loc) · 2.71 KB
/
segment_node_test.go
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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
type nodeArgs struct {
enabled bool
nodeVersion string
hasJS bool
hasTS bool
displayVersion bool
}
func bootStrapNodeTest(args *nodeArgs) *node {
env := new(MockedEnvironment)
env.On("hasCommand", "node").Return(args.enabled)
env.On("runCommand", "node", []string{"--version"}).Return(args.nodeVersion, nil)
env.On("hasFiles", "*.js").Return(args.hasJS)
env.On("hasFiles", "*.ts").Return(args.hasTS)
props := &properties{
values: map[Property]interface{}{
DisplayVersion: args.displayVersion,
},
}
n := &node{
env: env,
props: props,
}
return n
}
func TestNodeWriterDisabled(t *testing.T) {
args := &nodeArgs{
enabled: false,
}
node := bootStrapNodeTest(args)
assert.False(t, node.enabled(), "node is not available")
}
func TestNodeWriterDisabledNoJSorTSFiles(t *testing.T) {
args := &nodeArgs{
enabled: true,
}
node := bootStrapNodeTest(args)
assert.False(t, node.enabled(), "no JS or TS files in the current directory")
}
func TestNodeEnabledJSFiles(t *testing.T) {
expected := "1.14"
args := &nodeArgs{
enabled: true,
nodeVersion: expected,
hasJS: true,
displayVersion: true,
}
node := bootStrapNodeTest(args)
assert.True(t, node.enabled())
assert.Equal(t, expected, node.string(), "node is available and JS files are found")
}
func TestNodeEnabledTsFiles(t *testing.T) {
expected := "1.14"
args := &nodeArgs{
enabled: true,
nodeVersion: expected,
hasTS: true,
displayVersion: true,
}
node := bootStrapNodeTest(args)
assert.True(t, node.enabled())
assert.Equal(t, expected, node.string(), "node is available and TS files are found")
}
func TestNodeEnabledJsAndTsFiles(t *testing.T) {
expected := "1.14"
args := &nodeArgs{
enabled: true,
nodeVersion: expected,
hasJS: true,
hasTS: true,
displayVersion: true,
}
node := bootStrapNodeTest(args)
assert.True(t, node.enabled())
assert.Equal(t, expected, node.string(), "node is available and JS and TS files are found")
}
func TestNodeEnabledNoVersion(t *testing.T) {
expected := ""
args := &nodeArgs{
enabled: true,
nodeVersion: "1.14",
hasJS: true,
displayVersion: false,
}
node := bootStrapNodeTest(args)
assert.True(t, node.enabled())
assert.Equal(t, expected, node.string(), "we don't expect a version")
}
func TestNodeEnabledNodeVersion(t *testing.T) {
expected := "1.14"
args := &nodeArgs{
enabled: true,
nodeVersion: expected,
hasJS: true,
displayVersion: true,
}
node := bootStrapNodeTest(args)
assert.True(t, node.enabled())
assert.Equal(t, expected, node.string(), "we expect a version")
}