mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-27 20:09:39 -08:00
80 lines
1.8 KiB
Go
Executable file
80 lines
1.8 KiB
Go
Executable file
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type nodeArgs struct {
|
|
enabled bool
|
|
nodeVersion string
|
|
hasJS bool
|
|
hasTS 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)
|
|
env.On("hasFiles", "*.js").Return(args.hasJS)
|
|
env.On("hasFiles", "*.ts").Return(args.hasTS)
|
|
n := &node{
|
|
env: env,
|
|
}
|
|
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,
|
|
}
|
|
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,
|
|
}
|
|
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,
|
|
}
|
|
node := bootStrapNodeTest(args)
|
|
assert.True(t, node.enabled())
|
|
assert.Equal(t, expected, node.string(), "node is available and JS and TS files are found")
|
|
}
|