Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow watch early exit #865

Merged
merged 3 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ v1.1.4
======
- Fix for theme get --list (#862)
- Removed too restrictive timeouts (#864)
- Allow watch command to be cancelled while working on events (#865)

v1.1.3 (Dec 2, 2020)
====================
Expand Down
2 changes: 1 addition & 1 deletion cmd/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var watchCmd = &cobra.Command{
watcher.Watch()
defer watcher.Stop()

signalChan := make(chan os.Signal)
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt)

notifier := newNotifyAdapter(ctx.Env.Notify)
Expand Down
21 changes: 21 additions & 0 deletions cmd/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,27 @@ func TestWatch(t *testing.T) {
assert.Contains(t, stdOut.String(), "processing assets/app.js")
assert.Contains(t, stdOut.String(), "Deleted assets/app.js")
notifier.AssertExpectations(t)

signalChan = make(chan os.Signal)
eventChan = make(chan file.Event)
ctx, client, _, stdOut, stdErr = createTestCtx()
client.On("UpdateAsset", shopify.Asset{Key: "assets/app.js", Checksum: "d41d8cd98f00b204e9800998ecf8427e"}, "").Return(nil)
ctx.Flags.ConfigPath = "config.yml"
ctx.Env.Directory = "_testdata/projectdir"
go func() {
eventChan <- file.Event{Op: file.Update, Path: "assets/app.js"}
signalChan <- os.Interrupt
eventChan <- file.Event{Op: file.Remove, Path: "assets/app.js"}
}()
notifier = new(testAdapter)
notifier.On("notify", ctx, "assets/app.js")
err = watch(ctx, eventChan, signalChan, notifier)
assert.Nil(t, err)
assert.Contains(t, stdOut.String(), "Watching for file changes")
assert.Contains(t, stdOut.String(), "processing assets/app.js")
assert.Contains(t, stdOut.String(), "Updated assets/app.js")
assert.NotContains(t, stdOut.String(), "Deleted assets/app.js")
notifier.AssertExpectations(t)
}

func TestPerform(t *testing.T) {
Expand Down