Skip to content

Commit

Permalink
Merge pull request #865 from Shopify/allow_watch_early_exit
Browse files Browse the repository at this point in the history
Allow watch early exit
  • Loading branch information
Tim Anema authored Dec 3, 2020
2 parents 4e9ac30 + 48a7940 commit 7841f7a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
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

0 comments on commit 7841f7a

Please sign in to comment.