mirror of
https://github.com/go-task/task.git
synced 2025-08-10 22:42:19 +02:00
Updated test for file watcher interval param
Updated Interval Setting Priority
This commit is contained in:
@@ -1503,9 +1503,6 @@ Hello, World!
|
|||||||
assert.NoError(t, e.Setup())
|
assert.NoError(t, e.Setup())
|
||||||
buff.Reset()
|
buff.Reset()
|
||||||
|
|
||||||
ctx := context.Background()
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
|
|
||||||
err := os.MkdirAll(dir+"/src", 0755)
|
err := os.MkdirAll(dir+"/src", 0755)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
@@ -1514,6 +1511,9 @@ Hello, World!
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
|
||||||
go func(ctx context.Context) {
|
go func(ctx context.Context) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
@@ -1535,9 +1535,10 @@ Hello, World!
|
|||||||
}
|
}
|
||||||
time.Sleep(70 * time.Millisecond)
|
time.Sleep(70 * time.Millisecond)
|
||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
assert.Equal(t, expectedOutput, strings.TrimSpace(buff.String()))
|
assert.Equal(t, expectedOutput, strings.TrimSpace(buff.String()))
|
||||||
buff.Reset()
|
buff.Reset()
|
||||||
err = os.RemoveAll(dir + "/.task")
|
err = os.RemoveAll(dir + "/.task")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
err = os.RemoveAll(dir + "/src")
|
||||||
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
2
testdata/watcher_interval/Taskfile.yaml
vendored
2
testdata/watcher_interval/Taskfile.yaml
vendored
@@ -5,7 +5,7 @@ version: '3'
|
|||||||
vars:
|
vars:
|
||||||
GREETING: Hello, World!
|
GREETING: Hello, World!
|
||||||
|
|
||||||
interval: "50ms"
|
interval: "30ms"
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
default:
|
default:
|
||||||
|
10
watch.go
10
watch.go
@@ -39,17 +39,17 @@ func (e *Executor) watchTasks(calls ...taskfile.Call) error {
|
|||||||
|
|
||||||
var watchIntervalString string
|
var watchIntervalString string
|
||||||
|
|
||||||
if e.Taskfile.Interval != "" {
|
if e.Interval != "" {
|
||||||
watchIntervalString = e.Taskfile.Interval
|
|
||||||
} else if e.Interval != "" {
|
|
||||||
watchIntervalString = e.Interval
|
watchIntervalString = e.Interval
|
||||||
|
} else if e.Taskfile.Interval != "" {
|
||||||
|
watchIntervalString = e.Taskfile.Interval
|
||||||
}
|
}
|
||||||
|
|
||||||
watchInterval := defaultWatchInterval
|
watchInterval := defaultWatchInterval
|
||||||
|
|
||||||
if watchIntervalString != "" {
|
if watchIntervalString != "" {
|
||||||
var err error
|
var err error
|
||||||
watchInterval, err = parsedWatchInterval(watchIntervalString)
|
watchInterval, err = parseWatchInterval(watchIntervalString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.Logger.Errf(logger.Red, "%v", err)
|
e.Logger.Errf(logger.Red, "%v", err)
|
||||||
}
|
}
|
||||||
@@ -185,7 +185,7 @@ func shouldIgnoreFile(path string) bool {
|
|||||||
return strings.Contains(path, "/.git") || strings.Contains(path, "/.task") || strings.Contains(path, "/node_modules")
|
return strings.Contains(path, "/.git") || strings.Contains(path, "/.task") || strings.Contains(path, "/node_modules")
|
||||||
}
|
}
|
||||||
|
|
||||||
func parsedWatchInterval(watchInterval string) (time.Duration, error) {
|
func parseWatchInterval(watchInterval string) (time.Duration, error) {
|
||||||
v, err := time.ParseDuration(watchInterval)
|
v, err := time.ParseDuration(watchInterval)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf(`task: Could not parse watch interval "%s": %v`, watchInterval, err)
|
return 0, fmt.Errorf(`task: Could not parse watch interval "%s": %v`, watchInterval, err)
|
||||||
|
Reference in New Issue
Block a user